Repository navigation
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
| SET @ontology_axiom_relationship_cleanup_sql = CONCAT( | ||
| 'DELETE FROM entity_relationship WHERE (fromEntity = ''ontologyAxiom'' AND fromId IN (SELECT id COLLATE ', | ||
| (SELECT COLLATION_NAME FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'entity_relationship' AND column_name = 'fromId'), | ||
| ' FROM ontology_axiom_entity WHERE json_extract(json, ''$.ontology.id'') IS NULL)) OR (toEntity = ''ontologyAxiom'' AND toId IN (SELECT id COLLATE ', | ||
| (SELECT COLLATION_NAME FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'entity_relationship' AND column_name = 'toId'), | ||
| ' FROM ontology_axiom_entity WHERE json_extract(json, ''$.ontology.id'') IS NULL))' | ||
| ); | ||
| PREPARE ontology_axiom_relationship_cleanup_stmt FROM @ontology_axiom_relationship_cleanup_sql; | ||
| EXECUTE ontology_axiom_relationship_cleanup_stmt; | ||
| DEALLOCATE PREPARE ontology_axiom_relationship_cleanup_stmt; | ||
| SET @ontology_axiom_extension_cleanup_sql = CONCAT( | ||
| 'DELETE FROM entity_extension WHERE id IN (SELECT id COLLATE ', | ||
| (SELECT COLLATION_NAME FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'entity_extension' AND column_name = 'id'), | ||
| ' FROM ontology_axiom_entity WHERE json_extract(json, ''$.ontology.id'') IS NULL)' | ||
| ); |
There was a problem hiding this comment.
⚠️ Bug: COLLATE fails when the database charset isn't utf8mb4
Each guarded block puts COLLATE <entity_relationship/entity_extension column collation> on a utf8mb4 column (ontology_axiom_entity.id, ontology_change_set_entity.id, test_case_resolution_status_time_series.id, all pinned to utf8mb4_0900_ai_ci). The lookup only reads COLLATION_NAME. entity_relationship and entity_extension were created in flyway v001 with no charset, so they use the database default. On an older install whose default charset is utf8mb3 or latin1, the generated SQL becomes id COLLATE utf8mb3_general_ci or id COLLATE latin1_swedish_ci. MySQL rejects that with ER 1253 (COLLATION '...' is not valid for CHARACTER SET 'utf8mb4'), so the 2.1.0 migration and the server startup still fail. The original text didn't fail there, because MySQL converts the non-utf8mb4 side to utf8mb4 for these implicit compares. So the change can break databases that used to migrate cleanly, which contradicts the 'any database collation' goal.
Fix: also read CHARACTER_SET_NAME and build CONVERT(id USING <charset>) COLLATE <collation> (UUIDs are ASCII, so the conversion loses nothing). That keeps the index on the entity_relationship/entity_extension side and works for every charset.
Convert to the target column's charset before applying its collation (same pattern for every block):
SET @ontology_axiom_extension_cleanup_sql = (
SELECT CONCAT(
'DELETE FROM entity_extension WHERE id IN (SELECT CONVERT(id USING ', CHARACTER_SET_NAME, ') COLLATE ', COLLATION_NAME,
' FROM ontology_axiom_entity WHERE json_extract(json, ''$.ontology.id'') IS NULL)')
FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'entity_extension' AND column_name = 'id'
);
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
Issue
No issue. Found while finding why the nightly "Java UI ITs (embedded)" jobs on
mainand2.1have lost their runner every night since 10-20.Problem
On a MySQL database whose default collation is not
utf8mb4_0900_ai_ci(for exampleutf8mb4_unicode_ci), the 2.1.0 migration fails withIllegal mix of collations ... for operation '='.Six statements compare ids across two kinds of tables:
COLLATE=utf8mb4_0900_ai_ci(the ontology tables,test_case_resolution_status_time_series)entity_relationship,entity_extension)MySQL refuses to compare two columns with different collations, even when the tables are empty. So every upgrade on such a database hits it, not only ones with rows to clean.
migratestops at the first of these statements.migrate --forceskips it, but a skipped statement is never recorded, so the server then refuses to start: "There are pending migrations to be run on the database: [2.1.0]".The UI integration tests run on a MySQL with
utf8mb4_unicode_ci. Since these statements landed, their server never starts.What this PR changes
Each of those statements becomes a guarded block (
SET/PREPARE/EXECUTE/DEALLOCATE). The block reads, at run time, the collation of the older table's column frominformation_schema.columns, and applies it to the other side withCOLLATE. So:entity_relationshipandentity_extensioninto full scans)The statements:
schemaChanges.sql(from PR Fixes 35671: Add native ontologies and governed releases #35672)test_case_incidentbackfill inpostDataMigrationSQLScript.sql(from PR fix(dq): delete incident summary rows with their incident history #37054)They delete and insert the same rows as before, and they stay idempotent. A database that already ran the old text runs the new blocks once more, with no effect.
How it was tested
utf8mb4_unicode_ci: onmain,migratefails on these statements and the server never starts. With this PR,migrate(no--force) exits 0, every statement is recorded, and the server starts.utf8mb4_0900_ai_ci: unchanged;migrateexits 0 and the server starts.mainthe server cannot start.MySqlGuardedBlockNamesTestandMySqlMigrationUnitsTest.The harness side of the nightly failure (leaked containers when the server cannot start) is fixed separately.