【发布时间】:2020-05-16 07:32:21
【问题描述】:
我有一个 spring-boot JPA 应用程序,我正在尝试与 flyway 集成。我的应用程序启动良好,它在我的本地数据库中运行创建模式(V1_somescript.sql),但它不运行或应用插入(V2_insert_script.sql)脚本。这是我的配置:
飞路的 pom.xml:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.1.4</version>
</dependency>
application.properties 文件:
# ===============================
# JPA / HIBERNATE / FLYWAY
# ===============================
spring.jpa.hibernate.ddl-auto=update
spring.flyway.check-location=false
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
spring.jpa.properties.hibernate.generate_statistics=true
# ===============================
# DataSource
# ===============================
spring.flyway.locations=classpath*:resources/db/migrations
spring.datasource.url=jdbc:mysql://localhost:3306:3306/my_schema?useTimezone=true&serverTimezone=UTC
spring.datasource.username=my_username
spring.datasource.password=my_password
这里是 V1_create_schema.sql 脚本:
CREATE TABLE `lang` (
`lang` varchar(6) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
这里是 V2_insert_schema.sql 脚本:
INSERT IGNORE INTO `lang`(`lang`, `name`)
VALUES ('ar-AE', 'Arabic'),
('cs-CZ', 'Czech'),
('da-DK', 'Danish'),
('de-DE', 'German'),
('el-GR', 'Greek'),
('en-GB', 'English (UK)'),
('en-US', 'English (US)');
另外,这是我的 AppConfig.java 中的 bean 定义:
@Bean
@Profile(value = {"default", "memory"})
public Flyway flyway(DataSourceProperties dataSourceProperties) {
Flyway flyway =
Flyway.configure()
.dataSource(
dataSourceProperties.getUrl(),
dataSourceProperties.getUsername(),
dataSourceProperties.getPassword())
.baselineOnMigrate(true)
.locations("classpath:db/migration")
.load();
return flyway;
}
在我的 IDE 上启动应用程序时没有收到任何错误。我在启动应用程序之前删除了架构并创建了架构,并且看到该应用程序启动正常并应用了创建架构,但是 lang 表中没有任何记录。
此外,应用程序日志似乎表明它可能没有通过 flyway 应用 V1_create_schema.sql 迁移,而是必须由休眠完成。任何人都知道我在这里会错过什么吗?
【问题讨论】:
标签: java hibernate spring-boot jpa flyway