From 2f84bfbfa824e7ff52879c48478463abafc4b215 Mon Sep 17 00:00:00 2001 From: Vivek Ratnavel Subramanian Date: Thu, 1 Sep 2022 22:22:42 -0700 Subject: [PATCH] Fix #7100 Upgrade issues for 0.12 release (#7101) --- .../v004__create_db_connection_info.sql | 8 +++++- .../v004__create_db_connection_info.sql | 6 +++++ .../catalog/jdbi3/EntityRepository.java | 5 +++- .../catalog/jdbi3/TeamRepository.java | 26 +++++++++---------- .../catalog/resources/types/TypeResource.java | 2 +- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/bootstrap/sql/com.mysql.cj.jdbc.Driver/v004__create_db_connection_info.sql b/bootstrap/sql/com.mysql.cj.jdbc.Driver/v004__create_db_connection_info.sql index 948eabc1ca0..9577b4838f4 100644 --- a/bootstrap/sql/com.mysql.cj.jdbc.Driver/v004__create_db_connection_info.sql +++ b/bootstrap/sql/com.mysql.cj.jdbc.Driver/v004__create_db_connection_info.sql @@ -109,4 +109,10 @@ DELETE FROM entity_extension WHERE jsonSchema IN ('tableProfile', 'columnTest', 'tableTest'); DELETE FROM ingestion_pipeline_entity -WHERE LOWER(JSON_EXTRACT(json, '$.pipelineType') = 'profiler'); \ No newline at end of file +WHERE LOWER(JSON_EXTRACT(json, '$.pipelineType') = 'profiler'); + +DELETE FROM role_entity; +DELETE FROM policy_entity; +DELETE FROM field_relationship WHERE fromType IN ('role', 'policy') OR toType IN ('role', 'policy'); +DELETE FROM entity_relationship WHERE fromEntity IN ('role', 'policy') OR toEntity IN ('role', 'policy'); +ALTER TABLE role_entity DROP COLUMN defaultRole; diff --git a/bootstrap/sql/org.postgresql.Driver/v004__create_db_connection_info.sql b/bootstrap/sql/org.postgresql.Driver/v004__create_db_connection_info.sql index 8054ba045f2..645833f28f3 100644 --- a/bootstrap/sql/org.postgresql.Driver/v004__create_db_connection_info.sql +++ b/bootstrap/sql/org.postgresql.Driver/v004__create_db_connection_info.sql @@ -105,3 +105,9 @@ WHERE jsonSchema IN ('tableProfile', 'columnTest', 'tableTest'); DELETE FROM ingestion_pipeline_entity WHERE json_extract_path_text("json", 'pipelineType') = 'profiler'; + +DELETE FROM role_entity; +DELETE FROM policy_entity; +DELETE FROM field_relationship WHERE fromType IN ('role', 'policy') OR toType IN ('role', 'policy'); +DELETE FROM entity_relationship WHERE fromEntity IN ('role', 'policy') OR toEntity IN ('role', 'policy'); +ALTER TABLE role_entity DROP COLUMN defaultRole; diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java index f6514cde5e4..cdb42558b77 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java @@ -1125,7 +1125,10 @@ public abstract class EntityRepository { this.original = original; this.updated = updated; this.operation = operation; - this.updatingUser = SubjectCache.getInstance().getSubjectContext(updated.getUpdatedBy()).getUser(); + this.updatingUser = + updated.getUpdatedBy().equalsIgnoreCase("admin") + ? new User().withName("admin").withIsAdmin(true) + : SubjectCache.getInstance().getSubjectContext(updated.getUpdatedBy()).getUser(); } /** Compare original and updated entities and perform updates. Update the entity version and track changes. */ diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java index 6279840f3b1..e20943df4fa 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java @@ -328,21 +328,21 @@ public class TeamRepository extends EntityRepository { String json = dao.findJsonByFqn(ORGANIZATION_NAME, Include.ALL); if (json == null) { LOG.debug("Organization {} is not initialized", ORGANIZATION_NAME); - EntityReference organizationPolicy = Entity.getEntityReferenceByName(POLICY, "OrganizationPolicy", Include.ALL); - EntityReference dataConsumerRole = Entity.getEntityReferenceByName(ROLE, "DataConsumer", Include.ALL); - Team team = - new Team() - .withId(UUID.randomUUID()) - .withName(ORGANIZATION_NAME) - .withDisplayName(ORGANIZATION_NAME) - .withDescription("Organization under which all the other team hierarchy is created") - .withTeamType(ORGANIZATION) - .withUpdatedBy("admin") - .withUpdatedAt(System.currentTimeMillis()) - .withPolicies(new ArrayList<>(List.of(organizationPolicy))) - .withDefaultRoles(new ArrayList<>(List.of(dataConsumerRole))); // Teams try { + EntityReference organizationPolicy = Entity.getEntityReferenceByName(POLICY, "OrganizationPolicy", Include.ALL); + EntityReference dataConsumerRole = Entity.getEntityReferenceByName(ROLE, "DataConsumer", Include.ALL); + Team team = + new Team() + .withId(UUID.randomUUID()) + .withName(ORGANIZATION_NAME) + .withDisplayName(ORGANIZATION_NAME) + .withDescription("Organization under which all the other team hierarchy is created") + .withTeamType(ORGANIZATION) + .withUpdatedBy("admin") + .withUpdatedAt(System.currentTimeMillis()) + .withPolicies(new ArrayList<>(List.of(organizationPolicy))) + .withDefaultRoles(new ArrayList<>(List.of(dataConsumerRole))); organization = create(null, team); LOG.info("Organization {}:{} is successfully initialized", ORGANIZATION_NAME, organization.getId()); } catch (Exception e) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/types/TypeResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/types/TypeResource.java index 90c51169d5f..ca1ffca47dc 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/types/TypeResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/types/TypeResource.java @@ -111,7 +111,7 @@ public class TypeResource extends EntityResource { } this.dao.createOrUpdate(null, type); this.dao.addToRegistry(type); - } catch (IOException e) { + } catch (Exception e) { LOG.error("Error loading type {}", type.getName(), e); } });