持续交付中的生产数据迁移模式[英] production data migration patterns in continuous delivery

本文是小编为大家收集整理的关于持续交付中的生产数据迁移模式的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

连续交付时生产中的关系数据库(和模式)迁移模式是什么?

在许多传统发展中,DBA在当前发行周期中创建的许多较小的脚本中安排了一个大型迁移脚本.但是在CD中,开发人员可能希望将更改推向生产,而不是等待其他脚本编译.

我知道在Rails Emigration上,但对我来说,使用RAW SQL脚本看起来更合理.

我还看到了诸如 flyway 管理迁移的工具,但我没有读过许多人在生产中使用它们.这就是为什么我想知道这里有什么常见实践.

推荐答案

飞行非常适合连续交付/部署.许多客户在包括生产在内的所有环境中使用它.

对于跨环境级联的DB迁移的最重要的事情是要有一个三步过程:

步骤1

旧的应用程序代码与旧DB一起使用.

步骤2

新的应用程序代码将被部署,并在启动时迁移数据库.此迁移必须向后兼容,以便旧的应用程序代码仍然与新的DB一起使用.这是必不可少的,因为:

  • 然后,您可以进行滚动升级,一次升级一个节点,直到所有节点都具有新的应用程序代码
  • 如果新应用程序损坏,请立即回滚至旧的应用程序代码

此步骤可能涉及兼容性视图和触发器来完成这项工作.

步骤3

已证明更改可行后,下一个版本的应用程序代码获取 与必要的DB迁移一起部署,以丢弃任何剩余的过时(从步骤1)和兼容性(从步骤2)结构.

其他推荐答案

以单个(RAW)SQL文件对数据库实现更改,然后使用 sqlpatch 构建迁移脚本.

我通常只有一个单独的数据库git存储库,并且附有一个CD环境.我通常有一个生产和开发数据库,​​当我推到相应的分支时会自动迁移.

此设置使设置一个功能分支的另一个数据库非常容易. SQLPATCH负责单独的SQL文件中的所有依赖项,因此我可以轻松地合并另一个分支中的功能分支.

本文地址:https://www.itbaoku.cn/post/597566.html

问题描述

What are relational database (and schema) migration patterns on production in continuous delivery?

In many traditional developments the DBA arranges a big migration script out of the many smaller scripts created in the current release cycle. But in CD the developer may want to push the change now to production, not wait to compile them with other scripts.

I know on rails-migration but to me it looks more reasonable to use raw sql scripts.

I've also seen tools like flyway to manage migrations but I have not read of many people using them in production. This is why I wonder what are the common practices here.

推荐答案

Flyway works great for continuous delivery/deployment. Many clients use it across all environments, including production.

The single most important thing for cascading DB migrations across environments is to have a 3 step process:

Step 1

Old application code works together with old DB.

Step 2

New application code get deployed, and migrates DB on startup. This migration must be backwards-compatible so that old application code still works with the new DB. This is essential because:

  • you can then do rolling upgrades, upgrading one node at a time until all nodes have the new application code
  • rollback immediately to the old application code if the new one is broken

This step may involve compatibility views and triggers to do the job.

Step 3

After the changes have been proven to work, the next version of the application code gets deployed together with the necessary DB migrations to discard any remaining outdated (from step 1) and compatibility (from step 2) structures.

其他推荐答案

Implement changes to your database as single (raw) sql files, then use sqlpatch to build a migration script.

I usually have a single git repository for the database alone and a cd environment attached to it. I usually have a production and a development database that are automatically migrated when I push to corresponding branches.

This setup makes is very easy to setup another database for a feature branch and to experiment with it. Sqlpatch takes care of all the dependencies in the separate sql files so that I can easily merge a feature branch in another branch.