我应该担心使用Flyway时产生幂等迁移吗? [英] Should I be worried about creating idempotent migrations while using Flyway?

查看:86
本文介绍了我应该担心使用Flyway时产生幂等迁移吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关Flyway的博客文章,名称为将Flyway DB与分布式版本控制一起使用的经验教训.作者的建议之一是创建幂等迁移.

I have been reading a blog post about Flyway, called Lessons Learned Using Flyway DB with Distributed Version Control. One of the author's suggestions is to create idempotent migrations.

文章引用:

在一个完美的世界中,每个迁移只会针对每个迁移运行一次 数据库.

In a perfect world, each migration will only be run once against each database.

在完美世界中,就是这样.

In a perfect world, that is.

实际上,在某些情况下,您需要重新运行 迁移到同一数据库.通常这是由于 沿某处迁移失败,导致您不得不 在获取数据库之前回溯成功迁移的步骤 回到工作状态.发生这种情况时,它会非常有用 以便以幂等的方式编写迁移.

In actuality, there will be cases where you’ll need to re-run migrations against the same database. Often this will be due to a failed migration somewhere along the line, causing you to have to retrace your steps of successful migrations before to get the database back in a working state. When this happens, it’s incredibly helpful for the migration to be written in an idempotent manner.

假设我使用的数据库支持DDL事务,在创建这些迁移sql时我应该担心幂等性吗?

Assuming I am using a database that supports DDL transactions, should I be worried about idempotency while creating these migration sqls?

推荐答案

通常不,尤其是当您具有支持DDL事务的数据库时.

In general no, especially when you have a database that supports DDL transactions.

版本化迁移被设计为只能运行一次并且可以运行,但是不必具有幂等性(实际上没有好处).

Versioned migrations are designed to run exactly once and can, but don't have to be idempotent (virtually no benefit).

另一方面,可重复的迁移必须是幂等的,因为它们将一遍又一遍地运行.

Repeatable migrations on the other hand have to be idempotent as they'll be run over and over again.

Flyway让您非常轻松地从头开始重新创建数据库,这是您在实验时应首选的方法.

Flyway let's you very easily recreate your database from scratch, and that's the approach you should favor when experimenting.

这篇关于我应该担心使用Flyway时产生幂等迁移吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆