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?
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?