Flyway 输出到 SQL 文件
是否可以将数据库迁移输出到 SQL 文件,而不是直接调用 Flyway 中的数据库更改?
Is it possible to output the db migration to an SQL file instead of directly invoking database changes in flyway?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数情况下不需要这样做,因为使用 Flyway 时数据库迁移本身已经用 SQL 编写。
Most times this will not be needed as with Flyway the DB migrations themselves will already be written in SQL.
是的,这是可能的,而且就我而言,对于不想在产品中允许 Flyway 的 DBA 来说,该功能绝对是必须的。
我从这里修改了代码,这是flyway的一个试运行命令,您可以添加文件编写器并写出migrationDetails:
https://github.com/killbill/killbill/commit/996a3d5fd096525689dced825eac7a95a8a7817e
我是这样做的...项目结构(只是将其从killbill的项目中复制出来并将包重命名为flywaydr:
在Migrator.java add(实现回调并将其放入DbMigrateWithDryRun.java) :
然后编写一些东西来归档,例如:
最后一件事要提的是,我通过maven(谷歌程序集插件+带有依赖项的jar)将其编译并打包到“带有依赖项”的jar(又名fatjar)中并运行它通过如下命令,或者您可以将其作为依赖项包含并通过 mvn exec:exec 目标调用它,这也是我取得成功的方法。
Yes it's possible and as far as I am concerned the feature is an absolute must for DBAs who don't want to allow flyway in prod.
I made do with modifying code from here, it's a dry run command for flyway, you can add a filewriter and write out migrationDetails:
https://github.com/killbill/killbill/commit/996a3d5fd096525689dced825eac7a95a8a7817e
I did it like so... Project structure (just copied it out of killbill's project and renamed package to flywaydr:
In Migrator.java add (implement callback and put it in DbMigrateWithDryRun.java) :
Then to write stuff to file something like:
One last thing to mention, I compile and package this into a jar "with dependencies" (aka fatjar) via maven (google assembly plugin + jar with dependencies) and run it via command like below or you can include it as a dependency and call it via
mvn exec:exec
goal, which is something I had success with as well.我没找到办法。改用mybatis迁移。看起来相当不错。
I didnt find a way. Switched to mybatis migration. Looks quite nice.