Skip to content

fix(migrations): stop a MySQL migration on an unsupported database collation before it changes anything - #37150

Closed
manerow wants to merge 2 commits into
mainfrom
fix/mysql-collation-preflight
Closed

manerow wants to merge 2 commits into
mainfrom
fix/mysql-collation-preflight

Conversation

@manerow

@manerow manerow commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Issue

No issue. Follow-up to PR #37142, which found MySQL collations that cannot finish the 2.1.0 migration.

Problem

OpenMetadata's MySQL tables use two collations:

  • newer tables pin utf8mb4_0900_ai_ci in their definition
  • older core tables, such as entity_relationship and entity_extension, take the database default

MySQL refuses to compare two different non-binary collations of the same character set. So on a default such as utf8mb4_unicode_ci or utf8mb4_general_ci, migrations and queries that compare ids across the two groups fail with Illegal mix of collations. Today such a database fails halfway through an upgrade, with a raw SQL error.

What this PR changes

migrate and drop-create now check the MySQL database before changing anything:

  • migrate checks the database default and the id columns that migrations compare: entity_relationship.fromId, entity_relationship.toId and entity_extension.id. It reads the columns, because ALTER TABLE ... COLLATE without CONVERT TO changes only the table default.
  • drop-create checks only the database default, before it drops anything. It rebuilds the tables from that default, so drifted tables get repaired.

Only a utf8mb4 collation other than utf8mb4_0900_ai_ci or a _bin one is reported. The command then exits 1 and lists each clashing item with how to fix it.

Other columns, such as entity_extension.extension (ASCII on some databases), are not checked. PostgreSQL is not affected.

Who this can stop

  • New installs from what we ship: not stopped. The Docker setup and the Helm chart create openmetadata_db without a collation, so it gets MySQL 8's default.
  • utf8mb3, latin1 and _bin databases: not stopped. MySQL converts the other character set to utf8mb4, and a _bin collation wins the comparison. To finish 2.1.0, utf8mb3 and latin1 also need PR fix(migrations): let the 2.1.0 relationship type backfill run on utf8mb3 and latin1 MySQL databases #37189.
  • utf8mb4_general_ci and utf8mb4_unicode_ci databases: stopped. They fail the 2.1.0 upgrade anyway; the check makes them fail first, with a fix. We don't yet know if any exist: a database keeps the collations it was created with.
  • Before merging: we are confirming the real collations on the SaaS MySQL clusters with this query, which reads the same columns as the check:
SELECT c.TABLE_SCHEMA, s.DEFAULT_COLLATION_NAME AS db_default,
       c.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME AS column_collation
FROM information_schema.COLUMNS c
JOIN information_schema.SCHEMATA s ON s.SCHEMA_NAME = c.TABLE_SCHEMA
WHERE (c.TABLE_NAME = 'entity_relationship' AND c.COLUMN_NAME IN ('fromId', 'toId'))
   OR (c.TABLE_NAME = 'entity_extension' AND c.COLUMN_NAME = 'id');

A row needs fixing only if db_default or column_collation is a utf8mb4 collation other than utf8mb4_0900_ai_ci or a _bin one.

How it was tested

  • The 2.1.0 ontology cleanup DELETE on MySQL 8.0 fails with ERROR 1267 on five non-binary utf8mb4 collations, including unicode_ci and general_ci, and works on utf8mb3, latin1, ascii and _bin collations.
  • MySqlCollationCheckTest (Testcontainers, 14 tests) covers each case above, drifted columns, ALTER TABLE ... COLLATE, an ASCII extension column, and drop-create ignoring drifted tables.
  • The real openmetadata-ops.sh: on a utf8mb4_unicode_ci default, migrate creates no tables and drop-create drops nothing; on a correct default with drifted columns, migrate stops and drop-create rebuilds and finishes 2.1.0; on utf8mb3, the check passes.
  • GuardedBlockMySqlExecutionTest still passes.

@manerow
manerow requested a review from a team as a code owner November 5, 2026 10:56
@manerow
manerow requested a review from sonika-shah November 5, 2026 10:56
@manerow manerow added safe to test Add this label to run secure Github workflows on PRs backend labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@gitar-bot

gitar-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🔴 High risk · Because this gates schema migrations and destructive drop-create operations, an incorrect collation result could block upgrades or table recreation.

Adds a preflight check to migrate and drop-create that stops on a MySQL database whose default or core table collation is not utf8mb4_0900_ai_ci, before any changes are made. The earlier issue where drop-create dropped tables before the check ran has been resolved. No open issues found.

✅ 1 closed
✅ Bug: drop-create drops every table before the collation check runs

📄 openmetadata-service/src/main/java/org/openmetadata/service/util/OpenMetadataOperations.java:3606-3608 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/MySqlCollationCheck.java:25-31
dropCreate() calls dropAllTables() first and only then calls validateAndRunSystemDataMigrations(true), which is where the new MySqlCollationCheck.verify(jdbi) runs. On a utf8mb4_unicode_ci database, drop-create therefore deletes every OpenMetadata table and then fails with a message saying "Nothing has been changed". The message is false here, and the PR description says drop-create checks "before changing anything". After the drop, the core tables are gone, so the check only sees the database default.

Fix: run the check in dropCreate() right after parseConfig() and before dropAllTables(). For example, pull it into a verifyMySqlCollation() helper that both migrate and drop-create call before they change anything. Also add a test proving that drop-create leaves the tables in place on a database with the wrong collation.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

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

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant