From ab1e40099045fce445ccc5c779dbc5c65ce1a881 Mon Sep 17 00:00:00 2001 From: Ayush Shah Date: Mon, 5 Aug 2024 20:28:07 +0530 Subject: [PATCH] Minor: Remove 'owner' field from JSON in various entities (#17290) * Remove owner field from json in various entities * Add Psql migrations for owner * Modify operator type for query * chore: Update table_entity JSON structure to include dataModel owners --- .../native/1.5.0/mysql/schemaChanges.sql | 52 +++++++++++++++++++ .../native/1.5.0/postgres/schemaChanges.sql | 48 +++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/bootstrap/sql/migrations/native/1.5.0/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.5.0/mysql/schemaChanges.sql index 552d0a44020..e8344f674e3 100644 --- a/bootstrap/sql/migrations/native/1.5.0/mysql/schemaChanges.sql +++ b/bootstrap/sql/migrations/native/1.5.0/mysql/schemaChanges.sql @@ -232,3 +232,55 @@ UPDATE ingestion_pipeline_entity SET json = JSON_REMOVE(json, '$.owner', '$.service'); ALTER TABLE thread_entity ADD COLUMN domain VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.domain'); + +-- Remove owner from json from all entities +update api_collection_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update api_endpoint_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update api_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update bot_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update chart_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update dashboard_data_model_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update dashboard_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update dashboard_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update data_product_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update database_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update database_schema_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update dbservice_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update di_chart_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update domain_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update event_subscription_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update glossary_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update glossary_term_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update ingestion_pipeline_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update kpi_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update messaging_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update metadata_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update metric_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update ml_model_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update mlmodel_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update persona_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update pipeline_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update pipeline_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update policy_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update query_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update report_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update role_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update search_index_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update search_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update storage_container_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update storage_service_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update stored_procedure_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update table_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update team_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update thread_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update topic_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update type_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; +update user_entity set json = JSON_REMOVE(json, '$.owner') where json -> '$.owner' is not null; + +update table_entity set json = JSON_SET( + JSON_REMOVE(json, '$.dataModel.owner'), + '$.dataModel.owners', + JSON_ARRAY( + JSON_EXTRACT(json, '$.dataModel.owner') + ) +) where json -> '$.dataModel.owner' is not null; diff --git a/bootstrap/sql/migrations/native/1.5.0/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.5.0/postgres/schemaChanges.sql index 54bc6d04069..0a6246b3f2d 100644 --- a/bootstrap/sql/migrations/native/1.5.0/postgres/schemaChanges.sql +++ b/bootstrap/sql/migrations/native/1.5.0/postgres/schemaChanges.sql @@ -218,3 +218,51 @@ SET json = json::jsonb #- '{service}' WHERE json #> '{service}' IS NOT NULL; ALTER TABLE thread_entity ADD COLUMN domain VARCHAR(256) GENERATED ALWAYS AS (json ->> 'domain') STORED; + +-- Remove owner from json from all entities + +update api_collection_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update api_endpoint_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update api_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update bot_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update chart_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update dashboard_data_model_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update dashboard_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update dashboard_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update data_product_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update database_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update database_schema_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update dbservice_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update di_chart_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update domain_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update event_subscription_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update glossary_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update glossary_term_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update ingestion_pipeline_entity set json = json::jsonb#-'{owner}' where json::jsonb #>> '{owner}' is not null; +update kpi_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update messaging_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update metadata_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update metric_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update ml_model_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update mlmodel_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update persona_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update pipeline_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update pipeline_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update policy_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update query_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update report_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update role_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update search_index_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update search_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update storage_container_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update storage_service_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update stored_procedure_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update table_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update team_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update thread_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update topic_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update type_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; +update user_entity set json = json#-'{owner}' where json #>> '{owner}' is not null; + +update table_entity set json = jsonb_set(json#-'{dataModel,owner}', '{dataModel,owners}', +jsonb_build_array(json#>'{dataModel,owner}')) where json #>> '{dataModel,owner}' is not null;