使用 ragtime 回滚所有迁移
Rollback all migrations with ragtime
我正在处理一些假设下面的 rollback
函数会回滚所有迁移的代码。但是,它似乎只回滚了最新的迁移。
(defn create-migrator
[spec]
{:datastore (ragtime.jdbc/sql-database spec)
:migrations (ragtime.jdbc/load-resources "migrations")})
(defn rollback
[env]
(-> (create-db-spec env)
(create-migrator)
(ragtime.repl/rollback)))
如何更改 rollback
以回滚所有迁移?
Ragtime rollback
function 接受多个选项。其中有要回滚的迁移数或要回滚到的迁移 ID (amount-or-id
)。
作为 ragtime.jdbc/load-resources
returns 所有迁移的序列,按名称排序(按照惯例,它们将按应用顺序排序),您可以查询第一个并获取其 ID:
(-> (ragtime.jdbc/load-resources "migrations")
(first)
(:id))
如果你的数据库是最新的迁移,我想使用你的迁移序列的 count
作为 amount
也应该有效。
对于给定的示例:
(defn rollback-all
[env]
(let [spec (create-db-spec env)
migrator (create-migrator spec)
count-migrations (-> migrator :migrations count)]
(ragtime.repl/rollback migrator count-migrations)))
我正在处理一些假设下面的 rollback
函数会回滚所有迁移的代码。但是,它似乎只回滚了最新的迁移。
(defn create-migrator
[spec]
{:datastore (ragtime.jdbc/sql-database spec)
:migrations (ragtime.jdbc/load-resources "migrations")})
(defn rollback
[env]
(-> (create-db-spec env)
(create-migrator)
(ragtime.repl/rollback)))
如何更改 rollback
以回滚所有迁移?
Ragtime rollback
function 接受多个选项。其中有要回滚的迁移数或要回滚到的迁移 ID (amount-or-id
)。
作为 ragtime.jdbc/load-resources
returns 所有迁移的序列,按名称排序(按照惯例,它们将按应用顺序排序),您可以查询第一个并获取其 ID:
(-> (ragtime.jdbc/load-resources "migrations")
(first)
(:id))
如果你的数据库是最新的迁移,我想使用你的迁移序列的 count
作为 amount
也应该有效。
对于给定的示例:
(defn rollback-all
[env]
(let [spec (create-db-spec env)
migrator (create-migrator spec)
count-migrations (-> migrator :migrations count)]
(ragtime.repl/rollback migrator count-migrations)))