From 7c80c07eab2cdb9f2b8aad41a38f81294cd547f9 Mon Sep 17 00:00:00 2001 From: Mohit Yadav <105265192+mohityadav766@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:16:53 +0530 Subject: [PATCH] Move Migration to 1.4.6 (#17095) --- .../mysql/postDataMigrationSQLScript.sql | 43 +++++++++++++++++ .../native/1.4.6/mysql/schemaChanges.sql | 0 .../postgres/postDataMigrationSQLScript.sql | 43 +++++++++++++++++ .../native/1.4.6/postgres/schemaChanges.sql | 0 .../mysql/postDataMigrationSQLScript.sql | 46 +------------------ .../postgres/postDataMigrationSQLScript.sql | 43 ----------------- 6 files changed, 87 insertions(+), 88 deletions(-) create mode 100644 bootstrap/sql/migrations/native/1.4.6/mysql/postDataMigrationSQLScript.sql create mode 100644 bootstrap/sql/migrations/native/1.4.6/mysql/schemaChanges.sql create mode 100644 bootstrap/sql/migrations/native/1.4.6/postgres/postDataMigrationSQLScript.sql create mode 100644 bootstrap/sql/migrations/native/1.4.6/postgres/schemaChanges.sql diff --git a/bootstrap/sql/migrations/native/1.4.6/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.4.6/mysql/postDataMigrationSQLScript.sql new file mode 100644 index 00000000000..475f86a1ad7 --- /dev/null +++ b/bootstrap/sql/migrations/native/1.4.6/mysql/postDataMigrationSQLScript.sql @@ -0,0 +1,43 @@ +-- Remove Duplicate Usernames and Lowercase Them +WITH cte AS ( + SELECT + id, + ROW_NUMBER() OVER (PARTITION BY LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.name'))) ORDER BY id) as rn + FROM + user_entity +) +DELETE FROM user_entity +WHERE id IN ( + SELECT id + FROM cte + WHERE rn > 1 +); + +UPDATE user_entity +SET json = JSON_SET( + json, + '$.name', + LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.name'))) +); + +-- Remove Duplicate Emails and Lowercase Them +WITH cte AS ( + SELECT + id, + ROW_NUMBER() OVER (PARTITION BY LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.email'))) ORDER BY id) as rn + FROM + user_entity +) +DELETE FROM user_entity +WHERE id IN ( + SELECT id + FROM cte + WHERE rn > 1 +); + +UPDATE user_entity +SET json = JSON_SET( + json, + '$.email', + LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.email'))) +); diff --git a/bootstrap/sql/migrations/native/1.4.6/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.4.6/mysql/schemaChanges.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bootstrap/sql/migrations/native/1.4.6/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.4.6/postgres/postDataMigrationSQLScript.sql new file mode 100644 index 00000000000..adb0d2cd7ca --- /dev/null +++ b/bootstrap/sql/migrations/native/1.4.6/postgres/postDataMigrationSQLScript.sql @@ -0,0 +1,43 @@ +-- Remove Duplicate UserNames and lowercase them +WITH cte AS ( + SELECT + id, + ROW_NUMBER() OVER (PARTITION BY to_jsonb(LOWER(json->>'name')) ORDER BY id) as rn + FROM + user_entity +) +DELETE from user_entity +WHERE id IN ( + SELECT id + FROM cte + WHERE rn > 1 +); + +UPDATE user_entity +SET json = jsonb_set( + json, + '{name}', + to_jsonb(LOWER(json->>'name')) +); + +-- Remove Duplicate Emails and lowercase them +WITH cte AS ( + SELECT + id, + ROW_NUMBER() OVER (PARTITION BY to_jsonb(LOWER(json->>'email')) ORDER BY id) as rn + FROM + user_entity +) +DELETE from user_entity +WHERE id IN ( + SELECT id + FROM cte + WHERE rn > 1 +); + +UPDATE user_entity +SET json = jsonb_set( + json, + '{email}', + to_jsonb(LOWER(json->>'email')) +); diff --git a/bootstrap/sql/migrations/native/1.4.6/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.4.6/postgres/schemaChanges.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql index 740cbab52e0..7b1d6e095d4 100644 --- a/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql @@ -22,48 +22,4 @@ WHERE name IN ( 'columnValuesSumToBeBetween', 'columnValuesToBeBetween', 'tableRowCountToBeBetween' -); - --- Remove Duplicate Usernames and Lowercase Them -WITH cte AS ( - SELECT - id, - ROW_NUMBER() OVER (PARTITION BY LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.name'))) ORDER BY id) as rn - FROM - user_entity -) -DELETE FROM user_entity -WHERE id IN ( - SELECT id - FROM cte - WHERE rn > 1 -); - -UPDATE user_entity -SET json = JSON_SET( - json, - '$.name', - LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.name'))) -); - --- Remove Duplicate Emails and Lowercase Them -WITH cte AS ( - SELECT - id, - ROW_NUMBER() OVER (PARTITION BY LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.email'))) ORDER BY id) as rn - FROM - user_entity -) -DELETE FROM user_entity -WHERE id IN ( - SELECT id - FROM cte - WHERE rn > 1 -); - -UPDATE user_entity -SET json = JSON_SET( - json, - '$.email', - LOWER(JSON_UNQUOTE(JSON_EXTRACT(json, '$.email'))) -); +); \ No newline at end of file diff --git a/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql index 3ac2106b72a..85af0338b84 100644 --- a/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql @@ -23,46 +23,3 @@ WHERE name IN ( 'tableRowCountToBeBetween' ); --- Remove Duplicate UserNames and lowercase them -WITH cte AS ( - SELECT - id, - ROW_NUMBER() OVER (PARTITION BY to_jsonb(LOWER(json->>'name')) ORDER BY id) as rn - FROM - user_entity -) -DELETE from user_entity -WHERE id IN ( - SELECT id - FROM cte - WHERE rn > 1 -); - -UPDATE user_entity -SET json = jsonb_set( - json, - '{name}', - to_jsonb(LOWER(json->>'name')) -); - --- Remove Duplicate Emails and lowercase them -WITH cte AS ( - SELECT - id, - ROW_NUMBER() OVER (PARTITION BY to_jsonb(LOWER(json->>'email')) ORDER BY id) as rn - FROM - user_entity -) -DELETE from user_entity -WHERE id IN ( - SELECT id - FROM cte - WHERE rn > 1 -); - -UPDATE user_entity -SET json = jsonb_set( - json, - '{email}', - to_jsonb(LOWER(json->>'email')) -);