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

查看:213
本文介绍了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. 重建视图和存储过程。

这确保对模式的任何更改都反映在相关视图和存储过程中。

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

推荐答案

解决方案

更新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.

我想到了这一点,以及我正在放下飞利的初始设计。我对这方面的想法越多,我越清楚这些前和后脚本也是迁移的一个组成部分,或者至少迁移不能没有想成功。因此,我建议:

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 in a single migration

  • 有3次单独迁移x.1(drop views),x.2(实际迁移),x.3(rebuild views)

您甚至可以让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天全站免登陆