I am in love with the rails style of updating db schema. I can define a migration as a class with fairly simple, yet powerful syntax. I can run the updates with a single command and all of my models are updated. They are committed to source control and can be easily read, modified, and undone.
My current way of doing it for my asp.net mvc project is to open up the server explorer, manually change the database fields, then regenerate all of my linq-to-sql classes. This method is cumbersome, error prone, and lacks almost all of the advantages listed above. I am fairly sure there has to be a better way.
Can anybody enlighten me?
A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.
When you run db:migrate, rails will check a special table in the database which contains the timestamp of the last migration applied to the database. It will then apply all of the migrations with timestamps after that date and update the database table with the timestamp of the last migration.
Go to db/migrate subdirectory of your application and edit each file one by one using any simple text editor. The ID column will be created automatically, so don't do it here as well. The method self. up is used when migrating to a new version, self.
Rails Model (Active Record) works with SQL, and Rails Migration works with DDL. Rails Model supports ways to interact to with the database, while Rails Migration changes the database structure. A migration can change the name of a column in books table.
Rob Conery's Subsonic has something like migrations in .NET:
http://blog.wekeroad.com/2007/10/03/subsonic-migrate-me/
There are plenty of other toolkits offering similar approaches:
I'm sure there are more out there.
Old question, but still valid, so here's an additional answer that might be helpful to someone.
This question/answer here on SO has a list of candidates, and don't forget to check out Fluent Migrator as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With