开发者

When adding a new column to a table, should I create a new migration or edit an old one?

If开发者_开发百科 I create a table with rails generate migration, I can add an extra column to it later by creating a new migration. I could also rollback the original migration and then edit it to include the extra column.

Method 1: New Migration

//Create the model including the migration
$ rails generate model Foo bar:string

//Perform the migration
$ rake db:migrate

//Create the add column migration
$ rails generate migration add_foobar_to_foos foobar:string

//Perform the new migration
$ rake db:migrate

Method 2: Rollback

//Create the model including the migration
$ rails generate model Foo bar:string

//Perform the migration
$ rake db:migrate

//Rollback the migration
$ rake db:rollback

//Edit the original migration file

//Perform the new migration
$ rake db:migrate

What is the correct/best way to accomplish this task and why?


Ill go with method 1. why? because if other developers/machines are working with this environment you can get an inconstant state due to the fact that they might need to rollback at the right time in order to maintain correct db structure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜