Repository navigation
Conversation
…type ChangePrimaryKeyColumnsType dropped the primary key before copying data into the new column. MySQL Group Replication rejects DML on tables without a primary key, so the copy failed with error 3098 and left the table without one. Keep the key on the renamed column during the copy and move it to the new column with a single ALTER TABLE. Restore a missing key before copying data. Closes apache#9194
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.
Summary
ChangePrimaryKeyColumnsTypedropped the primary key, copied data into the new column, and added the key back. MySQL Group Replication rejects DML on tables without a primary key, so the copy failed with error 3098. The table stayed without a primary key, and the next start failed with error 1091.Now the helper keeps the primary key the whole time:
ALTER TABLE ... DROP PRIMARY KEY, ADD PRIMARY KEY (...)moves the key to the new column.ChangeColumnsTypekeeps its behavior. Its body moved to a privatechangeColumnsTypeWithHookthat runs a hook between the copy and the drop of the temp columns.The only caller is core migration
20240124155129(refs.idfrom varchar(255) to varchar(500)).Does this close any open issues?
Closes #9194
Other Information
Sonarqube migration
20230927145127drops the primary key of_tool_sonarqube_file_metricsitself, outside this helper, so it still fails on Group Replication. This PR doesn't change it.Tests
New e2e test
test/e2e/migrationhelper/change_primary_key_test.goruns againstE2E_DB_URL. It covers a table with a primary key and a table without one. On MySQL it setssql_require_primary_key = ONfor the session, so MySQL rejects any statement that leaves the table without a primary key. This catches the bug without Group Replication in CI.Results:
I also started DevLake from this branch with all Go plugins on a fresh MySQL 8.0 with Group Replication. The
refsmigration now passes. Without the sonarqube plugin all migrations pass and the server starts. On PostgreSQL 14 the core migrations pass.