【问题标题】:Flyway not picking up my sql file for migrationFlyway 没有拿起我的 sql 文件进行迁移
【发布时间】:2017-09-15 23:56:44
【问题描述】:

我使用的是flyway 4.1.2版

我有一个名为 SAPDATA 的架构。我正在寻找执行以下脚本 V0.0.1_1__baseline.sql 。我看到我的sql文件被flyway忽略了,它已经过滤掉了我的资源。

我已经在架构中有表,因此我将baselineOnMigrate 设置为true 以便迁移我的脚本。

请告诉我是否应该明确设置架构名称? 我不确定为什么我的 sql 文件被过滤掉了?

如果我在飞行途中遗漏任何特定设置以便执行我的 sql,请您告知?

执行代码

      @Override
        protected void doOperation(DatabaseConfig.DataSourceConfig databaseConfig, String location) {
            final Flyway flyway = new Flyway();
            flyway.setLocations(location);
            flyway.setDataSource(databaseConfig.getUrl(), databaseConfig.getUsername(), databaseConfig.getPassword());
           flyway.setBaselineOnMigrate(true);
           flyway.migrate();
        }

**Execution logs**
 17:51:46.073 [main] DEBUG org.flywaydb.core.internal.util.FeatureDetector - Spring Jdbc available: false
17:51:46.074 [main] DEBUG org.flywaydb.core.internal.callback.SqlScriptFlywayCallback - Scanning for SQL callbacks ...
17:51:46.074 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning for classpath resources at 'classpath:db/migration/sap' (Prefix: '', Suffix: '.sql')
17:51:46.074 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Determining location urls for classpath:db/migration/sap using ClassLoader sun.misc.Launcher$AppClassLoader@446cdf90 ...
17:51:46.074 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning URL: file:/C:/dev/workspaces/intellij-workspaces/reference-data-system/database/target/classes/db/migration/sap
17:51:46.075 [main] DEBUG org.flywaydb.core.internal.util.FeatureDetector - JBoss VFS v2 available: false
17:51:46.077 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner - Scanning starting at classpath root in filesystem: C:\dev\workspaces\intellij-workspaces\reference-data-system\database\target\classes\
17:51:46.077 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner - Scanning for resources in path: C:\dev\workspaces\intellij-workspaces\reference-data-system\database\target\classes\db\migration\sap (db/migration/sap)
17:51:46.098 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Found resource: db/migration/sap/V0.0.1_1__baseline.sql
17:51:46.706 [main] DEBUG org.flywaydb.core.internal.command.DbValidate - Validating migrations ...
17:51:46.757 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning for classpath resources at 'classpath:db/migration/sap' (Prefix: 'V', Suffix: '.sql')
17:51:46.757 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning URL: file:/C:/dev/workspaces/intellij-workspaces/reference-data-system/database/target/classes/db/migration/sap
17:51:46.757 [main] DEBUG org.flywaydb.core.internal.util.FeatureDetector - JBoss VFS v2 available: false
17:51:46.774 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Found resource: db/migration/sap/V0.0.1_1__baseline.sql
17:51:46.777 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning for classpath resources at 'classpath:db/migration/sap' (Prefix: 'R', Suffix: '.sql')
17:51:46.777 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning URL: file:/C:/dev/workspaces/intellij-workspaces/reference-data-system/database/target/classes/db/migration/sap
17:51:46.778 [main] DEBUG org.flywaydb.core.internal.util.FeatureDetector - JBoss VFS v2 available: false
17:51:46.789 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Filtering out resource: db/migration/sap/V0.0.1_1__baseline.sql (filename: V0.0.1_1__baseline.sql)
17:51:46.791 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning for classes at 'classpath:db/migration/sap' (Implementing: 'org.flywaydb.core.api.migration.jdbc.JdbcMigration')
17:51:46.791 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Scanning URL: file:/C:/dev/workspaces/intellij-workspaces/reference-data-system/database/target/classes/db/migration/sap
17:51:46.791 [main] DEBUG org.flywaydb.core.internal.util.FeatureDetector - JBoss VFS v2 available: false
17:51:46.803 [main] DEBUG org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner - Filtering out resource: db/migration/sap/V0.0.1_1__baseline.sql (filename: V0.0.1_1__baseline.sql)
17:51:47.107 [main] INFO org.flywaydb.core.internal.command.DbValidate - Successfully validated 2 migrations (execution time 00:00.398s)
17:51:47.240 [main] INFO org.flywaydb.core.internal.dbsupport.sqlserver.SQLServerDbSupport - SQLServer does not support setting the schema for the current session. Default schema NOT changed to SAPDATA
17:51:47.330 [main] DEBUG org.flywaydb.core.internal.command.DbSchemas - Schema [SAPDATA] already exists. Skipping schema creation.
17:51:48.343 [main] DEBUG org.flywaydb.core.internal.dbsupport.Table - Locking table [SAPDATA].[schema_version]...
17:51:48.394 [main] DEBUG org.flywaydb.core.internal.dbsupport.Table - Lock acquired for table [SAPDATA].[schema_version]
17:51:48.793 [main] INFO org.flywaydb.core.internal.command.DbMigrate - Current version of schema [SAPDATA]: 1
17:51:48.877 [main] INFO org.flywaydb.core.internal.command.DbMigrate - Schema [SAPDATA] is up to date. No migration necessary.

【问题讨论】:

  • 我不明白。您是否已经尝试使用 Flyway#setSchemas(String... schemas) 设置架构?
  • 是的,我也试过这个选项。出于某种原因,它过滤掉了我的 sql 文件。
  • 那么你发布的日志是用#setSchema(..)生成的吗?因为在代码中你没有。
  • 我已经用我为上面运行的代码获得的最新日志更新了上面的内容。这没有设置架构名称。请你能告诉我我可能会错过什么吗?
  • 基线设置为 1,但脚本的版本为 0。我认为这是未应用脚本的原因。

标签: java flyway


【解决方案1】:

根据您的日志,您已经拥有版本 1 的架构,尽管您的脚本是版本 0。

如果你想应用你的脚本,你必须增加它的版本,因为所有版本低于当前版本的脚本都会被跳过。

【讨论】:

    猜你喜欢
    • 2016-04-28
    • 2020-01-02
    • 2016-10-24
    • 2023-03-13
    • 2018-12-19
    • 2017-02-07
    • 2014-05-14
    • 2019-03-05
    • 2015-07-10
    相关资源
    最近更新 更多