Editing Existing Rails Migrations is a good idea?

大憨熊 提交于 2019-11-28 13:35:28

If you are working with a team and you committed the migration then NO.

If it is only on your local environment then just create a new migration fixing what you need. You can drop tables\columns and do what you need.

Since you clean the db and reset it, then everyone will be doing the same or they will have issues if they try to migrate.

I'm working on a web-app in development mode. Although I am working alone, it's best practice to use migrations to modify the database. It might leave a trail of modifications, but you can see the evolution of your database structure. In the long run, you will become faster at resolving db issues with migrations.

Database migrations are a tool. Like any toolbox the most important thing is to understand what it is good for, how to use it, and why to use it that way.

  • Live Site: In a live site you can't simply use rake:db reset because clearly you need all that data
  • In collaboration: You need to maintain migrations in consistency with other developers. What if they have entered data into their database (for whatever purpose) and simply mixed in your code. You've now completely foobared their efforts and they will be compelled to reset their entire database
  • Rake db:rollback : Once you've modified the code you'll have to reset, now you can't run rollback.
  • It's a bad habit: In the majority of cases the polite manner in which to do this is to create a new migration. It is better to be in the habit and of the mindset to be able to quickly and efficiently create new migrations.

I'm not actually telling you not to do it. These are just the major points as to why not do as I see it. I most cases if you are alone, or especially if you are just forming up your project (and may not immediately realize how you want the database to look/work playing around with them directly may be most efficient. It is important to understand the why and wherefore's before you going mucking about against best practice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!