Flyway 的迁移前和迁移后脚本 [英] Pre- and Post-migration scripts for Flyway

查看:28
本文介绍了Flyway 的迁移前和迁移后脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在迁移前后执行挂钩脚本的方法.我有一堆视图和存储过程,希望这个过程是:

I am looking for a way to execute a hook script before and after migration. I have a bunch of views and stored procedures and would like the process to be:

  1. 删除所有视图和存储过程.
  2. 运行迁移.
  3. 重建视图和存储过程.

这可确保对架构的任何更改都反映在相关视图和存储过程中.步骤 (1) 和 (3) 将是 bash 脚本.

This insures that any change to the schema is reflected in related views and stored procedures. Steps (1) and (3) will be bash scripts.

这在 Flyway 中可行吗?

Is this possible in Flyway?

推荐答案

2014-04-29 更新: 现在,通过实现 FlywayCallback 接口,Flyway 3.0 可以实现这一点.

Update 2014-04-29: This is now Possible with Flyway 3.0 by implementing the FlywayCallback interface.

简短的回答是:不,目前还没有.

The short answer is: no, not at this point.

原因如下:我在制定 Flyway 的初始设计时考虑了这一点.不过,我对这方面考虑得越多,我就越清楚这些 pre 和 post 脚本也是迁移不可或缺的一部分,或者至少是迁移离不开的东西想要成功.因此,我建议:

Here is the reason: I thought about this as well as I was laying down the initial design for Flyway. The more I thought about this aspect though, the more it became clear to me that these pre and post scripts are also an integral part of the migration, or at least something a migration can not do without if it wants to be successful. Therefore I would recommend to either:

  • 合并 1、2 和一次迁移 3 个
  • 有 3 个单独的迁移 x.1(删除视图)、x.2(实际迁移)、x.3(重建视图)

如果重复这些步骤,您甚至可以让 x.1 和 x.3 调用存储过程来为您完成工作以避免迁移之间的代码重复.

You might even be able to have x.1 and x.3 call stored procedures that do the work for you to avoid code duplication between migrations if these steps are repeating.

让 Flyway 负责执行对数据库结构的所有更改,这使得整个事情变得更加简单,避免了不同技术的混合.

Having Flyway take care of performing all changes to the database structure makes the whole thing more straightforward, avoiding a mix of different technologies.

这篇关于Flyway 的迁移前和迁移后脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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