From 58d5988a16a99586fb520284204c6e3e519b9d1b Mon Sep 17 00:00:00 2001 From: Mohit Yadav <105265192+mohityadav766@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:45:58 +0530 Subject: [PATCH] Add Onboarding SQL (#19525) * Add Primary Key Migration * Update queries and conflict on apps data store * Update queries and conflict on apps data store * add index on isBot --- .../sql/migrations/native/1.6.3/mysql/schemaChanges.sql | 5 +++++ .../sql/migrations/native/1.6.3/postgres/schemaChanges.sql | 5 +++++ .../java/org/openmetadata/service/jdbi3/CollectionDAO.java | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bootstrap/sql/migrations/native/1.6.3/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.6.3/mysql/schemaChanges.sql index e69de29bb2d..1bd78fc4dc8 100644 --- a/bootstrap/sql/migrations/native/1.6.3/mysql/schemaChanges.sql +++ b/bootstrap/sql/migrations/native/1.6.3/mysql/schemaChanges.sql @@ -0,0 +1,5 @@ +-- Add constraint to apps_data_store +ALTER TABLE apps_data_store ADD CONSTRAINT entity_relationship_pky PRIMARY KEY (identifier, type); +UPDATE user_entity SET json = JSON_SET(json, '$.isBot', false) WHERE JSON_EXTRACT(json, '$.isBot') IS NULL; +ALTER TABLE user_entity ADD COLUMN isBot BOOLEAN GENERATED ALWAYS AS (json -> '$.isBot') NOT NULL; +CREATE INDEX idx_isBot ON user_entity (isBot); \ No newline at end of file diff --git a/bootstrap/sql/migrations/native/1.6.3/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.6.3/postgres/schemaChanges.sql index e69de29bb2d..b8a8f413fc0 100644 --- a/bootstrap/sql/migrations/native/1.6.3/postgres/schemaChanges.sql +++ b/bootstrap/sql/migrations/native/1.6.3/postgres/schemaChanges.sql @@ -0,0 +1,5 @@ +-- Add constraint to apps_data_store +ALTER TABLE apps_data_store ADD CONSTRAINT entity_relationship_pky PRIMARY KEY (identifier, type); +UPDATE user_entity SET json = jsonb_set(json::jsonb, '{isBot}', 'false'::jsonb, true) WHERE NOT (json ? 'isBot'); +ALTER TABLE user_entity ADD COLUMN isBot BOOLEAN GENERATED ALWAYS AS ((json ->> 'deleted')::boolean) STORED NOT NULL; +CREATE INDEX idx_isBot ON user_entity (isBot); \ No newline at end of file diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java index fb1bd3ec661..05f04a292d0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java @@ -4893,11 +4893,11 @@ public interface CollectionDAO { interface AppsDataStore { @ConnectionAwareSqlUpdate( value = - "INSERT INTO apps_data_store(identifier, type, json) VALUES (:identifier, :type, :json)", + "INSERT INTO apps_data_store(identifier, type, json) VALUES (:identifier, :type, :json) ON DUPLICATE KEY UPDATE json = VALUES(json)", connectionType = MYSQL) @ConnectionAwareSqlUpdate( value = - "INSERT INTO apps_data_store(identifier, type, json) VALUES (:identifier, :type, :json :: jsonb)", + "INSERT INTO apps_data_store(identifier, type, json) VALUES (:identifier, :type, :json :: jsonb) ON CONFLICT (identifier, type) DO UPDATE SET json = EXCLUDED.json", connectionType = POSTGRES) void insert( @Bind("identifier") String identifier,