假设我在我的计算机上本地托管了一个网站和该网站的数据库(用于开发)和另一个托管的数据库(用于生产)......即首先我在 dev db 上进行更改,然后我对 prod 进行更改D B。
将我在本地数据库上所做的更改传输到托管数据库的最佳方法是什么?
如果重要的话,我正在使用 MS Sql Server (2008)
假设我在我的计算机上本地托管了一个网站和该网站的数据库(用于开发)和另一个托管的数据库(用于生产)......即首先我在 dev db 上进行更改,然后我对 prod 进行更改D B。
将我在本地数据库上所做的更改传输到托管数据库的最佳方法是什么?
如果重要的话,我正在使用 MS Sql Server (2008)
使用 Visual Studio 和 SQL Server 执行此操作的正确方法是将数据库项目添加到 Web 应用解决方案。数据库项目应该有 SQL 文件,可以在新服务器上完全重新创建整个数据库以及所有必要的表、过程用户和角色。
这样,它们也包含在所有其余代码的源代码控制中。
数据库项目中有一个Changes子文件夹,我将用于后续版本的数据库应用任何新更改或添加的 SQL 文件放在其中。
The SQL in the files should be written with proper "if exists" blocks such that it can be run safely multiple times on an already updated database without error.
As a rule, you should never make your changes directly in the database - instead modify the SQL script in the project and apply it to the database to make sure your source code (the SQL files) is always up to date.
当开发人员测试/验证他们的更改时,我会通过开发人员编写的更改脚本来迁移更改。(移动大数据除外。)所有脚本都存储在源代码控制系统中。并且可以由 DBA 验证。
它是手动的,有时耗时但有效、安全和受控的过程。
数据库太重要了,无法从开发人员那里复制。
有一些工具可以帮助创建/验证这些脚本。请参阅http://www.red-gate.com/ 我使用他们的工具比较了 2 个数据库以创建脚本。布赖恩
If the changes are small, I sometimes make them by hand. For larger changes, I use Red Gate's SQL Compare to generate change scripts. These are hand-verified and run in the QA environment first to make sure they don't break anything. For large changes, we run a special backup prior to making the change both in QA and in production.
我们曾经使用 Ron 提供的方法。对于拥有专门的 DBA 团队的大型项目来说,这很有意义。但是,如果您没有专门为 DB 编写代码的开发人员,那么这种方法会耗费大量时间和资源。
使用 RedGate DB 比较的方法也不好。你还有很多手工工作,你可以错误地跳过一些步骤。
它需要更好的东西。这就是我们构建“Agile DB Recreation/Import/Reverse/Export tool”的原因 ,该工具是免费的。
优点:您的开发人员使用任何首选工具来开发 DEV DB。然后他们运行 DB RIRE,它生成逆向数据库(表、视图、存储过程等)并将数据导出到 XML 文件中。您可以将 XML 文件保存在任何代码存储库系统中。
And the second step is to run DB RIRE one more time to generate difference scripts between structure and data in XML files and in Production DB.
Of course you can make as much iterations as you need.