简体   繁体   English

在生产服务器上运行EF迁移的最佳方法是什么?

[英]What is the best way to run EF migration on production server?

What I have: 我有的:

  • VS2015 VS2015
  • ASP.NET 5 MVC 6 Project ASP.NET 5 MVC 6项目
  • EF 7 EF 7
  • Some migrations for my project 我项目的一些迁移
  • Azure website Azure网站
  • I publish via VS "Publish.." wizzard. 我通过VS发布“Publish ..”wizzard。

What I need: 我需要的:

  • I need to know what is the best way to run migrations on the production DB. 我需要知道在生产数据库上运行迁移的最佳方法是什么。
  • I prefer something that can be automated. 我更喜欢可以自动化的东西。 The best solution will be something integrated in the "Publish" wizard. 最佳解决方案将集成在“发布”向导中。

Notes: 笔记:

  • I'm running my migrations on my dev station with "dnx ef database update". 我正在使用“dnx ef database update”在我的开发站上运行迁移。 I guess I can use the webapp PS console but... doesn't seems like the proper way. 我想我可以使用webapp PS控制台,但......似乎不是正确的方法。

  • I know I can generate a SQL script for the migration but this seems to be too manual. 我知道我可以为迁移生成一个SQL脚本,但这似乎太手动了。

  • I remember that the "Publish" wizard had option "Execute EF migrations" in the past. 我记得“发布”向导过去有选项“执行EF迁移”。 Can't see it now. 现在看不到它。

It depends on who has control over the production DB (dev team or separate DBA team). 这取决于谁可以控制生产数据库(开发团队或单独的DBA团队)。

In a customer project that I worked on, each developer had their own copy of the DB, where they tested all their migrations. 在我工作的客户项目中,每个开发人员都有自己的数据库副本,他们在那里测试了所有的迁移。 Once the application code and migration code got checked in, we used TeamCity as a CI server to deploy the website, update the staging DB, and run unit tests & integration tests. 签入应用程序代码和迁移代码后,我们使用TeamCity作为CI服务器来部署网站,更新登台数据库,以及运行单元测试和集成测试。

We provided the SQL scripts (generated by EF) to the DBA team to run against the production DB. 我们将SQL脚本(由EF生成)提供给DBA团队以针对生产数据库运行。 Our dev team never touched the production DB. 我们的开发团队从未接触过生产数据库。

If you're allowed to update the production DB, you can do it yourself. 如果您被允许更新生产数据库,您可以自己完成。 But I would highly recommend inspecting and then running EF-generated scripts that you can roll back if necessary. 但我强烈建议检查然后运行EF生成的脚本,必要时可以回滚。 Also, don't forget to back up the production DB as needed. 另外,不要忘记根据需要备份生产数据库。

Since you want automation (and if you are comfortable with it), you can use your CI system to update your production DB, the way my team and I updated our staging DB. 由于您需要自动化(如果您对它感到满意),您可以使用CI系统更新您的生产数据库,这是我的团队和我更新我们的暂存数据库的方式。

Hope that helps! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF 5-模型首次数据库迁移:发布到远程生产服务器后要更改模型? - EF 5 - Model first database migration: change model after published to remote production server? 自动迁移在生产服务器上运行 - Automatic migration runs on a production server 确定本地/登台/制作的URL的最佳方法是什么? - What is the best way to determine URL for local/staging/production? 从服务器下载文件的最佳方法是什么? - What is the best way to download file from server 在EF中添加子列表的最佳方法 - Best Way to Add Sublist in EF 将图像上传到服务器的最佳方法是什么? 保存在数据库还是服务器文件夹中? - what is the best way to upload images to server? save in database or in server folder? 使用AJAX将一些XML发送到服务器的最佳方法是什么? - What would be the best way to send some XML to server using AJAX? 通过在服务器上保存静态表来提高性能的最佳和正确方法是什么? - What is the best and right way to improve performance by saving static tables on server? 在服务器端获取日期和时间的最佳方法是什么? - What is the best way to get the date and time in server side? 服务器向Web客户端发送消息的最佳方式是什么? - What's the best way for the server to send messages to a web client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM