在SO社区wiki上有一些关于数据库对象是否应该进行版本控制的讨论.但是,I haven't seen much discussion about the best-practices for creating a build-automation process for database objects.

对于我的团队来说,这一直是一个有争议的讨论点-特别是在判断数据库部署自动化方法的好处和风险时,开发人员和DBA通常有不同的目标、方法和顾虑.

I would like to hear some ideas from the SO community about what practices have been effective in the real world.

我知道哪种做法是最好的,这有点主观,但我认为一个很好的对话,关于哪些工作可以对很多人有帮助.

Here are some of my teaser questions about areas of concern in this topic. These are not meant to be a definitive list - rather a starting point for people to help understand what I'm looking for.

  1. Should both test and production environments be built from source control?
    • 两者都应该使用自动化构建-还是应该通过从稳定的、已完成的测试环境复制对象来构建生产?
    • 如何在部署脚本中处理测试环境和生产环境之间的潜在差异?
    • 如何测试部署脚本在生产环境中的工作效率,以及它们在测试中的工作效率?
  2. 什么类型的对象应该进行版本控制?
  3. 哪些类型的对象不应进行版本控制?
  4. 在SCM存储库中应该如何组织数据库对象?
    • 如何处理转换脚本或更改脚本等一次性内容?
    • 如何处理数据库中注销的对象?
    • 从开发到测试级的promoting个对象应该由谁负责?
    • 如何协调来自多个开发人员的更改?
    • 如何处理多个系统使用的数据库对象的分支?
  5. 这个过程有哪些例外(如果有的话)是合理的?
    • 安全问题?
    • 具有取消标识问题的数据?
    • 无法完全自动化的脚本?
  6. 您如何才能使流程具有弹性和可执行性?
    • 到开发人员错误?
    • 应对意外的环境问题?
    • 用于灾难恢复?
  7. 您如何让决策者相信DB-SCM的好处确实证明了成本是合理的?
    • 轶事证据?
    • 行业研究?
    • 行业最佳实践建议?
    • 向公认当局提出上诉?
    • 成本/效益分析?
  8. 在此模型中,谁应该"拥有"数据库对象?
    • 开发人员?
    • DBA?
    • 数据分析师?
    • 多个?

推荐答案

以下是对您问题的一些回答:

  1. 测试和生产环境都应该从源代码控制构建吗?YES
  2. What types of objects should be version controlled?
    • 只是代码(过程、包、触发器、java等)?
    • 索引?
    • 约束?
    • 表格定义?
    • 表更改脚本?(例如,更改脚本)
    • 每件事
    • 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)
  3. 哪些类型的对象不应进行版本控制?
  4. 如何在SCM存储库中组织数据库对象?
  5. 这个过程有哪些例外(如果有的话)是合理的?
    • 安全问题?
    • do not store passwords for test/prod. you may allow it for dev, especially if you have automated daily/nightly DB rebuilds
    • 具有取消标识问题的数据?
    • 无法完全自动化的脚本?
    • document and store with the release info/ALTER script
  6. How can you make the process resilient and enforceable?
    • 到开发人员的错误?
    • 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
    • 面对意想不到的环境问题?
    • 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 :)
    • 用于灾难恢复?
  7. 您如何说服决策者,DB-SCM的好处确实证明了成本的合理性?
  8. 在此模型中,谁应该"拥有"数据库对象?
    • 开发人员?
    • DBA?
    • 数据分析师?
    • 多个?
    • 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 :)]

Database相关问答推荐

如何自动更新不同的数据库?

从仅连接器电源查询制作图表

即使将enable_seqscan设置为关闭,也未使用数组列上的 GIN 索引?

如何在构建时创建填充的 MySQL Docker 映像

将 Redis 数据同步到 MySQL 的最佳策略是什么?

被删除的行占用的空间会被重新使用吗?

Neo4j:逐步创建自动索引

使用存储过程是一种不好的做法吗?

xtradb vs innodb

postgresql 在 where 子句中使用 json 子元素

应用程序用户应该是数据库用户吗?

你可以在一个 Hibernate Session 中有多个事务吗?

如何将 Android 手机上的 SQLite 数据库与服务器上的 MySQL 数据库同步?

我应该将用户 ID 公开吗?

获取数据库路径

如何在多列上创建 FULLTEXT 索引?

Firebase 排行榜排名

查询 oracle clob 列

Data Mapper 是不是比 Active Record 更现代的趋势

做或不做:将图像存储在数据库中