Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is NHibernate SchemaUpdate safe in production code?

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.

like image 656
Kenneth Cochran Avatar asked Jan 14 '10 16:01

Kenneth Cochran


4 Answers

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.

like image 149
Greg Beech Avatar answered Nov 13 '22 04:11

Greg Beech


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.

like image 37
Jamie Ide Avatar answered Nov 13 '22 04:11

Jamie Ide


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.

like image 37
SerialSeb Avatar answered Nov 13 '22 05:11

SerialSeb


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 :)

like image 42
mhenrixon Avatar answered Nov 13 '22 04:11

mhenrixon