Make cross-service Auth role/user creation idempotent in migrations - #1573
Open
3keyroman wants to merge 3 commits into
Open
Make cross-service Auth role/user creation idempotent in migrations#15733keyroman wants to merge 3 commits into
3keyroman wants to merge 3 commits into
Conversation
Migrations create roles and users in the Auth Service via a cross-service call.
If a migration was interrupted and then re-run, that call failed with
ENTITY_NOT_UNIQUE ("already exists") and wedged Core startup. Creation now returns
the existing entity instead, so migrations are safe to re-run.
Adds getOrCreateRole/getOrCreateUser in DatabaseAuthMigration and routes the
affected migrations through them; the three edited migrations are flagged
isAltered with their checksum constants left unchanged.
There was a problem hiding this comment.
Pull request overview
This PR makes cross-service Auth role/user creation during Flyway Java migrations idempotent, preventing Core startup from failing when a migration is interrupted and re-run after the Auth Service has already created the role/user.
Changes:
- Added
DatabaseAuthMigration.getOrCreateRole/getOrCreateUserhelpers and routed Auth creation through them. - Updated impacted migrations to use the new idempotent helpers for role/user creation.
- Marked the altered Java migrations as
isAltered=trueinDatabaseMigration.JavaMigrationChecksumswhile keeping existing checksum constants unchanged to preserve Flyway validation behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/com/czertainly/core/util/DatabaseAuthMigration.java |
Adds idempotent get-or-create helpers and uses them from existing helper methods. |
src/main/java/db/migration/V202209211100__Access_Control.java |
Routes user/role creation through idempotent helpers. |
src/main/java/db/migration/V202303211718__Scep_Roles.java |
Routes SCEP role/user creation through idempotent helpers. |
src/main/java/db/migration/V202404021100__CreateCmpUserAndPermissions.java |
Routes CMP role/user creation through idempotent helpers. |
src/main/java/com/czertainly/core/util/DatabaseMigration.java |
Flags the modified Java migrations as altered (without changing stored checksum constants). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+116
to
+123
| public static RoleDetailDto getOrCreateRole(RoleManagementApiClient roleClient, RoleRequestDto request) { | ||
| for (RoleDto existing : roleClient.getRoles().getData()) { | ||
| if (existing.getName().equals(request.getName())) { | ||
| return roleClient.getRoleDetail(existing.getUuid()); | ||
| } | ||
| } | ||
| return roleClient.createRole(request); | ||
| } |
Comment on lines
+129
to
+135
| public static UserDetailDto getOrCreateUser(UserManagementApiClient userClient, UserRequestDto request) { | ||
| for (UserDto existing : userClient.getUsers().getData()) { | ||
| if (existing.getUsername().equals(request.getUsername())) { | ||
| return userClient.getUserDetail(existing.getUuid()); | ||
| } | ||
| } | ||
| return userClient.createUser(request); |
|
lubomirw
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Migrations create roles and users in the Auth Service via a cross-service call. If a migration was interrupted and then re-run, that call failed with
ENTITY_NOT_UNIQUE("already exists") and wedged Core startup. Creation now returns the existing entity instead, so migrations are safe to re-run.Adds
getOrCreateRole/getOrCreateUserinDatabaseAuthMigrationand routes the affected migrations (V202209211100,V202303211718,V202404021100, plus the helper already used byV202411141900) through them. The three edited migrations are flaggedisAlteredwith their checksum constants left unchanged, so Flyway validation against existing databases is unaffected.