tags:

views:

566

answers:

1

I'm using NHibernate mappings as a defining schema for my app in the development phase and for the schema definition I'm using the NHibernate.Tool.hbm2ddl.SchemaExport() method to generate a createscript.

Now, I have considered using the Configuration.GenerateSchemaUpdateScript() method to generate database changescripts like this:


var dialect = Dialect.GetDialect(configuration.Properties);
string[] schemaUpdateScript;
using (var conn = new SqlConnection(
        configuration.GetProperty("connection.connection_string")))
{
  conn.Open();
  schemaUpdateScript = configuration.GenerateSchemaUpdateScript(dialect, 
                            new DatabaseMetadata(conn, dialect));
}

After this I'll save the schema update script to timestamp-named script-files.

Is this a good way to manage schema changes in NHibernate?

Are there any major drawbacks?

A: 

In short - it depends. I've used it to create script which I then edited by hand, but I'm sure I read somewhere it will not create new non-null columns for existing tables - which seems to make sense, as how would NHibernate know how to populate the columns?

David Kemp
yeah, the non nulls is a problem. The missing Default-value feature for columns would be nice here, though. But there's no way around adjusting the sql by hand in most cases anyway.
Christian Dalager