Antonio Dragos
Antonio Dragos

Reputation: 2873

Automatically baselining a database with Flyway in a Spring Boot project

I'm trying to add Flyway to a Spring Boot project. In accordance with the instructions, I've created my initial DDL script and committed it to src/main/resources/db/migration/V1__base_version.sql.

If I run the baseline command, this will create the flyway_schema_history table and set the baseline version therein to 1.

While this works fine for my local database, I would like this to happen automatically on the other developers' local environments, UAT environment, etc.

I tried adding the following property to the Spring Boot config

spring:
  flyway:
    baseline-on-migrate: true

I expected this to do the same thing as the baseline command when the Spring Boot app starts up if the flyway_schema_history table does not exist, i.e. create this table and insert a row specifying the current schema version, but it didn't.

Is there a way to automatically baseline the database when the app starts up?

Upvotes: 7

Views: 1432

Answers (1)

JasonL
JasonL

Reputation: 11

You need to run a migrate command to actually trigger that. More info can be referred here: https://documentation.red-gate.com/flyway/flyway-cli-and-api/configuration/parameters/flyway/baseline-on-migrate.

Upvotes: 0

Related Questions