NHibernate and database changes/deployment
deployment, fluent-nhibernate, nhibernate, sql
Solution
I have very good experience using this framework:
http://code.google.com/p/migratordotnet/
Basically you create a class for each database change and annotate the class with a timestamp. The final assembly is then applied in timestamp order.
This means that during development it becomes easy after each checkout to just blindly run the db upgrade process, and know that you are synchronized with the world.
using Migrator.Framework;
using System.Data;
namespace DBMigration
{
[Migration(20080401110402)]
public class CreateUserTable_001 : Migration
{
public void Up()
{
Database.CreateTable("User",
new Column("UserId", DbType.Int32,
ColumnProperties.PrimaryKeyWithIdentity),
new Column("Username", DbType.AnsiString, 25)
);
}
public void Down()
{
Database.RemoveTable("User");
}
}
Problem
I'm looking into using NHibernate and Fluent NHibernate for my next project but one thing I'd like clearing up before hand is how do you manage changes to the database? eg, I have NH + FNH working, application has been deployed and is live but we make a change in the development environment, for example say we add a new property to a entity which is mapped using NH/FNH. How do you apply that change to the database without having to drop the table? Thank you GE