FlyWay迁移脚本

时间:2017-09-19 15:50:29

标签: java flyway

你能帮忙为什么flyway无法安装脚本 ?

我的架构是空的,只有一个表创建了flyway。但它也是空的。

如何正确配置FlyWay?我的脚本具有以下形式

V1__20170918_Initial_structure.sql

18:43:30,773 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG Flyway:40 - DDL Transactions Supported: false
18:43:30,773 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG Flyway:40 - Schema: TEST_SERVER
18:43:30,778 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG FeatureDetector:40 - Spring Jdbc available: false
18:43:30,779 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG SqlScriptFlywayCallback:40 - Scanning for SQL callbacks ...
18:43:30,779 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning for classpath resources at 'classpath:db/migration' (Prefix: '', Suffix: '.sql')
18:43:30,780 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Determining location urls for classpath:db/migration using ClassLoader ModuleClassLoader for Module "deployment.mobile.bank.services-1.0.5.ear.flyway-1.0-SNAPSHOT.jar:main" from Service Module Loader ...
18:43:30,780 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning URL: vfs:/E:/Soft/Server_10.1.0/bin/content/mobile.bank.services-1.0.5.ear/flyway-1.0-SNAPSHOT.jar/db/migration/
18:43:30,780 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG FeatureDetector:40 - JBoss VFS v2 available: false
18:43:30,781 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG FeatureDetector:40 - JBoss VFS v3 available: true
18:43:30,782 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG JBossVFSv3ClassPathLocationScanner:40 - Scanning starting at classpath root on JBoss VFS: E:\Soft\Server_10.1.0\bin\content\mobile.bank.services-1.0.5.ear\flyway-1.0-SNAPSHOT.jar\/
18:43:30,834 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG DbValidate:40 - Validating migrations ...
18:43:30,836 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning for classpath resources at 'classpath:db/migration' (Prefix: 'V', Suffix: '.sql')
18:43:30,836 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning URL: vfs:/E:/Soft/Server_10.1.0/bin/content/mobile.bank.services-1.0.5.ear/flyway-1.0-SNAPSHOT.jar/db/migration/
18:43:30,836 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG FeatureDetector:40 - JBoss VFS v2 available: false
18:43:30,836 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning for classpath resources at 'classpath:db/migration' (Prefix: 'R', Suffix: '.sql')
18:43:30,836 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning URL: vfs:/E:/Soft/Server_10.1.0/bin/content/mobile.bank.services-1.0.5.ear/flyway-1.0-SNAPSHOT.jar/db/migration/
18:43:30,837 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG FeatureDetector:40 - JBoss VFS v2 available: false
18:43:30,837 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning for classes at 'classpath:db/migration' (Implementing: 'org.flywaydb.core.api.migration.jdbc.JdbcMigration')
18:43:30,837 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG ClassPathScanner:40 - Scanning URL: vfs:/E:/Soft/Server_10.1.0/bin/content/mobile.bank.services-1.0.5.ear/flyway-1.0-SNAPSHOT.jar/db/migration/
18:43:30,838 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG FeatureDetector:40 - JBoss VFS v2 available: false
18:43:30,853 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 INFO  DbValidate:44 - Successfully validated 0 migrations (execution time 00:00.018s)
18:43:30,859 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG DbSchemas:40 - Schema "TEST_SERVER" already exists. Skipping schema creation.
18:43:30,935 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG Table:40 - Locking table "TEST_SERVER"."SERVER_VERSION_DB"...
18:43:30,936 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 DEBUG Table:40 - Lock acquired for table "TEST_SERVER"."SERVER_VERSION_DB"
18:43:30,943 INFO  [stdout] (ServerService Thread Pool -- 20) 2017-09-19 18:43:30 DEBUG Reflections:184 - going to scan these urls:
18:43:30,943 INFO  [stdout] (ServerService Thread Pool -- 20) vfs:/E:/Soft/Server_10.1.0/bin/content/mobile.bank.services-1.0.5.ear/service-web-1.0-SNAPSHOT.war/WEB-INF/classes/
18:43:30,943 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 INFO  DbMigrate:44 - Current version of schema "TEST_SERVER": << Empty Schema >>
18:43:30,945 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 INFO  DbMigrate:44 - Schema "TEST_SERVER" is up to date. No migration necessary.
18:43:30,974 INFO  [stdout] (ServerService Thread Pool -- 14) 2017-09-19 18:43:30 INFO  DEBUG_LOGGER:48 - FlyWayMigrator - flywayMigrateStop

我的源代码

public void flywayMigrateStart() {
    LoggerUtil.getDEBUG_LOGGER().info("FlyWayMigrator - flywayMigrateStart");
    String flywayMinVersion = FlyWayProperty.getInstance().getProperty(FlyWayProperty.FLYWAY_MIN_VERSION);

    if (flywayMinVersion != null) {
        Flyway flyway = new Flyway();
        try {
            flyway.setDataSource(createDataSource());
            flyway.setTable(FlyWayProperty.getInstance().getProperty(FlyWayProperty.FLYWAY_MIGRATION_TABLE_NAME));
            flyway.setBaselineVersionAsString(FlyWayProperty.getInstance().getProperty(FlyWayProperty.FLYWAY_BASELINE_VERSION));
            flyway.setSqlMigrationSeparator(FlyWayProperty.getInstance().getProperty(FlyWayProperty.FLYWAY_MIGRATION_SEPARATOR));
            flyway.setEncoding(FlyWayProperty.getInstance().getProperty(FlyWayProperty.FLYWAY_ENCODING));
            flyway.setSchemas(FlyWayProperty.getInstance().getProperty(FlyWayProperty.ORACLE_DB_USERNAME));
            flyway.setBaselineOnMigrate(true);
            flyway.migrate();
            flywayMigrateStop();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

我的属性文件

ORACLE_DB_DRIVER_CLASS=oracle.jdbc.driver.OracleDriver
ORACLE_DB_URL=jdbc:oracle:thin:@192.168.100.210:1521:DB
ORACLE_DB_USERNAME=TEST_SERVER
ORACLE_DB_PASSWORD=TEST_SERVER
FLYWAY_MIN_VERSION=V1
FLYWAY_MIGRATION_TABLE_NAME=SERVER_VERSION_DB
FLYWAY_BASELINE_VERSION=1.0.0
FLYWAY_MIGRATION_SEPARATOR=#
FLYWAY_ENCODING=UTF-8

2 个答案:

答案 0 :(得分:1)

Flyway无法找到您的迁移文件,因此它认为所有内容都是最新的:

INFO  DbValidate:44 - Successfully validated 0 migrations (execution time 00:00.018s)

您需要指定位置或将迁移移至已搜索的位置。使用setLocations()来执行此操作。

答案 1 :(得分:0)

如果你使用maven构建这个jar - flyway-1.0-SNAPSHOT.jar,那么确保src / main / resources有一个包含你的V1__20170918_Initial_structure.sql的db / migration文件夹

请告诉我是否能够解决您的问题。