使用EF 4.1部署数据库更改 [英] Deploying database changes with EF 4.1

查看:159
本文介绍了使用EF 4.1部署数据库更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有任何关于在EF 4.1代码优先解决方案中部署数据库更改的最佳做法?我知道MS目前不支持EF 4.1的数据库迁移,但显然人们将不时需要这样做。



谢谢

解决方案

将数据库部署到生产后,您必须进行增量更改。这意味着在部署下一个版本之前,您必须在开发框中准备两个数据库:




  • 目前在生产中部署数据库模式的数据库 - 您应该能够从源代码控制中获取此信息,以便始终正确地标记/标记您的生产版本

  • 具有新DB模式的数据库



一旦你有两个数据库,你可以使用一些工具来为你制作不同的SQL脚本。我有两个经验:





这些工具是对于SQL服务器。



一旦你有差异脚本,你可以在你的开发框上测试。请注意,差异脚本无法创建一些更复杂的更改,并要求您创建自定义迁移脚本,例如在重构真实表时将数据现有数据存储在临时表中。另外,如果您在新版本中使用新的种子数据,则必须将其手动添加到脚本中或使用数据比较工具(也由两个产品提供)。



之后可以计划停止生产应用程序数据库备份并运行升级脚本。


Does anyone have any best practices around deploying database changes in an EF 4.1 code-first solution? I know MS does not currently support database migrations for EF 4.1, but obviously people are going to need to do this from time to time.

Thanks

解决方案

Once you deployed database to production you must do incremental changes. It means that before you deploy next version you must prepare two databases in your dev box:

  • Database with DB schema currently deployed in production - you should be able to get this from source control so always correctly label / tag your production releases
  • Database with new DB schema

Once you have two databases you can use some tool to make difference SQL script for you. I have experience with both:

These tools are for SQL server.

Once you have difference script you can test it on your dev box. Be aware that some more complicated changes cannot be created by difference script and require you to create custom migration script for example with storing data existing data in temporary tables while refactoring real table. Also if you use some new seed data in your new version you must add them manually into script or use Data Compare tools (also offered by both products).

After that you can plan outage of your production application, database backup and running upgrade script.

这篇关于使用EF 4.1部署数据库更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆