views:

173

answers:

4

For simplicity's sake. I'm using Fluent NHibernate's Automapping combined with NHibernate's SchemaUpdate during runtime. On each run Automapper creates mappings for all entity classes and SchemaUpdate applies the schema to the existing database. I was pleasantly surprised that it works correctly against an empty database as well. It's worked fine so far in a development environment and has allowed me to respond to bugs rather quickly.

My question is whether it is reliable enough to leave in production code. Obviously it doesn't need to run every time the program starts in a production environment but it would be useful for incremental product updates (though I don't plan on making any major changes to the domain after the product ships).

(Perhaps my real question should be how safe is it to use these two tools in conjunction?)

Update

The application has two versions: a standalone desktop and a multiuser client/server. Also due to the nature of the business domain (tax software) I have the luxury of starting with a clean database each year.

+2  A: 

For this to be able to run in production code, the account that the production application uses to connect to your database would have to have permission to change the database schema.

That alone should deter you from this approach, irrespective of the quality/reliability of the NHibernate code.

Greg Beech
A: 

It depends on how critical the data is! I doubt that's such a good idea for a banking system. I have not had any problems with the update apart from one thing. Sometimes it does not rename properly. Further more it's a security risk connecting with an account that can modify the schema like that :)

mhenrixon
A: 

You may want to consider that SchemaUpdate will always make additive and non-destructive changes, resulting in stale columns and nullable columns where they should be non-nullable.

In other words, absolutely not for production use.

serialseb
+1  A: 

I wouldn't risk it. What works well is to run it on a staging server that has been restored from production, then use a database comparison tool (such as Red Gate) to examine the changes and generate a script.

Jamie Ide