OpenMetadata/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql
Mohit Yadav b1620e682a
Fix Users Issue due to capital names (#16828)
* Fix Users Issue due to capital names

* Fixed Tests

* No lowercasing name

* Revert

* toLowerCase

* fix email casing from UI side on basic auth

* compare lowercase email only from the loggedInUser

* address comments

* Updated LowerCase UserName on updates

* revert ui changes

* Migrate Name and Email

* cypress failure

* fix glossary test

* fix activity feed test

* Compare by Lowercasing Email and username

---------

Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com>
Co-authored-by: Chira Madlani <chirag@getcollate.io>
Co-authored-by: karanh37 <karanh37@gmail.com>
2024-07-19 11:39:09 +05:30

69 lines
1.7 KiB
SQL

-- matchEnum Test Definition Parameter for columnValuesToBeInSet
UPDATE test_definition
SET json = jsonb_set(json, '{parameterDefinition}', json->'parameterDefinition' || '['
'{"name": "matchEnum", "displayName": "Match enum", "description": "If enabled, validate that each value independently matches the enum.", "dataType": "BOOLEAN", "required": false, "optionValues": []}'
']'::jsonb
)
WHERE name = 'columnValuesToBeInSet'
AND JSONB_ARRAY_LENGTH(json->'parameterDefinition') < 2;
-- Test Case dyanic test migration
UPDATE test_definition
SET json = JSONB_SET(json, '{supportsDynamicAssertion}', 'true', true)
WHERE name IN (
'columnValueMaxToBeBetween',
'columnValueMeanToBeBetween',
'columnValueMedianToBeBetween',
'columnValueMinToBeBetween',
'columnValueStdDevToBeBetween',
'columnValuesLengthsToBeBetween',
'columnValuesSumToBeBetween',
'columnValuesToBeBetween',
'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'))
);