Yii migrations

At the beginning, why we need migration? 

In a long time, PHP has no way to currently deploy a project  at many server at same time with the exactly same database schema.

Most time we have to dump database and import them to some othere server.

If someone changed the database schema, we have to apply the new 'SQL' file at all servers. That guy may has to tell all developers. (I think so, it may not be correct.)

 

Now Yii provided the way to manage our database schema. We don't need to waste time to care the database schema.

The following steps how we can use database migration during development:

  1. Tim creates a new migration (e.g. create a new table)
  2. Tim commits the new migration into source control system (e.g. SVN, GIT)
  3. Doug updates from source control system and receives the new migration
  4. Doug applies the migration to his local development database

 

Use migration

1 % cd WebRoot/webappname
2 % php protected/yiic migrate create <name>
3 # Migration command list
4 % php protected/yiic migrate                      # Apply all new migrations
5 % php protected/yiic up [step]                    # Apply one or a few new migrations
6 % php protected/yiic down [step]               # Revert the last one or several applied migrations

# More details see:  http://www.yiiframework.com/doc/guide/1.1/en/database.migration

posted on 2012-10-15 15:29  技术员  阅读(707)  评论(0编辑  收藏  举报

导航