DataMapper Migrations

Posted by glenn on Sunday, October 05, 2008

Posted in datamapper

datamapper-migrations

I’ve been working on some merb related things of late, and I’m planning on writing a more detailed article on creating a merb application from scratch as so many of the tutorials out there kind of leave you hanging. In the interim though, I’m just going to touch on a little nugget of information that isn’t very well publicised regarding DataMapper, one of the ORMs that gets used with merb.

ActiveRecord Style Migrations with DataMapper

That’s right, you aren’t left having to wrestle with the command line and ALTER TABLE statements just because you’ve left ActiveRecord behind. All the migration joy you’ve come to love with ruby on rails can come and live with you happily with merb and DataMapper.

First things first, you’ll want to generate a new migration:

We should now have a file named 001_my_migration.rb and if we look at it, it won’t be too foreign based on our ActiveRecord experiences:

To pad it out with some code that is actually useful, add in the definitions for what you want done:

Running the DataMapper Migration

And now that we’ve got the migration we are happy with, applying it to our underlying database is just a matter of the following:

Glenn Gillen is a ruby and ruby on rails developer with clients in London, New York, Los Angeles, and Australia. Ruby Pond specialise in social networking development, and social and online marketing. Contact Ruby Pond if you wish to discuss hiring Glenn or one of our other developers for your own project.
blog comments powered by Disqus