The 'version' command

The up and down commands are pretty prescriptive in how they work. The up command evolves all the way up, and down only devolves one step down. Sometimes that might be limiting, so the version command exists to allow you to migrate the schema to any specific version of the database you like. You simply call it, specifying the version you’d like to end up at, and the migrations system figures out whether it has to go up or down, and which migrations it needs to run. Here’s an example.

/home/cbegin/testdb$ migrate status
ID             Applied At          Description
==================================================================
20090802210445    ...pending...    create changelog
20090804225207    ...pending...    create author table
20090804225328    ...pending...    create blog table
20090804225333    ...pending...    create post table

/home/cbegin/testdb$ migrate version 20090804225207

/home/cbegin/testdb$ migrate status
ID             Applied At          Description
==================================================================
20090802210445 2009-08-04 22:51:17 create changelog
20090804225207 2009-08-04 22:51:17 create author table
20090804225328    ...pending...    create blog table
20090804225333    ...pending...    create post table

/home/cbegin/testdb$ migrate up

/home/cbegin/testdb$ migrate status
ID             Applied At          Description
==================================================================
20090802210445 2009-08-04 22:51:17 create changelog
20090804225207 2009-08-04 22:51:17 create author table
20090804225328 2009-08-04 22:54:32 create blog table
20090804225333 2009-08-04 22:54:32 create post table

/home/cbegin/testdb$ migrate version 20090804225207

/home/cbegin/testdb$ migrate status
ID             Applied At          Description
==================================================================
20090802210445 2009-08-04 22:51:17 create changelog
20090804225207 2009-08-04 22:51:17 create author table
20090804225328    ...pending...    create blog table
20090804225333    ...pending...    create post table

The version command is a powerful utility for moving to a specific revision of the database.