# Cleaning up migrations

**URL:** <https://www.ruby-forum.com/t/cleaning-up-migrations/195707>\
**Category:** Rails\
**Created:** [September 28, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707 "2010-09-28T19:11:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/1 "2010-09-28T19:11:30Z")

</div>

My project has a lot of migrations, that ar not all necessary on my new  
server, since the database has been copied.

For installation, I simply removed these migrations on the the server,  
before executing, but that no good solution for further maintainance of  
the new server.

I’m using vlad as deployment tool. How to cleanup the migrations? Is it  
possible, to simply remove the unwanted migrations from db/migrate?

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/2 "2010-09-28T19:31:27Z")

</div>

Fritz T. wrote:

> My project has a lot of migrations, that ar not all necessary on my new  
> server, since the database has been copied.
> 
> For installation, I simply removed these migrations on the the server,  
> before executing, but that no good solution for further maintainance of  
> the new server.
> 
> I’m using vlad as deployment tool. How to cleanup the migrations? Is it  
> possible, to simply remove the unwanted migrations from db/migrate?

Don’t. They’re not doing any harm, and they may be helpful for future  
maintenance.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 8:40pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/3 "2010-09-28T20:40:00Z")

</div>

Marnen Laibow-Koser wrote:

> Don’t. They’re not doing any harm, and they may be helpful for future  
> maintenance.

They harm, they are data migrations, that require data, that may have  
been changed in the meantime.

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 9:30pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/4 "2010-09-28T21:30:43Z")

</div>

Fritz T. wrote:

> Marnen Laibow-Koser wrote:
> 
> > Don’t. They’re not doing any harm, and they may be helpful for future  
> > maintenance.
> 
> They harm,

How? You’re not normally going to be running old migrations. What  
specific problem do you think you will run into if you leave the old  
migrations around?

> they are data migrations, that require data, that may have  
> been changed in the meantime.

Can you give an example? Are you talking about seed data, or about  
changing existing data to fit a new schema?

If the former, then you’ve got a great example of why you shouldn’t use  
migrations for seed data. If the latter, then there’s really no issue.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/5 "2010-09-28T22:05:32Z")

</div>

Marnen Laibow-Koser wrote:

> How? You’re not normally going to be running old migrations. What  
> specific problem do you think you will run into if you leave the old  
> migrations around?

I moved the complete database from my interim server to the permanent  
one. This database had been modified by the data migrations and in the  
meantime some data has been changed. So it’s not a good idea, to rerun  
the data migrations on the new server.

To prevent this, I locally removed the data migrations on the new server  
before migrating.

On my developmentsystem, they’re still present and dont harm, but I  
guess, they will be pushed up to the server again with my next update  
and will get run, because there is no corresponding entry in the  
migration data base.

Maybe, the simplest solution will be, to do something to make them null  
migrations on the development system.

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 10:37pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/6 "2010-09-28T22:37:13Z")

</div>

On Tuesday 28 September 2010, Fritz T. wrote:

> To prevent this, I locally removed the data migrations on the new  
> server before migrating.
> 
> On my developmentsystem, they’re still present and dont harm, but I  
> guess, they will be pushed up to the server again with my next update  
> and will get run, because there is no corresponding entry in the  
> migration data base.

Why is there no corresponding entry in the database? If you initialize a  
database from db/schema.rb, an entry is created in the migrations table  
indicating the version of the schema.

> Maybe, the simplest solution will be, to do something to make them  
> null migrations on the development system.

Just throw them away. If you can.

Migrations are tools for changing the structure of a database from one  
version to the next. They have no lasting value. In particular,  
migrations are _not_ the right means to re-create a database. For that,  
db/schema.rb + rake db:schema:load is the proper way.

Also, migrations are not supposed to add data to the database, apart  
from changes necessary for migrating the structure. For adding data,  
there are db/seeds.rb and rake db:seed. It’s good idea to write  
db/seeds.rb in such a way that it can be run again and again without  
causing harm.

In summary, if you’re worried that old migrations may inadvertently be  
applied to your database, make sure that it contains a suitable entry in  
its migrations table indicating the actual version of the schema.

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 11:18pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/7 "2010-09-28T23:18:25Z")

</div>

Thanks for your explanations.

---

<div class="post-metadata">

**Author:** ![trapper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@trapper](https://www.ruby-forum.com/u/trapper)\
**Post date:** [September 28, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/cleaning-up-migrations/195707/8 "2010-09-28T22:41:26Z")

</div>

Fritz T. wrote:

> Marnen Laibow-Koser wrote:
> 
> > How? You’re not normally going to be running old migrations. What  
> > specific problem do you think you will run into if you leave the old  
> > migrations around?
> 
> I moved the complete database from my interim server to the permanent  
> one.

Then the schema\_migrations table should have the correct values, so Rake  
will know not to run the old migrations.

[…].

> On my developmentsystem, they’re still present and dont harm, but I  
> guess, they will be pushed up to the server again with my next update  
> and will get run, because there is no corresponding entry in the  
> migration data base.

Why aren’t there? If the migration was run, its ID will be in the  
schema\_migrations table.

> Maybe, the simplest solution will be, to do something to make them null  
> migrations on the development system.

And the right way to do that is to make sure that their IDs are in  
schema\_migrations.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
