“特定于数据库"的最佳方式Flyway的SQL脚本 [英] Best way for "database specific" sql scripts with Flyway

查看:67
本文介绍了“特定于数据库"的最佳方式Flyway的SQL脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在当前项目中使用Flyway进行数据库迁移,我非常喜欢它.我目前在PROD-和Derby的TEST环境中使用Oracle.

I started to use Flyway in my current project for database migrations and I like it very much. I currently use Oracle in PROD- and Derby in TEST-Environment.

很快,我确实遇到了特定于数据库的sql命令的问题,例如

Pretty soon, I did run in the problem of database specific sql commands, e.g.

  • ALTER TABLE T1 MODIFY F1 VARCHAR(256); on Oracle vs
  • ALTER TABLE T1 ALTER F1 SET DATA TYPE VARCHAR(256);在Derby上.
  • ALTER TABLE T1 MODIFY F1 VARCHAR(256); on Oracle vs
  • ALTER TABLE T1 ALTER F1 SET DATA TYPE VARCHAR(256); on Derby.

我看不到编写供应商中立的alter table修改列数据类型" sql的方法.

I can't see a way to write a "vendor neutral alter table modify column datatype" sql.

使用Flyway处理此问题的最佳方法是什么?

What's the best way to deal with this problem using Flyway?

推荐答案

您可以使用flyway.locations属性.

You can use the flyway.locations property.

在测试中看起来像这样:

In test in would look like this:

flyway.locations=sql/common,sql/derby

和产品:

flyway.locations=sql/common,sql/oracle

然后,可以在特定于数据库的位置中,在特定于数据库的特定语句(V2__Alter_table.sql)的公用副本和不同副本中包含公用语句(V1__Create_table.sql).

You could then have the common statements (V1__Create_table.sql) in common and different copies of the DB-specific statements (V2__Alter_table.sql) in the db-specific locations.

我认为,更好的解决方案是在生产和测试中使用相同的数据库.是的,您确实会损失一些性能,但另一方面,您还可以消除环境之间的另一个差异(以及潜在的错误源).

An even better solution, in my opinion, is to have the same DB in prod and test. Yes, you do lose a bit of performance, but on the other hand you also eliminate another difference (and potential source of errors) between the environments.

这篇关于“特定于数据库"的最佳方式Flyway的SQL脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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