简体   繁体   English

您如何处理数据库表的配置管理?

[英]How do you deal with configuration management of Database Tables?

How do you deal with source control management and automated deployment (configuration management) of database tables. 您如何处理数据库表的源代码管理和自动部署(配置管理)。 I work in a SQL Server environment and it's pretty easy to script out drop and create files for stored procedures/triggers/functions even jobs. 我在SQL Server环境中工作,编写拖放脚本并为存储过程/触发器/函数甚至作业创建文件非常容易。 It's also easy to handle scripting out the creation of a new db table. 处理创建新数据库表的脚本也很容易。 However, if at a later point you want to modify that table, you can't necessarily just drop it and recreate it with the new field for fear of losing data. 但是,如果以后要修改该表,则不必担心会丢失数据而不必只是删除它并使用新字段重新创建它。 Is there an automated way to deal with this problem? 有没有自动的方法来解决这个问题? Do you script out a temp table and backfill after updating the new changed table? 更新新的更改表后,是否编写临时表并回填脚本? (could be rough if there is a lot of data) (如果有很多数据,可能会很粗糙)

Any suggestions would be greatly appreciated. 任何建议将不胜感激。

Tools like Red-gate's SQL Compare are invaluable in making sure you have a complete script. 诸如Red-gate的SQL Compare之类的工具对于确保您具有完整的脚本非常有用。 You still may need to manually adjust it to make sure the objects are scripted in the correct order. 您仍然可能需要手动对其进行调整,以确保以正确的顺序编写了对象脚本。 Make sure to script triggers and constraints, etc as well as tables.In general you will want to use alter commands instead of drop and create especially if the table is at all large. 确保对触发器,约束等以及表编写脚本。通常,您将要使用alter命令而不是drop and create,尤其是在表很大的情况下。

All our tables and functions and stored procs are required to be under source control as well, so we can return to old versions if need be. 我们所有的表和函数以及存储的proc也都必须处于源代码控制之下,因此如果需要,我们可以返回旧版本。 Also our dbas periodically delte anything they find not in Source COntrol, so that keeps developers from forgetting to do it. 此外,我们的dbas会定期删除未在Source COntrol中找到的任何内容,从而使开发人员避免忘记这样做。

Of course all development scripts being promoted to production should be run on a QA or staging server first to ensure the script will run properly (and with no changes required) before it is run on prod. 当然,所有升级到生产环境的开发脚本都应首先在QA或登台服务器上运行,以确保脚本在产品上运行之前可以正确运行(无需任何更改)。 Also the timing of running on prod needs to be considered, you don't want to lock out users especially during busy periods and time has shown that loading scripts to production late on Friday afternoon is usually a bad idea. 另外,还需要考虑在产品上运行的时间,您不想将用户锁定,尤其是在繁忙的时期,并且时间表明在星期五下午晚些时候将脚本加载到生产中通常不是一个好主意。

We had similar experiences working with Oracle DB. 我们在使用Oracle DB方面有类似的经验。 We established procedures for adopting SVN and automated scripts (that pull changes from SVN) in order to build patches. 我们建立了采用SVN和自动脚本(从SVN中提取更改)以构建补丁的过程。 Please see http://www.scmsupport.com/scm.php?go=home.html and http://scmsupport.wordpress.com/ for more details. 有关更多详细信息,请访问http://www.scmsupport.com/scm.php?go=home.htmlhttp://scmsupport.wordpress.com/

There are tools available that help you develop your schema, develop changes, version those changes and will help you compare the differences between versions and even generate the SQL to make the DDL changes. 有可用的工具可帮助您开发架构,开发更改,对这些更改进行版本化,并可以帮助您比较版本之间的差异,甚至生成SQL以进行DDL更改。

For example, check out Embarcadero Change Manager and other products offered by Embarcardero. 例如,查看Embarcadero Change Manager和Embarcardero提供的其他产品。

You can automatically create the initial creation script, but ALTER scripts really need to be hand-coded on a case-by-case basis, because in practice you need to do custom stuff in them. 您可以自动创建初始创建脚本,但实际上,ALTER脚本确实需要根据具体情况进行手工编码,因为在实践中,您需要在其中编写自定义内容。

In any case, you'll need some way of creating apply and rollback scripts for each change, and have an installer script which runs them (and a rollback which rolls them back of course). 无论如何,您都需要某种方式为每次更改创建Apply和Rollback脚本,并需要有一个运行它们的安装程序脚本(当然还有一个Rollback可以回滚它们)。 Such an installer should probably remember what version the schema is in, and run all the necessary migrations, in the right order. 这样的安装程序可能应该记住该模式所在的版本,并以正确的顺序运行所有必要的迁移。

See my article here: 在这里查看我的文章:

http://marksverbiage.blogspot.com/2008/07/versioning-your-schema.html http://marksverbiage.blogspot.com/2008/07/versioning-your-schema.html

It varies, depending on how you want to treat existing data and how extensive the schema changes are, but even in Management Studio, before you commit changes, you can generate a script of all the changes. 它的变化取决于您要如何处理现有数据以及架构更改的范围,但是即使在Management Studio中,在提交更改之前,您也可以生成所有更改的脚本。

For a lot of data or where there are constraints or foreign keys, even simple ALTER operations can take a significant amount of time. 对于大量数据或存在约束或外键的地方,即使是简单的ALTER操作也要花费大量时间。

Ohh forgot to say, make sure you have a good set of database backups before loading schema changes to production. 哦,忘了说了,在将架构更改加载到生产之前,请确保您具有一组良好的数据库备份。 Better safe than sorry. 安全胜过遗憾。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM