预期数据库模型是在实时的不一致 [英] Expected database model is inconsistent in real-time

查看:93
本文介绍了预期数据库模型是在实时的不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题,我面临着我在那里写的更新部署的应用程序,以使数据库的问题最新的更新的版本,我们正在部署。基本轮廓如下:

In this question, I was facing an issue where I was writing an update for a deployed application to bring the database up to date with the newer version we are deploying. Basic outline as follows:

      
  • 在开始使用应用程序的当前部署的版本
  •   
  • 补充说明利用现有的新功能的数据库
  •   
  • 添加了新的数据库表和关系
  •   
  • 补充说明依赖于新的DATABSE结构
  • 新功能   
  • 在测试完成后,准​​备部署
  •   
  • Began with currently deployed version of application
  • Added new functionality that used existing database
  • Added new database tables and relationships
  • Added new functionality that depended on the new databse structure
  • Testing complete, ready for deployment

这里的问题是,当前部署的应用程序已使用了数个月,并有大量的数据需要是preserved,所以简单地替换老带新是不可行的(至少不为数据库,但当然它的工作原理为code)中。所以我用下面的步骤来编写SQL脚本的应用程序运行在第一次启动时进行必要的更改数据库没有(来自填充新表除外)触及现有数据的更新版本:

The issue here is that the currently deployed application has been in use for a few months and has a lot of data that would need to be preserved, so simply replacing the old with the new was not viable (at least not for the database, but of course it works for the code). So I used the following steps to write a script in SQL for the updated version of the application to run the first time it starts up to make the necessary changes to the database without touching existing data (aside from populating the new tables):

      
  • 使用VS2010的生成模型数据库功能来创建一个.SQL(最初使用生成数据库模式功能创建的模型)
  •   
  • 删除.SQL的作用于现有的表,除了那些新老表之间添加FKS所有部件
  •   
  • 使用生成的脚本来建立新的数据库
  •   
  • Use VS2010's "Generate database from model" functionality to create a .sql (the model was originally created using the "Generate model from database" functionality)
  • Remove all parts of the .sql that act on the existing tables, except for those that add FKs between new and old tables
  • Use the resulting script to build the new database

听起来pretty的清洁,做,对不对?错误。从模型到数据库的映射是完全错误的新表。总而言之,生成该模型的数据库有在多个指定表(及映射是正确的应用程序的工作),并通过在多个(相同的名称所创建的模型的表产生的数据库,以什么的表,其中在DB产生的模型,但该模型没有映射到它们)。该解决方案最终被改剧本来命名表中的单数,然后一切都准确无误地运行。

Sounds pretty clean and done, right? Wrong. The mapping from the model to the database was all wrong for the new tables. Long story short, the database that generated the model had tables named in the plural (and the mapping was correct and the application worked), and the database generated by the model created tables in the plural (identical names to what the tables where the DB generated the model, but the model did not map to them). The solution ended up being to change the script to name the tables in the singular, and then everything worked flawlessly.

这里发生了什么?在code仍然不变,未进行任何更改到模型制作,和旧表继续正常工作的全部时间,但在某个地方的过程

What happened here? The code remained untouched, no changes were made to the model, and the old tables continued to work fine the entire time, yet somewhere in the process of

      
  • 生成脚本
  •   
  • 删除新表和约束(那些还没有在部署的版本存在)
  •   
  • 运行脚本,重新添加表
  •   
  • Generate script
  • Delete "new" tables and constraints (those that don't yet exist in the deployed version)
  • Run script to re-add the tables

的映射决定是单独指定表(用户,而不是用户,地址代替地址等)。

the mapping decided to be to singularly named tables (User instead of Users, Address instead of Addresses, etc).

任何人都可以向我解释如何/为什么会出现这种情况了?

Can anyone explain to me how/why this would happen this way?

推荐答案

您可能想要看一些那个展鹏供应的工具 - 良好的工具比较两个数据库结构和生成脚本来更新

You might want to look at some of the tools that redgate supply - good tools for comparing two DB structures and generating a script to update.

<一个href="http://www.red-gate.com/?utm_source=google&utm_medium=cpc&utm_content=brand_aware&utm_campaign=redgate&gclid=CIamkumgw6sCFcYPfAodnGVjsQ" rel="nofollow">http://www.red-gate.com/?utm_source=google&utm_medium=cpc&utm_content=brand_aware&utm_campaign=redgate&gclid=CIamkumgw6sCFcYPfAodnGVjsQ

这篇关于预期数据库模型是在实时的不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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