advertisement

Print

Cookin' with Ruby on Rails - May
Pages: 1, 2, 3, 4, 5, 6

Migrate back to the most current version: Version 3.

Migrate back to Version 3
Figure 33. (Click to enlarge.)

And our schema is reconstructed.

Schema updated to Version 3
Figure 34. (Click to enlarge.)

As is our database.

Database for Version 3
Figure 35. (Click to enlarge.)

Paul:  OK.  So the first thought I'm getting is that, with migrations, I can pretty easily put my database under version control.  So if I've got a customer-reported bug to fix and the database schema has changed since the release they're using, I can migrate my development and test systems' databases back to the version that matches the software they're running.  And if there are intervening releases, I can step through the whole list doing exactly the same thing.  So basically, I can check out my database right along with my code base.  I have to admit, that is pretty cool.  

So what do we have to do now?  I mean, we've got some garbage in our migrations now.  We have no idea whether or not Boss is going to want to add any information about contributors.   Can we get rid of those migration files?

CB:  We can, but we need to do it carefully.  Rails won't like it if we get things out of synch.  The easiest way to get everything back to where we started is to use Rails to migrate us back to our baseline,

Migrate back to Version 1
Figure 36. (Click to enlarge.)

check our schema to make sure it's what we expect,

See that schema is back to Version 1
Figure 37. (Click to enlarge.)

check our database to make sure it's what we expect,

Version 1 database
Figure 38. (Click to enlarge.)

then go to the migration directory,

Migration files to delete
Figure 39.

and get rid of the garbage.

Migration files all cleaned up
Figure 40.

Now our migrations will start again with the current version being our baseline.

Back to the baseline
Figure 41. (Click to enlarge.)

All cleaned up and ready to move forward.

Paul:  Wow.  That's pretty impressive stuff!  I'll have to play around with it some more.  Right now, though, I've got to take off. Thanks for sharing the pie and for taking me through migrations.  If we can, I'd like to pick up next time we get together with the unit tests.  I'll definitely feel better when I know those are in place.

And so Paul takes off and CB goes back to his 9-5 drudgery, daydreaming just a little about what the future might hold. Could it really happen? Could this actually turn into a chance to do some serious coding in Ruby on Rails? Have some fun and get paid too? Well now, there's something I'd like a lot!  Even better if it comes with free pizza! ;-)

Click to continue your adventure as CB and Paul add Unit tests to their Cookbook app.

Bill Walton is a software development/project management consultant/contractor.


Return to Ruby.