Fix entity_ext owner update query (#17493)

This commit is contained in:
Onkar Ravgan 2024-08-20 04:31:07 +05:30 committed by GitHub
parent 424a03f49c
commit 2a8ee41c38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 16 deletions

View File

@ -209,16 +209,13 @@ WHERE JSON_CONTAINS_PATH(json, 'one', '$.feedInfo.entitySpecificInfo.updatedOwne
AND JSON_TYPE(JSON_EXTRACT(json, '$.feedInfo.entitySpecificInfo.updatedOwner')) <> 'ARRAY'; AND JSON_TYPE(JSON_EXTRACT(json, '$.feedInfo.entitySpecificInfo.updatedOwner')) <> 'ARRAY';
-- Update entity_extension to move owner to array -- Update entity_extension to move owner to array
UPDATE entity_extension update entity_extension set json = JSON_SET(
SET json = JSON_SET( JSON_REMOVE(json, '$.owner'),
json, '$.owners',
'$.owner',
JSON_ARRAY( JSON_ARRAY(
JSON_EXTRACT(json, '$.owner') JSON_EXTRACT(json, '$.owner')
) )
) ) where json -> '$.owner' is not null;
WHERE JSON_CONTAINS_PATH(json, 'one', '$.owner')
AND JSON_TYPE(JSON_EXTRACT(json, '$.owner')) <> 'ARRAY';
ALTER TABLE test_case MODIFY COLUMN `name` VARCHAR(512) GENERATED ALWAYS AS (json ->> '$.name') NOT NULL; ALTER TABLE test_case MODIFY COLUMN `name` VARCHAR(512) GENERATED ALWAYS AS (json ->> '$.name') NOT NULL;

View File

@ -191,15 +191,8 @@ WHERE jsonb_path_exists(json, '$.feedInfo.entitySpecificInfo.updatedOwner')
AND jsonb_typeof(json->'feedInfo'->'entitySpecificInfo'->'updatedOwner') <> 'array'; AND jsonb_typeof(json->'feedInfo'->'entitySpecificInfo'->'updatedOwner') <> 'array';
-- Update entity_extension to move owner to array -- Update entity_extension to move owner to array
UPDATE entity_extension update entity_extension set json = jsonb_set(json#-'{owner}', '{owners}',
SET json = jsonb_set( jsonb_build_array(json#>'{owner}')) where json #>> '{owner}' is not null;
json,
'{owner}',
to_jsonb(ARRAY[jsonb_path_query_first(json, '$.owner')])
)
WHERE jsonb_path_exists(json, '$.owner')
AND jsonb_path_query_first(json, '$.owner ? (@ != null)') IS NOT null
AND jsonb_typeof(json->'owner') <> 'array';
ALTER TABLE test_case ALTER COLUMN name TYPE VARCHAR(512); ALTER TABLE test_case ALTER COLUMN name TYPE VARCHAR(512);