I have a spring-boot JPA app that I am trying to integrate flyway with. My app starts fine and it runs the create schema(V1_somescript.sql) in my local DB, but it doesn't run or apply the insert(V2_insert_script.sql) script. Here is what my configuration looks like:
pom.xml for flyway:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.1.4</version>
</dependency>
application.properties file:
# ===============================
# 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
Here is the V1_create_schema.sql script:
CREATE TABLE `lang` (
`lang` varchar(6) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Here is the V2_insert_schema.sql script:
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)');
Also, here is the bean definition in my AppConfig.java:
@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;
}
I don't get any error on starting the app on my IDE. I dropped the schema and created the schema before starting the app, and saw that app started fine and applied the create schema, but the lang table did not have any records in it.
Also, the application logs seem to suggest that it may not have applied the V1_create_schema.sql migrations via flyway and instead, it must be done by hibernate. Anyone know what could I be missing here ?
it looks like Hibernate creates the data model for you (spring.jpa.hibernate.ddl-auto=update), which you can disable since you are using Flyway.
Anyway when using Flyway on an existing non-empty schema you want to
spring.flyway.baseline-on-migrate = true
to ensure the Flyway History table is created when it first runs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With