公司项目需要兼容国产数据库达梦,达梦和oracle 相似度还是非常高的。绝大部分的sql语句都能共用。但是flyway 本身是不支持达梦的,但是不着急,flyway 本身是开源的,那么我们是否能将达梦适配到 oracle的flyway呢
因公司项目之前是用6.3.3 版本,现在版本已经变化挺大了,所以还是使用tag 为6.3.3 的
我们直接打包是不能直接打包成功的
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project flyway-core: Fatal error compiling
网上的解释是,版本不一致,但按照他们的方法一个个设置,怎么都没用。
后面怀疑是idea 的问题,用mvn clean package 打包做测试
结果发现mvn 的提示清晰多了
无效的标记: --release
这样打包就可以正常使用了
org.flywaydb.core.internal.jdbc.DatabaseType类中
if (databaseProductName.startsWith("Oracle"))) {
return ORACLE;
}
增加||databaseProductName.startsWith("DM")
if (databaseProductName.startsWith("Oracle")||databaseProductName.startsWith("DM")) {
return ORACLE;
}
public class DriverDataSource implements DataSource {
public enum DriverType {
...
ORACLE("jdbc:oracle", "oracle.jdbc.OracleDriver"),
DM("jdbc:dm", "dm.jdbc.driver.DmDriver"),
我们要兼容达梦,达梦的版本是8.X 而 Oracle 是需要10.x 以上的,所以我们不校验版本
Exception in thread "main" org.flywaydb.core.internal.exception.FlywayDbUpgradeRequiredException: Oracle upgrade required: Oracle 8.1 is outdated and no longer supported by Flyway. Flyway currently supports Oracle 10 and newer.
因为我们达梦直接使用oracle 的语法,但是版本还是达梦的。所以我们直接注释掉。有两处
- 第一处为:
protected final void ensureDatabaseIsRecentEnough(String oldestSupportedVersion) {
// if (!getVersion().isAtLeast(oldestSupportedVersion)) {
// throw new FlywayDbUpgradeRequiredException(databaseType, computeVersionDisplayName(getVersion()),
// computeVersionDisplayName(MigrationVersion.fromVersion(oldestSupportedVersion)));
// }
}
- 第二处为:
/**
* Ensures this database it at least at recent as this version otherwise suggest upgrade to this higher edition of
* Flyway.
*
* @param oldestSupportedVersionInThisEdition The oldest supported version of the database by this edition of Flyway.
* @param editionWhereStillSupported The edition of Flyway that still supports this version of the database,
* in case it's too old.
*/
protected final void ensureDatabaseNotOlderThanOtherwiseRecommendUpgradeToFlywayEdition(String oldestSupportedVersionInThisEdition,
Edition editionWhereStillSupported) {
// if (!getVersion().isAtLeast(oldestSupportedVersionInThisEdition)) {
// throw new FlywayEditionUpgradeRequiredException(
// editionWhereStillSupported,
// databaseType,
// computeVersionDisplayName(getVersion()));
// }
}
<dependency>
<groupId>com.dm</groupId>
<artifactId>DmJdbcDriver</artifactId>
<version>1.8.0</version>
</dependency>
public class MainTest {
public static void main(String[] args) {
Flyway flyway = Flyway.configure().dataSource("jdbc:dm://192.168.0.1:5236",
"root", "123456").load();
// 第一步先执行baseline,之后才能执行migrate
flyway.baseline();
// flyway.migrate();
System.out.println("执行完了");
}
}
也正常生成 flyway_schema_history
问题解决:flyway源码编译,报:flyway-core: Fatal error compiling: 无效的标记: --release