Sequencing Migrations

Prior to Rails 2.1, the migrations were sequenced via a simple numbering scheme baked into the name of the migration file, and automatically handled by the migration generator.Each migration received a sequential number. There were many inconveniences inherent in that approach, especially in team environments where two developers could check in a migration with the same sequence number. Thankfully those issues have been
eliminated by using timestamps to sequence migrations.


Migrations that have already been run are listed in a special database table that Rails
maintains. It is named schema_migrations and only has one column:

mysql> desc schema_migrations;
| Field| Type| Null | Key | Default | Extra |

| version | varchar(255) | NO| PRI | NULL|
1 row in set (0.00 sec)
When you pull down new migrations from source control, rake db:migrate will check
the schema_migrations table and execute all migrations that have not yet run (even if
they have earlier timestamps than migrations that you’ve added yourself in the interim).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s