0

I am using flyway for migrations in my Spring boot application. I have around 5 migration scripts with names in the below fashion:

V1__initialmigrations.sql
V2__alter_message_table.sql

When the migrations run and I see the data in 'flyway_schema_history' table, the data looks good for all migration scripts except the very first one for which under the 'script' column, the value is '<< Flyway Baseline >>' rather than the name of the script unlike other rows. Also, the 'installed_by' column has the value 'null' for this very row while other have the user name that I have in my Spring boot yml file. Also, the 'checksum' is null as well. The only flyway related properties in the spring env yml file are :

spring:
  flyway:
    baseline-on-migrate: true
    enabled: true

I am not sure if this is the right behavior. Any inputs would be appreciated.

T Anna
  • 874
  • 5
  • 21
  • 52

1 Answers1

0

You only use the baseline-on-migrate property if you've created a new baseline after the initial application. Flyway ignores all script with a version below what is set in baseline-version (default 1).

For example in applications i've worked on we had years of migration script backlog. we replaced all of them with a single file with current db structure and enabled baseline-on-migrate with baseline-version: X.1 where our new baseline script was VX_0_0.

See also official documentation on baseline: https://flywaydb.org/documentation/concepts/baselinemigrations

Ralan
  • 651
  • 6
  • 17
  • But that doesn't explain having a nul checksum and installed_by for the baseline. – T Anna Jul 12 '22 at 13:10
  • The checksum is null as the migration line for BASELINE is not much more than a placeholder. there is no actual SQL that is run to make a checksum for. the baseline row in migration script is only there to tell flyway not to look at migration scripts with a lower number. otherwise it would throw exceptions that your current migration is at version 5 while it found a unexecuted migration with version 1 – Ralan Jul 12 '22 at 13:15
  • But the create table script in 'V1__initialmigration.sql' does run. I do see the table being created. So, there is a valid script in there. Its more than a placeholder. As I said, its the only script which i dont see in any of the rows, but I can see all other script names mentioned in the subsequent rows under the 'script' column 'flyway_schema_history. – T Anna Jul 12 '22 at 13:23
  • Also, I went through the link you mentioned. It says all baseline migrations need to start with 'B' and 'baseline migrations do not replace versioned migrations'. I do not have any script that starts with a 'B'. All start with 'V'. – T Anna Jul 12 '22 at 13:29