英文:
Flyway runs V0 migration scripts on initial migration
问题
I am working on a Spring Boot 2.7 application with an existing Oracle 19c database and is trying to integrate Flyway(v8.5). I have created a migration script named V0__create_tables.sql
, which is intended to be used for setting up tests in H2 at a later stage, and an empty file V1__baseline.sql
.
我正在开发一个Spring Boot 2.7应用程序,使用现有的Oracle 19c数据库,并尝试集成Flyway(v8.5)。我已经创建了一个名为V0__create_tables.sql
的迁移脚本,用于在以后的阶段在H2中设置测试,并创建了一个空文件V1__baseline.sql
。
I have configured the following properties in my application.properties
file:
我已在我的application.properties
文件中配置了以下属性:
spring.flyway.baselineVersion=1
spring.flyway.baselineOnMigrate=true
Despite these settings, when I execute flyway migrate
, the V0__create_tables.sql
script is executed instead of recognizing it as the baseline and skipping it. In the console I get origin=org.flywaydb.core.internal.command.DbMigrate message="Current version of schema "STER": << Empty Schema >>"
and no signs of the baseline version being configured as 1.
尽管这些设置,但当我执行flyway migrate
时,会执行V0__create_tables.sql
脚本,而不是将其识别为基线并跳过它。在控制台中,我得到了origin=org.flywaydb.core.internal.command.DbMigrate message="Current version of schema "STER": << Empty Schema >>"
的消息,没有迹象表明基线版本已配置为1。
I have verified that flyway is responding to changes in the application.properties
file by toggling flyway on and off with spring.flyway.enable
我已经通过使用spring.flyway.enable
来切换flyway的启用状态来验证flyway是否响应application.properties
文件中的更改。
Can anyone please help me understand why Flyway is executing the V0__create_tables.sql
script instead of treating it as the baseline version and skipping it?
有人可以帮助我理解为什么Flyway执行V0__create_tables.sql
脚本,而不是将其视为基线版本并跳过吗?
Any assistance or insights would be greatly appreciated. Thank you!
任何帮助或见解将不胜感激。谢谢!
英文:
I am working on a Spring Boot 2.7 application with an existing Oracle 19c database and is trying to integrate Flyway(v8.5). I have created a migration script named V0__create_tables.sql
, which is intended to be used for setting up tests in H2 at a later stage, and an empty file V1__baseline.sql
.
I have configured the following properties in my application.properties
file:
spring.flyway.baselineVersion=1
spring.flyway.baselineOnMigrate=true
Despite these settings, when I execute flyway migrate
, the V0__create_tables.sql
script is executed instead of recognizing it as the baseline and skipping it. In the console I get origin=org.flywaydb.core.internal.command.DbMigrate message="Current version of schema "STER": << Empty Schema >>"
and no signs of the baseline version being configured as 1.
I have verified that flyway is responding to changes in the application.properties
file by toggling flyway on and off with spring.flyway.enable
Can anyone please help me understand why Flyway is executing the V0__create_tables.sql
script instead of treating it as the baseline version and skipping it?
Any assistance or insights would be greatly appreciated. Thank you!
答案1
得分: 1
如果在运行这些代码时,你的数据库中已经有数据了吗?
如果没有,对于默认设置的Spring Boot和Flyway,这两者都不会执行任何操作。
baselineOnMigrate
只会在你的模式中已经有(且仅有)非Flyway数据时才运行 baseline
命令。如果你的数据库模式是空的或不存在,那么Flyway将没有需要基线化的内容,不会运行该命令。
因此,如果没有调用 baseline
,那么 baselineVersion
将不会被使用。
默认情况下,Spring Boot 只运行 Flyway 的 migrate
命令。如果你需要在空模式上运行 Flyway 的 baseline
,那么你需要通过创建一个 FlywayMigrationStrategy
bean 来改变Spring的行为,该bean会依次运行 baseline
和 migrate
。
类似这样:
@Configuration
public class BaselineMigrationStrategyConfig {
@Bean
public FlywayMigrationStrategy flywayMigrationStrategy() {
return flyway -> {
flyway.baseline();
flyway.migrate();
};
}
}
希望这对你有帮助。
英文:
Do you already have anything in your database when you run these?
If you do not, neither of these will do anything with a default set up of Spring Boot with Flyway.
baselineOnMigrate
will only run the baseline
command if there is already (and only) non-Flyway data in your schema. If your database schema is empty, or non-existent, then Flyway will have nothing to baseline and not run the command.
As a result, if baseline
is not called then baselineVersion
is not used.
By default, Spring Boot is only running Flyway's migrate
command. If you need Flyway to run baseline
on an empty setup then you will need to change the Spring behavior by creating a FlywayMigrationStrategy
bean which runs baseline
then migrate
.
Something like:
@Configuration
public class BaselineMigrationStrategyConfig {
@Bean
public FlywayMigrationStrategy flywayMigrationStrategy() {
return flyway -> {
flyway.baseline();
flyway.migrate();
};
}
}
I hope this helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论