如何从源代码控制构建数据库? [英] How should you build your database from source control?
本文介绍了如何从源代码控制构建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关于SO社区Wiki的一些讨论,关于数据库对象是否应该受版本控制。但是,我还没有看到过有关为数据库对象创建内置自动化过程的最佳做法的讨论。
There has been some discussion on the SO community wiki about whether database objects should be version controlled. However, I haven't seen much discussion about the best-practices for creating a build-automation process for database objects.
对我的团队来说是一个有争议的讨论点 - 特别是在评估数据库部署的自动化方法的好处和风险时,开发人员和DBA通常有不同的目标,方法和关注。
This has been a contentious point of discussion for my team - particularly since developers and DBAs often have different goals, approaches, and concerns when evaluating the benefits and risks of an automation approach to database deployment.
我想听取SO社群的一些想法,了解在现实世界中哪些做法已经有效。
我意识到
这里有一些我的前贴片问题关于本主题的关注领域。
- 应该使用自动化生成,
- 如何处理部署脚本中测试环境和生产环境之间的潜在差异?
- 如何处理测试环境与生产环境之间的潜在差异?
- 只是代码(程序,包,触发器,java等)?
- 索引?
- 约束?
- 表定义?
- 表更改脚本? (例如ALTER脚本)
- 一切?
- Sequences?
- Grants?
- User Accounts?
- 序列?
- Grants?
- 用户帐户? >
- How do you deal with one-time things like conversion scripts or ALTER scripts?
- How do you deal with retiring objects from the database?
- Who should be responsible for promoting objects from development to test level?
- How do you coordinate changes from multiple developers?
- How do you deal with branching for database objects used by multiple systems?
- 如何处理转换脚本或ALTER脚本等一次性内容?
- 如何处理
- 如何从数据库中删除对象?
- 如何从发展到测试级别负责
- 如何处理多个系统使用的数据库对象的分支?
- Security issues?
- Data with de-identification concerns?
- Scripts that can't be fully automated?
- 安全问题?
- 有解除身份问题的数据?
- 对于开发人员的错误?
- 遇到意想不到的环境问题?
- 灾难恢复?
- Anecdotal evidence?
- Industry research?
- Industry best-practice recommendations?
- Appeals to recognized authorities?
- Cost/Benefit analysis?
- 轶事证据?
- 行业研究?
- 行业最佳实践建议?
- >
- 成本/效益分析?
- Developers?
- DBAs?
- Data Analysts?
- More than one?
- 开发人员
- DBA?
- 数据分析师? >
- 多个?
推荐答案
以下是您问题的一些答案:
- Should both test and production environments be built from source control? YES
- Should both be built using automation - or should production by built by copying objects from a stable, finalized test environment?
- Automation for both. Do NOT copy data between the environments
- How do you deal with potential differences between test and production environments in deployment scripts?
- Use templates, so that actually you would produce different set of scripts for each environment (ex. references to external systems, linked databases, etc)
- How do you test that the deployment scripts will work as effectively against production as they do in test?
- You test them on pre-production environment: test deployment on exact copy of production environment (database and potentially other systems)
- 测试环境和生产环境都是从源代码控制构建的吗? 是
- 应使用自动化构建,还是通过从稳定的最终测试环境复制对象来构建生产? / li>
- 两者的自动化。请勿在环境之间复制数据
- 如何处理部署脚本中测试环境和生产环境之间的潜在差异?
- strong>使用模板,因此实际上您将为每个环境(例如对外部系统,链接的数据库等的引用)生成不同的脚本集
- 在预生产环境中测试它们:在生产环境的精确副本上测试部署(数据库和潜在的其他系统)
- 应使用自动化构建,还是通过从稳定的最终测试环境复制对象来构建生产? / li>
- Just code (procedures, packages, triggers, java, etc)?
- Indexes?
- Constraints?
- Table Definitions?
- Table Change Scripts? (eg. ALTER scripts)
- Everything?
- Everything, and:
- Do not forget static data (lookup lists etc), so you do not need to copy ANY data between environments
- Keep only current version of the database scripts (version controlled, of course), and
- Store ALTER scripts: 1 BIG script (or directory of scripts named liked 001_AlterXXX.sql, so that running them in natural sort order will upgrade from version A to B)
- 只是代码(程序,包,触发器,java等)?
- 索引?
- 约束?
- 表定义?
- 表更改脚本? (例如ALTER脚本)
- 一切?
- 一切:
- 不要忘记静态数据(查找列表等),因此您不需要在环境之间复制任何数据。
- strong>保存只有当前版本的数据库脚本(版本控制,当然)
- 存储ALTER脚本:1 BIG脚本喜欢001_AlterXXX.sql,以便按照自然排序顺序将其从版本A升级到B)
- Sequences?
- Grants?
- User Accounts?
- see 2. If your users/roles (or technical user names) are different between environments, you can still script them using templates (see 1.)
- 序列?
- Grants?
- 用户帐户? >
- 请参阅2.如果您的用户/角色(或技术用户名)在不同环境之间不同,您仍然可以使用模板对其进行脚本化(参见1)。
- 如何处理一次性转换脚本或ALTER脚本等问题?
- 请参阅2
- 如何处理退出数据库中的对象?
- 从数据库中删除,从源控制中继/ tip>
- 谁应该负责将对象从开发推广到测试级别?
- dev / test /
- 如何协调多个开发人员的变更?
- 请勿为每个开发人员建立单独的资料库。你使用源控制,对吧?在这种情况下,开发人员更改数据库和签入脚本。
- 如何处理多个系统使用的数据库对象的分支? $
- Security issues?
- do not store passwords for test/prod. you may allow it for dev, especially if you have automated daily/nightly DB rebuilds
- Data with de-identification concerns?
- Scripts that can't be fully automated?
- document and store with the release info/ALTER script
- 安全问题?
- 不存储测试/ prod的密码。
- 有关身份识别问题的数据?
- 您可以允许自己每天/每夜重建数据库 / li>
- 如何使流程具有弹性和可执行性?
- 对于开发人员错误?
- 从头开始每天生成测试,升级(使用ALTER从版本A到B)。
- 使用版本控制和备份。
- 将PROD数据库模式与您认为的数据库模式进行比较,尤其是在部署之前。 SuperDuperCool DBA可能修复了票系统中从未出现的错误:)
- 对于灾难恢复?
- To developer error?
- tested with daily build from scratch, and compare the results to the incremental upgrade (from version A to B using ALTER). compare both resulting schema and static data
- To unexpected environmental issues?
- use version control and backups
- compare the PROD database schema to what you think it is, especially before deployment. SuperDuperCool DBA may have fixed a bug that was never in your ticket system :)
- For disaster recovery?
- 轶事证据?
- 行业研究?
- 行业最佳实践
-
-
- 和DBA同意,你不需要说服任何人,我想(除非你需要钱买一个软件,如用于MSSQL的dbGhost )
- Anecdotal evidence?
- Industry research?
- Industry best-practice recommendations?
- Appeals to recognized authorities?
- Cost/Benefit analysis?
- if developers and DBAs agree, you do not need to convince anyone, I think (Unless you need money to buy a software like a dbGhost for MSSQL)
- 开发人员
- DBA?
- 数据分析师? >
- 多于一个?
- 通常,DBA批准模型(在签入之前或之后作为代码审查的一部分)。他们绝对拥有与性能相关的对象。但是一般情况下,团队拥有它[和雇主,当然:]
- Developers?
- DBAs?
- Data Analysts?
- More than one?
- Usually DBAs approve the model (before check-in or after as part of code review). They definitely own performance related objects. But in general the team own it [and employer, of course :)]
这篇关于如何从源代码控制构建数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文