Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!

Justin Etheredge is a Senior Consultant for Dominion Digital in Richmond, Virginia - United States. He likes to blog quite a bit at http://www.codethinked.com with hopes that someone out there might read it. When he isn't writing software or working on his computer... wait, he is always doing that. Anyways, Justin likes programming, a lot. Justin has posted 24 posts at DZone. View Full User Profile

Migrations in C# using RikMigrations

12.17.2008
Email
Views: 3000
  • submit to reddit

For those of you who have used Ruby on Rails before, you most likely already know what migrations are, and you probably love them! They are such a simple idea and once you start using them you'll wonder why you never thought of them. Recently I was doing a bit of work which required me to do some build automation, and (after prodding from some co-workers) I decided that we needed to do some migrations. Migrations are easier to just show you than explain, so I am going to move right into some code. First though, I am going to explain to you the tool that I chose.

I searched around a bit, and found two different tools for doing Migrations in .NET. One was called MigratorDotNet and the other was called RikMigrations. I evaluated them both, and in the end I chose RikMigrations because I liked the way that it searched an assembly for embedded migrations (instead of pointing to a folder of source files) and also allowed you to have multiple sets of Migrations in the same project by identifying them with keys. I'm assuming that this could have been accomplished in MigratorDotNet by using multiple folders, but I chose not to take that approach.

Okay, so let's see some code. First we are going to start off by creating a blank database called "TestMigratorApp". Next I am going to pretend that I have received a requirement for creating a user table with just two columns. One for "Id" which is going to be an auto-incrementing integer column, and another for username. Obviously our user table would be a bit more complex than this, but we don't want to clutter the example with too much extra crap.

Read the rest of this post at CodeThinked.com

References
Published at DZone with permission of its author, Justin Etheredge. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)