Skip to content

fix(mysql): foreign key violation on mysql cluster - #201

Open
wimueller wants to merge 2 commits into
Innovar-Healthcare:bridgelink_developmentfrom
wimueller:bridgelink_development
Open

wimueller wants to merge 2 commits into
Innovar-Healthcare:bridgelink_developmentfrom
wimueller:bridgelink_development

Conversation

@wimueller

Copy link
Copy Markdown

Description

This PR fixes a foreign key constraint violation when creating the default admin user on MySQL Cluster installations.

Problem

The PERSON table uses an auto-incrementing ID. The initialization script inserted the admin user's password using a hardcoded PERSON_ID of 1:

INSERT INTO PERSON_PASSWORD (PERSON_ID, PASSWORD) VALUES(1, ...);

On a MySQL Cluster, the newly created admin user is not guaranteed to receive ID 1. As a result, the subsequent insert into PERSON_PASSWORD can reference a non-existent PERSON record and fail with a foreign key constraint violation.

Fix

The password is now associated with the actual ID of the newly created admin user by looking up the generated PERSON.ID using the username:

INSERT INTO PERSON_PASSWORD (PERSON_ID, PASSWORD)
SELECT ID, '...'
FROM PERSON
WHERE USERNAME = 'admin';

This removes the dependency on a specific auto-increment value and makes the initialization script compatible with MySQL Cluster environments.

Impact

  • Fixes the foreign key constraint violation during database initialization.
  • Removes the assumption that the admin user receives ID = 1.
  • No changes to the database schema are required.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant