Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails style database migrations for asp.net?

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?

like image 947
captncraig Avatar asked Jan 12 '10 05:01

captncraig


People also ask

What rails db Migrate?

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.

How rails db Migrate works?

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.

How do I migrate a database in Ruby on Rails?

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.

What is difference between model and migration in rails?

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.


2 Answers

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:

  • Migrator.NET
  • RikMigrations and InfoQ article on it

I'm sure there are more out there.

like image 139
marc_s Avatar answered Oct 02 '22 22:10

marc_s


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.

like image 23
Tom Juergens Avatar answered Oct 02 '22 21:10

Tom Juergens