Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix MySQL utf8mb3 app DB Library root migration (#76540)

Andersoncfa17c66be9d
diff --git a/resources/migrations/062/20260513_legacy_library_root_entity_ids.yaml b/resources/migrations/062/20260513_legacy_library_root_entity_ids.yaml
index a6b66ae15c5..a64b20602af 100644
--- a/resources/migrations/062/20260513_legacy_library_root_entity_ids.yaml
+++ b/resources/migrations/062/20260513_legacy_library_root_entity_ids.yaml
@@ -19,6 +19,23 @@ databaseChangeLog:
rollback:
- empty: {}
+ - changeSet:
+ id: v62.legacy-library-root-entity-id-updated-id-cleanup
+ author: andsalves
+ comment: >-
+ Delete the first updated changeset rows for the Library Data and Library Metrics entity ID backfills. Those
+ changesets were re-id'd after patching their MySQL/MariaDB SQL to avoid hard-coded utf8mb4 collations, @see
+ #76510.
+ changes:
+ - sql:
+ sql: >-
+ DELETE FROM ${databasechangelog.name} WHERE id IN (
+ 'v62.2026-05-13T12:00:01-updated',
+ 'v62.2026-05-13T12:00:02-updated'
+ ) AND filename = 'migrations/062_update_migrations.yaml';
+ rollback:
+ - empty: {}
+
- changeSet:
id: v62.2026-05-13T11:59:58
author: andsalves
@@ -71,7 +88,7 @@ databaseChangeLog:
- empty: {}
- changeSet:
- id: v62.2026-05-13T12:00:01-updated
+ id: v62.2026-05-13T12:00:01-updated-2
author: andsalves
comment: Backfill canonical entity_id for legacy Library Data section
changes:
@@ -106,9 +123,9 @@ databaseChangeLog:
UPDATE collection
SET entity_id = 'librarylibrarydatadat'
WHERE type = 'library-data'
- AND location IN (
+ AND CAST(location AS BINARY) IN (
SELECT loc FROM (
- SELECT CONCAT('/', CAST(id AS CHAR), '/') COLLATE utf8mb4_unicode_ci AS loc
+ SELECT CAST(CONCAT('/', CAST(id AS CHAR), '/') AS BINARY) AS loc
FROM collection
WHERE type = 'library' AND location = '/'
) lib_loc
@@ -118,8 +135,8 @@ databaseChangeLog:
SELECT COUNT(*) AS cnt
FROM collection child
WHERE child.type = 'library-data'
- AND child.location IN (
- SELECT CONCAT('/', CAST(lib.id AS CHAR), '/') COLLATE utf8mb4_unicode_ci
+ AND CAST(child.location AS BINARY) IN (
+ SELECT CAST(CONCAT('/', CAST(lib.id AS CHAR), '/') AS BINARY)
FROM collection lib
WHERE lib.type = 'library' AND lib.location = '/'
)
@@ -129,7 +146,7 @@ databaseChangeLog:
- empty: {}
- changeSet:
- id: v62.2026-05-13T12:00:02-updated
+ id: v62.2026-05-13T12:00:02-updated-2
author: andsalves
comment: Backfill canonical entity_id for legacy Library Metrics section
changes:
@@ -164,9 +181,9 @@ databaseChangeLog:
UPDATE collection
SET entity_id = 'librarylibrarymetrics'
WHERE type = 'library-metrics'
- AND location IN (
+ AND CAST(location AS BINARY) IN (
SELECT loc FROM (
- SELECT CONCAT('/', CAST(id AS CHAR), '/') COLLATE utf8mb4_unicode_ci AS loc
+ SELECT CAST(CONCAT('/', CAST(id AS CHAR), '/') AS BINARY) AS loc
FROM collection
WHERE type = 'library' AND location = '/'
) lib_loc
@@ -176,8 +193,8 @@ databaseChangeLog:
SELECT COUNT(*) AS cnt
FROM collection child
WHERE child.type = 'library-metrics'
- AND child.location IN (
- SELECT CONCAT('/', CAST(lib.id AS CHAR), '/') COLLATE utf8mb4_unicode_ci
+ AND CAST(child.location AS BINARY) IN (
+ SELECT CAST(CONCAT('/', CAST(lib.id AS CHAR), '/') AS BINARY)
FROM collection lib
WHERE lib.type = 'library' AND lib.location = '/'
)
diff --git a/test/metabase/app_db/schema_migrations_test.clj b/test/metabase/app_db/schema_migrations_test.clj
index 4987a64e6f8..9dd4f82003d 100644
--- a/test/metabase/app_db/schema_migrations_test.clj
+++ b/test/metabase/app_db/schema_migrations_test.clj
@@ -2893,8 +2893,8 @@
(str/trim (t2/select-one-fn :entity_id :collection :id collection-id)))
(deftest backfill-legacy-library-root-collection-entity-ids-test
- (testing "v62.2026-05-13T12:00:00 through v62.2026-05-13T12:00:02-updated: backfill canonical Library root entity IDs"
- (impl/test-migrations ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated"] [migrate!]
+ (testing "v62.2026-05-13T12:00:00 through v62.2026-05-13T12:00:02-updated-2: backfill canonical Library root entity IDs"
+ (impl/test-migrations ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated-2"] [migrate!]
(let [library-id (insert-legacy-library-collection! {:name "Library"
:slug "library"
:type "library"
@@ -2917,9 +2917,42 @@
(is (= "librarylibrarymetrics"
(collection-entity-id metrics-id)))))))
+(deftest backfill-legacy-library-root-collection-entity-ids-mysql-utf8mb3-test
+ (testing "Library root entity ID backfill handles utf8mb3 MySQL app DB sessions (#76510)"
+ (mt/test-driver :mysql
+ (impl/with-temp-empty-app-db [conn :mysql]
+ (impl/run-migrations-in-range! conn
+ [(str "v" "00.00-000") "v62.2026-05-13T12:00:00"]
+ {:inclusive-end? false})
+ (jdbc/execute! {:connection conn}
+ "ALTER TABLE collection CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci")
+ (let [library-id (insert-legacy-library-collection! {:name "Library"
+ :slug "library"
+ :type "library"
+ :entity_id "legacy-library-root"})
+ data-id (insert-legacy-library-collection! {:name "Data"
+ :slug "data"
+ :type "library-data"
+ :location (str "/" library-id "/")
+ :entity_id "legacy-library-data"})
+ metrics-id (insert-legacy-library-collection! {:name "Metrics"
+ :slug "metrics"
+ :type "library-metrics"
+ :location (str "/" library-id "/")
+ :entity_id "legacy-library-metric"})]
+ (jdbc/execute! {:connection conn} "SET NAMES utf8 COLLATE utf8_general_ci")
+ (impl/run-migrations-in-range! conn
+ ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated-2"])
+ (is (= "librarylibrarylibrary"
+ (collection-entity-id library-id)))
+ (is (= "librarylibrarydatadat"
+ (collection-entity-id data-id)))
+ (is (= "librarylibrarymetrics"
+ (collection-entity-id metrics-id))))))))
+
(deftest backfill-legacy-library-root-collection-entity-ids-test-2
(testing "ambiguous Library Data direct children are not modified"
- (impl/test-migrations ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated"] [migrate!]
+ (impl/test-migrations ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated-2"] [migrate!]
(let [library-id (insert-legacy-library-collection! {:name "Library"
:slug "library"
:type "library"
@@ -2951,7 +2984,7 @@
(deftest backfill-legacy-library-root-collection-entity-ids-test-3
(testing "Library Data collections outside Library root do not count as ambiguous"
- (impl/test-migrations ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated"] [migrate!]
+ (impl/test-migrations ["v62.2026-05-13T12:00:00" "v62.2026-05-13T12:00:02-updated-2"] [migrate!]
(let [library-id (insert-legacy-library-collection! {:name "Library"
:slug "library"
:type "library"
@@ -2979,7 +3012,7 @@
(deftest backfill-legacy-library-root-collection-entity-ids-test-4
(testing "pre-existing canonical Library rows with missing types prevent entity_id collisions"
- (impl/test-migrations ["v62.2026-05-13T11:59:58" "v62.2026-05-13T12:00:02-updated"] [migrate!]
+ (impl/test-migrations ["v62.2026-05-13T11:59:58" "v62.2026-05-13T12:00:02-updated-2"] [migrate!]
(let [canonical-library-id (insert-legacy-library-collection! {:name "Pre-existing canonical Library"
:slug "canonical-library"
:type nil