Editing Existing Rails Migrations is a good idea?

前端 未结 3 1467
面向向阳花
面向向阳花 2020-12-11 17:33

When starting out a new project, there are lot of changes in models that I find it easy to edit an existing migration & run db:clean or db:reset

3条回答
  •  情深已故
    2020-12-11 18:16

    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.

提交回复
热议问题