Clojure:如何在生产环境中 运行 进行复杂的数据库迁移?

Clojure: How to run complex DB migration in production?

假设您有一项任务要执行复杂的数据库迁移,作为将新版本发布到生产环境的一部分,您通常如何在 Clojure 项目中执行此操作?

新“大”版本迁移的示例:

您将如何以自动化方式进行第二次迁移?必须执行所有 3 个迁移才能成功发布新版本。

看起来像 Flyway DB has Java migrations,这看起来正是我们所需要的,但是有什么方法可以从 Clojure 中使用它吗?

也许可以添加另一个 .clj 文件 along with other .sql migrations 并且 Flyway 会选择它?

我有点惊讶,我无法为 Clojure 中看似非常常见的任务提供任何示例,只有简单的 SQL 查询。

引用 Migratus README:

Defining a code-based migration

Create a code-based migration by adding a .edn file to your migrations directory that contains the namespace and up/down functions to run, e.g. resources/migrations/20170331141500-import-users.edn:

{:ns app.migrations.import-users
 :up-fn migrate-up
 :down-fn migrate-down} 

Then, in src/app/migrations/import_users.clj:

(ns app.migrations.import-users)

(defn migrate-up [config]
;; do stuff here
)

(defn migrate-down [config]    
;; maybe undo stuff here
) 

The up and down migration functions should both accept a single parameter, which is the config map passed to Migratus (so your migrations can be configurable). You can omit the up or down migration by setting :up-fn or down-fn to nil in the EDN file.