From 71f993a2fc474f801990d9f4f19bfbe76f0119a5 Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 22 Sep 2025 15:13:25 +0200 Subject: [PATCH] Minor fix broken 1.9.8 migrations (#23487) * chore: fix duplicate migrations from 1.9.8 * fix: psql update query --- .../native/1.9.10/mysql/postDataMigrationSQLScript.sql | 7 +++++++ .../sql/migrations/native/1.9.10/mysql/schemaChanges.sql | 0 .../1.9.10/postgres/postDataMigrationSQLScript.sql | 7 +++++++ .../migrations/native/1.9.10/postgres/schemaChanges.sql | 0 .../native/1.9.9/mysql/postDataMigrationSQLScript.sql | 6 ++++-- .../native/1.9.9/postgres/postDataMigrationSQLScript.sql | 9 ++++++--- 6 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 bootstrap/sql/migrations/native/1.9.10/mysql/postDataMigrationSQLScript.sql create mode 100644 bootstrap/sql/migrations/native/1.9.10/mysql/schemaChanges.sql create mode 100644 bootstrap/sql/migrations/native/1.9.10/postgres/postDataMigrationSQLScript.sql create mode 100644 bootstrap/sql/migrations/native/1.9.10/postgres/schemaChanges.sql diff --git a/bootstrap/sql/migrations/native/1.9.10/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.9.10/mysql/postDataMigrationSQLScript.sql new file mode 100644 index 00000000000..6301f8a4f6c --- /dev/null +++ b/bootstrap/sql/migrations/native/1.9.10/mysql/postDataMigrationSQLScript.sql @@ -0,0 +1,7 @@ +-- If you upgraded to 1.9.8 with the initial migration and then upgraded to 1.9.9 +-- `'profileData', pdts.json` `pdts.json` will have the profileData in the json field +-- you will hence have performed the same migration again. This brings the json +-- `profileData`field back to the original state. +UPDATE profiler_data_time_series +SET json = JSON_SET(json, '$.profileData', json->'$.profileData.profileData') +WHERE json->>'$.profileData.profileData' IS NOT NULL; \ No newline at end of file diff --git a/bootstrap/sql/migrations/native/1.9.10/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.9.10/mysql/schemaChanges.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bootstrap/sql/migrations/native/1.9.10/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.9.10/postgres/postDataMigrationSQLScript.sql new file mode 100644 index 00000000000..9613da24ee0 --- /dev/null +++ b/bootstrap/sql/migrations/native/1.9.10/postgres/postDataMigrationSQLScript.sql @@ -0,0 +1,7 @@ +-- If you upgraded to 1.9.8 with the initial migration and then upgraded to 1.9.9 +-- `'profileData', pdts.json` `pdts.json` will have the profileData in the json field +-- you will hence have performed the same migration again. This brings the json +-- `profileData`field back to the original state. +UPDATE profiler_data_time_series +SET json = jsonb_set(json::jsonb, '{profileData}', json::jsonb->'profileData'->'profileData')::json +WHERE json->'profileData'->>'profileData' IS NOT NULL; \ No newline at end of file diff --git a/bootstrap/sql/migrations/native/1.9.10/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.9.10/postgres/schemaChanges.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bootstrap/sql/migrations/native/1.9.9/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.9.9/mysql/postDataMigrationSQLScript.sql index b98f8d3f779..afb3dea909a 100644 --- a/bootstrap/sql/migrations/native/1.9.9/mysql/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.9.9/mysql/postDataMigrationSQLScript.sql @@ -28,7 +28,8 @@ SET pdts.json = JSON_OBJECT( 'profileData', pdts.json, 'profileType', 'table' ) -WHERE pdts.extension = 'table.tableProfile'; +WHERE pdts.extension = 'table.tableProfile' +AND pdts.json->>'$.profileData' IS NULL; -- Migrate system profiles (direct match) UPDATE profiler_data_time_series pdts @@ -45,7 +46,8 @@ SET pdts.json = JSON_OBJECT( 'profileData', pdts.json, 'profileType', 'system' ) -WHERE pdts.extension = 'table.systemProfile'; +WHERE pdts.extension = 'table.systemProfile' +AND pdts.json->>'$.profileData' IS NULL; -- Migrate column profiles using temporary mapping table for better performance -- Create temporary mapping table to extract table hash from column hash diff --git a/bootstrap/sql/migrations/native/1.9.9/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.9.9/postgres/postDataMigrationSQLScript.sql index 4efc8388c2a..0d3f9dbed5a 100644 --- a/bootstrap/sql/migrations/native/1.9.9/postgres/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.9.9/postgres/postDataMigrationSQLScript.sql @@ -33,7 +33,8 @@ SET json = jsonb_build_object( ) FROM table_entity te WHERE pdts.entityFQNHash = te.fqnHash - AND pdts.extension = 'table.tableProfile'; + AND pdts.extension = 'table.tableProfile' + AND pdts.json->>'profileData' IS NULL; -- Migrate system profiles (direct match) UPDATE profiler_data_time_series pdts @@ -51,7 +52,8 @@ SET json = jsonb_build_object( ) FROM table_entity te WHERE pdts.entityFQNHash = te.fqnHash - AND pdts.extension = 'table.systemProfile'; + AND pdts.extension = 'table.systemProfile' + AND pdts.json->>'profileData' IS NULL; -- Migrate column profiles using temporary mapping table for better performance -- Use UNLOGGED table for memory-like performance (no WAL writes) @@ -95,7 +97,8 @@ SET json = jsonb_build_object( FROM column_to_table_mapping ctm INNER JOIN table_entity te ON ctm.table_hash = te.fqnHash WHERE pdts.entityFQNHash = ctm.column_hash - AND pdts.extension = 'table.columnProfile'; + AND pdts.extension = 'table.columnProfile' + AND pdts.json->>'profileData' IS NULL; -- Clean up temporary table DROP TABLE IF EXISTS column_to_table_mapping;