Repository navigation
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
storage
Describe the bug
An explicitly configured migration-strategy is silently ignored when the database is empty.
QuarkusJpaConnectionProviderFactory#createOrUpdateSchema (and the same branch in DefaultJpaConnectionProviderFactory#migration) handles an empty database like this:
} else if (status == JpaUpdaterProvider.Status.EMPTY) {
if (initializeEmpty) {
update(connection, schema, session, updater);
} else {
switch (strategy) { ... }
}
}initializeEmpty defaults to true, so unless the user also sets initialize-empty=false, the strategy switch is never reached:
migration-strategy=manualinitializes the schema in place and writes no export script, although the option exists precisely to avoid DDL from the server.migration-strategy=validatecreates the whole schema on a database it was told to only validate.
The two settings contradict each other and the explicit one loses. Even the help text of initialize-empty says "If you want to manually initialize the database set migrationStrategy to manual which will create a file with SQL commands to initialize the database", which is not what happens.
Noticed while working on #51730, where documenting the current behaviour was rightly rejected as documenting a bug (#51730 (comment)). This issue is the follow-up requested there.
Note that initialize-empty=false combined with the default update strategy still updates, so today the option only has an effect on manual and validate.
Version
main (999.0.0-SNAPSHOT)
Expected behavior
An explicit migration strategy wins on an empty database: manual writes the export script and exits, validate fails startup with a clear message.
A backward compatible way to get there: make the default of initialize-empty depend on the strategy (true for update, false for manual and validate) and let an explicitly configured value win in all cases. Existing setups that set the option explicitly keep their behaviour, and manual plus an explicit initialize-empty=true remains available as an opt-in for auto-initializing an empty database while keeping manual migrations for upgrades.
Actual behavior
On an empty database with --spi-connections-jpa--quarkus--migration-strategy=manual and no other flags, the server creates the full schema and starts. No SQL file is written and nothing hints that the strategy was ignored. The same happens with validate.
How to Reproduce?
- Point Keycloak at an empty database.
kc.sh start-dev --spi-connections-jpa-quarkus-migration-strategy=manual- The server starts and the schema is created;
keycloak-database-update.sqlis never written.
Anything else?
A PR implementing the expected behaviour above is linked.
Metadata
Metadata
Assignees
Labels
Type
Fields
Projects
- StatusShow more project fieldsNo status
Activity
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database
Honor an explicit migration strategy on an empty database