8000 Honor an explicit migration strategy on an empty database by Alnyli07 · Pull Request #51933 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Honor an explicit migration strategy on an empty database - #51933

Open
Alnyli07 wants to merge 1 commit into
keycloak:mainfrom
Alnyli07:fix/empty-database-explicit-migration-strategy
Open

Alnyli07 wants to merge 1 commit into
keycloak:mainfrom
Alnyli07:fix/empty-database-explicit-migration-strategy

Conversation

@Alnyli07
Copy link
Copy Markdown
Contributor

Closes #51932

What

An explicitly configured migration-strategy is silently ignored when the database is empty:
initializeEmpty defaults to true and is checked before the strategy, so manual initializes the schema
in place without writing the export script, and validate creates the whole schema on a database it was told
to only validate. Follow-up requested in
#51730 (comment).

How

The default of initialize-empty now depends on the strategy: true for update (unchanged), false for
manual and validate. An explicitly configured value wins in all cases:

empty database + before after
update (no flag) initialize initialize
manual (no flag) silent initialize export + startup error
validate (no flag) silent initialize startup error
manual/validate + explicit initialize-empty=true initialize initialize
manual + explicit initialize-empty=false export + startup error export + startup error

One line of logic in QuarkusJpaConnectionProviderFactory and the same in the legacy
DefaultJpaConnectionProviderFactory, plus the initialize-empty help text and an entry in the upgrading
guide, since the two fixed rows are a behavior change.

Note that initialize-empty=false combined with update already updates today, so the option only ever had
an effect on manual and validate; this change gives it a consistent meaning instead of a contradicting one.

Testing

New EmptyDatabaseMigrationStrategyDistTest (H2, raw dist, empty database):

  • manual alone produces the export script and the "Database not initialized" startup error (red without the fix);
  • validate alone fails startup with "please enable database initialization" (red without the fix);
  • manual with an explicit initialize-empty=true still initializes and starts (green before and after, pins the opt-in).

Existing manual-strategy tests (ManualMigrationCustomProviderDistTest, LiquibaseDistTest,
PostgreSQLDistTest/MySQLDistTest/MariaDBDistTest) all pass initialize-empty explicitly, so their
behavior is unchanged; the first two were re-run locally and are green.

Note on AI assistance

AI agents were used while investigating this and while drafting the change, tests and documentation. I have
reviewed and understand every line, ran the verification described above myself, and will handle review
feedback directly.

Copilot AI balanced review requested due to automatic review settings August 21, 2026 11:04
@Alnyli07
Alnyli07 requested review from a team as code owners August 21, 2026 11:04
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates empty-database initialization defaults to respect manual and validation migration strategies.

Changes:

  • Makes initialize-empty strategy-dependent while preserving explicit overrides.
  • Adds distribution tests for manual and validation behavior.
  • Documents the behavioral change.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
QuarkusJpaConnectionProviderFactory.java Applies strategy-dependent initialization defaults.
DefaultJpaConnectionProviderFactory.java Mirrors behavior in the legacy provider.
EmptyDatabaseMigrationStrategyDistTest.java Tests empty-database migration scenarios.
changes-26_8_0.adoc Adds the upgrade notice.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 21, 2026 11:30
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from aafcf42 to 7747c79 Compare August 21, 2026 11:30
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 26, 2026 13:13
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from 7747c79 to c015df1 Compare August 26, 2026 13:13
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

shawkins
shawkins previously approved these changes Sep 8, 2026
@shawkins shawkins left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Alnyli07

Let's get another review from @keycloak/cloud-native or @keycloak/sre and get this merged.

@shawkins
shawkins requested review from a team September 8, 2026 21:46
@michalvavrik
Copy link
Copy Markdown
Member

LGTM, thanks @Alnyli07

Let's get another review from @keycloak/cloud-native or @keycloak/sre and get this merged.

I am waiting with the review until #51730 is merged.

Breaking changes are identified as those that might require changes for existing users to their configurations or applications.
In minor or patch releases, {project_name} will only introduce breaking changes to fix bugs.

=== Empty database and an explicit migration strategy
@michalvavrik michalvavrik Sep 11, 2026 •
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT when user configures update migration strategy, this initialize-empty has no effect. Regardless of true or false or unset. Should documentation mention it or it is already doc-ed or implied somehow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @michalvavrik , with update an empty database is always initialized, regardless of initialize-empty. That was already the case before this change; both the initializeEmpty branch and the UPDATE case of the switch end up in update().

It isn't documented anywhere though, and the help text of initializeEmpty ("If set to false the database has to be manually initialized") is actually misleading for update. I'd add one sentence to this upgrade note and fix the help text:

initialize-empty only affects the manual and validate strategies. With update, an empty database is always initialized regardless of this setting.

Want me to push that here, or would you rather keep it out of this PR?

@michalvavrik michalvavrik Sep 16, 2026 •
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought we should document it somehow, I understand it is preexisting "fact". But since you are fixing the initialize-empty, doc-ing this would be good. If you don't mind, do it. As I say these days "short concise note will do" 😁 Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, short and concise as requested :) One sentence in the upgrade note plus the help text, and rebased onto main. Thanks!

Copilot AI review requested due to automatic review settings September 23, 2026 06:26
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from c015df1 to b238af2 Compare September 23, 2026 06:26
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation consistently addresses the reported behavior and includes focused regression coverage and documentation.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@@ -0,0 +1,85 @@
/*
* Copyright 2026 Red Hat, Inc. and/or its affiliates
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep it, just fyi: it is not necessary anymore to add this

@michalvavrik michalvavrik left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copilot AI review requested due to automatic review settings September 25, 2026 11:04
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from b238af2 to 3ecb184 Compare September 25, 2026 11:04
@Alnyli07
Alnyli07 requested a review from a team as a code owner September 25, 2026 11:04
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation, tests, and documentation consistently address the reported behavior.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings October 6, 2026 08:21
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from 3ecb184 to 4089be9 Compare October 6, 2026 08:21
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The export test can pass using a stale SQL file preserved in the distribution’s bin directory.

Review effort: Balanced
Findings: None

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.broker.KcSamlBrokerTest#loginInResponseToEmpty

Keycloak CI - FIPS IT (strict)

java.lang.AssertionError: 

Expected: response status code matches is <200>
     but: was <HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Set-Cookie: AUTH_SESSION_ID=UmZEVVdEbGptNWJiUDQwanNYZFNOUnlfLmg2ZGJhaVprcDBpZXQ0X2w0LV9iTmtIR0hMLVFsdXl2blVSaHhDdmJqdUk3QmtOWTZGcjQwbTdXbEZvczh2MUgzMkN3TkV4V1NsZ00wUEk4WGphZlpn;Versi
10BC8
on=1;Path=/auth/realms/consumer/;Secure;HttpOnly;SameSite=None, Set-Cookie: KC_AUTH_SESSION_HASH="FHh4IUWzHxSF4zHvmovrc9I44taVUuosAkuandpG0GdsKSeTF/U64ZP5eV/AuKR9";Version=1;Path=/auth/realms/consumer/;Max-Age=60;Secure;SameSite=None, content-length: 94, Content-Type: application/json] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 94,Chunked: false]}}> with entity {"error":"unknown_error","error_description":"For more on this error consult the server log."}
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...

Report flaky test

org.keycloak.testsuite.broker.KcSamlSignedBrokerTest#loginUserAllNamespacesInTopElement

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

org.keycloak.testsuite.broker.KcSamlSignedBrokerTest#testSignatureDataWhenWantsRequestsSigned

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

@Alnyli07
Alnyli07 requested a review from shawkins October 13, 2026 14:11
Copilot AI balanced review requested due to automatic review settings October 21, 2026 06:28
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from 4089be9 to 4e463f9 Compare October 21, 2026 06:28
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The explicit-override regression test needs to verify successful startup rather than only the development-mode banner.

No open issues 🎉

Review effort: Balanced

On an empty database initializeEmpty defaults to true and is checked
before the migration strategy, so an explicitly configured manual or
validate strategy was silently ignored: manual initialized the schema in
place without writing the export script, and validate created the whole
schema on a database it was told to only validate.

Make the default of initialize-empty depend on the strategy instead:
true for update, false for manual and validate. An explicitly configured
value still wins in all cases, so existing setups keep their behavior
and manual plus an explicit initialize-empty=true remains available as
an opt-in.

Closes keycloak#51932

Signed-off-by: Ali Tugrul Pinar <ali@keymate.io>
@Alnyli07
Alnyli07 force-pushed the fix/empty-database-explicit-migration-strategy branch from 4e463f9 to 87cd9ef Compare November 2, 2026 11:04
Copilot AI balanced review requested due to automatic review settings November 2, 2026 11:04
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the changes to empty-database migration strategy behavior.

No open issues 🎉

Review effort: Balanced

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants

0