Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline only applied on complete empty schemas #3767

Closed
Auskennfuchs opened this issue Oct 23, 2023 · 4 comments · May be fixed by #3768
Closed

Baseline only applied on complete empty schemas #3767

Auskennfuchs opened this issue Oct 23, 2023 · 4 comments · May be fixed by #3768

Comments

@Auskennfuchs
Copy link

Auskennfuchs commented Oct 23, 2023

Which version and edition of Flyway are you using?

flyway-core 9.22.3 community edition

If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)

yes

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Java API

Which database are you using? (Type & version)

IBM DB2

Which operating system are you using?

Linux

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

I'm sharing one schema with multiple flyway migrations. Each migration maintains an independent set of tables. Everything is working and each flyway migration has it's own flyway history table. Now I'm trying to add baselining to the migrations to speed up the initialization of new databases.

I have this simple scenario:

V1.0__CreateTable.sql  <- initial table
V1.1__AddFirstName.sql <- add new column
B2.0__Baseline.sql <- cumulation of V1.0 and V1.1
V2.1__AddEmail.sql <- add another column

The schema, where the migration is running is not empty, so other tables are already existing because of previously running migrations.

My flyway is configured like this:

Flyway.configure()
				.dataSource(dataSource)
				.locations(scriptsLocation)
				.schemas(migration.getSchema())
				.baselineVersion("0")
				.baselineOnMigrate(true)
				.table(migration.getFlywayTable())
				.load();

The scripts are correctly parsed:

[de.afb.core.flyway.MigrationController] State: BELOW_BASELINE Version: 1.0 Description: CreateTable
[de.afb.core.flyway.MigrationController] State: BELOW_BASELINE Version: 1.1 Description: AddFirstName
[de.auskenfuchs.core.flyway.MigrationController] State: PENDING Version: 2.0 Description: Baseline2
[de.auskennfuchs.core.flyway.MigrationController] State: PENDING Version: 2.1 Description: AddEmail

So Flyway correctly identifies V1.0 and V1.1 as below the newest baseline. But still these scripts are executed and B2.0 is ignored completely.
When I'm running the same Migration on an empty schema everything works like expected, B2.0 and V2.1 are execucted and V1.x are ignored. In every case I'm providing the baselineVersion as 0.

What did you expect to see?

I would expect that also on not empty schemas the baseline is correctly used.

What did you see instead?

The baseline version is ignored on non empty schemas. Even when I'm setting the baselineVersion to 2 or 1.9 the baseline script is never executed.

I assume there were some decisions that only empty schemas can guarantee the proper baseline with flyway, but in some scenarios this may not apply. It would be good to have an option that the baseline is still applied, as long as the flyway history table doesn't exist.

@JasonLuo-Redgate
Copy link

Hi @Auskennfuchs , based on the info posted here https://documentation.red-gate.com/fd/baseline-migrations-184127465.html,
Baseline migrations are only used when deploying to new environments. If used in an environment where some Flyway migrations have already been applied, baseline migrations will be ignored.

@JasonLuo-Redgate
Copy link

Also, according to https://documentation.red-gate.com/fd/baseline-on-migrate-224919695.html, when baselineOnMigrate is set to true, Flyway will automatically call [baseline] when [migrate] is executed against a non-empty schema with no metadata table. This schema will then be baselined with the baselineVersion before executing the migrations.

@Auskennfuchs
Copy link
Author

Also, according to https://documentation.red-gate.com/fd/baseline-on-migrate-224919695.html, when baselineOnMigrate is set to true, Flyway will automatically call [baseline] when [migrate] is executed against a non-empty schema with no metadata table. This schema will then be baselined with the baselineVersion before executing the migrations.

Hello Jason,
thank you for your reply. Unfortunately the baselineOnMigrate is not affecting the usage of the baseline on a non empty schema. As you can see in my initial post I've already set the parameter to true, but it is ignored in this scenario.

@JasonLuo-Redgate
Copy link

JasonLuo-Redgate commented Nov 6, 2023

Hi @Auskennfuchs , let's walk through both your scenarios:

Running on an empty schema:

  1. baselineOnMigrate ignored. Because it only works for non-empty schema.
  2. Then as you configured Baseline script, Flyway takes 2.0 as baseline, and ignores scripts below it.

Running on an non-empty schema:

  1. baselineOnMigrate applied. Flyway took current schema as baseline.
  2. Then your configured Baseline script will be ignored by Flyway, because Baseline script only works for new environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants