Skip to content

Explicit migration-strategy manual or validate is silently ignored when the database is empty #51932

Description

@Alnyli07

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=manual initializes the schema in place and writes no export script, although the option exists precisely to avoid DDL from the server.
  • migration-strategy=validate creates 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?

  1. Point Keycloak at an empty database.
  2. kc.sh start-dev --spi-connections-jpa-quarkus-migration-strategy=manual
  3. The server starts and the schema is created; keycloak-database-update.sql is never written.

Anything else?

A PR implementing the expected behaviour above is linked.

Activity

  1. moved this from Backlog to In progress in Keycloak Roadmapon Sep 10, 2026
  2. added a commit that references this issue on Sep 23, 2026
    b238af2
  3. added
    kind/bug
    on Sep 23, 2026
  4. added theissue type on Sep 23, 2026
  5. added
    area/dist/quarkus
    on Sep 23, 2026
  6. added a commit that references this issue on Sep 25, 2026
    3ecb184
  7. added a commit that references this issue on Oct 6, 2026
    4089be9
  8. added a commit that references this issue on Oct 21, 2026
    4e463f9
  9. added a commit that references this issue on Nov 2, 2026
    87cd9ef
  10. added a commit that references this issue on Nov 10, 2026
    1cb6a7d
  11. added a commit that references this issue on Nov 20, 2026
    4e74ca3
  12. added a commit that references this issue on Nov 27, 2026
    b219406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/dist/quarkuskind/bugpriority/importantteam/cloud-native

    Type

    Fields

    No fields configured for bug.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions