Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing Existing Rails Migrations is a good idea?

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 than create a new migration. I do this when app has not hit production which means I can reset/clean database without worries & I am working solo or part of a small team.

But Today, I came across the following advice in Rails Guide saying its not a good idea & discourages editing existing migrations:

Editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or, more generally, which has not been propagated beyond your development machine) is relatively harmless.

I want to know:

  • what potential pitfalls I can run into ?
  • Does those pitfalls apply in my case(development stage,working solo)?
like image 652
CuriousMind Avatar asked May 30 '12 07:05

CuriousMind


People also ask

Can you edit a migration file rails?

If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run rake db:migrate.

Can I edit a migration?

You can edit only a migration batch that has a status of Created.

Why do we need migration in rails?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.


1 Answers

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.

like image 106
Sully Avatar answered Sep 21 '22 02:09

Sully