Is NHibernate SchemaUpdate safe in production code?

陌路散爱 提交于 2019-12-03 17:13:19

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/2065845/is-nhibernate-schemaupdate-safe-in-production-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!