Migrations fixes for #17967 (#18232)

* fix migrations.

* fix logging
This commit is contained in:
Siddhant 2024-10-11 19:21:12 +05:30 committed by GitHub
parent 69b34684b5
commit 07b039b8b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 96 additions and 32 deletions

View File

@ -42,19 +42,4 @@ SET json = JSON_REMOVE(json, '$.testCaseResult');
UPDATE installed_apps SET json = JSON_SET(json, '$.supportsInterrupt', true) where name = 'SearchIndexingApplication';
UPDATE apps_marketplace SET json = JSON_SET(json, '$.supportsInterrupt', true) where name = 'SearchIndexingApplication';
ALTER TABLE apps_extension_time_series ADD COLUMN appName VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.appName') STORED NOT NULL;
-- Update serviceType in api_endpoint_entity table
UPDATE api_endpoint_entity
SET json = JSON_SET(json, '$.serviceType', 'Rest')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'REST';
-- Update serviceType in api_service_entity table
UPDATE api_service_entity
SET json = JSON_SET(json, '$.serviceType', 'Rest')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'REST';
-- Update serviceType in api_collection_entity table
UPDATE api_collection_entity
SET json = JSON_SET(json, '$.serviceType', 'Rest')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'REST';
ALTER TABLE apps_extension_time_series ADD COLUMN appName VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.appName') STORED NOT NULL;

View File

@ -59,19 +59,4 @@ SET json = jsonb_set(
)
where name = 'SearchIndexingApplication';
ALTER TABLE apps_extension_time_series ADD COLUMN appName VARCHAR(256) GENERATED ALWAYS AS (json ->> 'appName') STORED NOT NULL;
-- Update serviceType in api_endpoint_entity table
UPDATE api_endpoint_entity
SET json = jsonb_set(json, '{serviceType}', '"Rest"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'REST';
-- Update serviceType in api_service_entity table
UPDATE api_service_entity
SET json = jsonb_set(json, '{serviceType}', '"Rest"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'REST';
-- Update serviceType in api_collection_entity table
UPDATE api_collection_entity
SET json = jsonb_set(json, '{serviceType}', '"Rest"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'REST';
ALTER TABLE apps_extension_time_series ADD COLUMN appName VARCHAR(256) GENERATED ALWAYS AS (json ->> 'appName') STORED NOT NULL;

View File

@ -1,6 +1,7 @@
package org.openmetadata.service.migration.mysql.v160;
import static org.openmetadata.service.migration.utils.v160.MigrationUtil.addAppExtensionName;
import static org.openmetadata.service.migration.utils.v160.MigrationUtil.migrateServiceTypesAndConnections;
import lombok.SneakyThrows;
import org.openmetadata.service.migration.api.MigrationProcessImpl;
@ -16,5 +17,6 @@ public class Migration extends MigrationProcessImpl {
@SneakyThrows
public void runDataMigration() {
addAppExtensionName(handle, collectionDAO, authenticationConfiguration, false);
migrateServiceTypesAndConnections(handle, false);
}
}

View File

@ -1,6 +1,7 @@
package org.openmetadata.service.migration.postgres.v160;
import static org.openmetadata.service.migration.utils.v160.MigrationUtil.addAppExtensionName;
import static org.openmetadata.service.migration.utils.v160.MigrationUtil.migrateServiceTypesAndConnections;
import lombok.SneakyThrows;
import org.openmetadata.service.migration.api.MigrationProcessImpl;
@ -16,5 +17,6 @@ public class Migration extends MigrationProcessImpl {
@SneakyThrows
public void runDataMigration() {
addAppExtensionName(handle, collectionDAO, authenticationConfiguration, true);
migrateServiceTypesAndConnections(handle, true);
}
}

View File

@ -80,4 +80,94 @@ public class MigrationUtil {
}
update.bind("appId", app.getId().toString()).bind("appName", app.getName()).execute();
}
public static void migrateServiceTypesAndConnections(Handle handle, boolean postgresql) {
LOG.info("Starting service type and connection type migrations");
try {
migrateServiceTypeInApiEndPointServiceType(handle, postgresql);
migrateServiceTypeInApiServiceEntity(handle, postgresql);
migrateConnectionTypeInApiServiceEntity(handle, postgresql);
migrateServiceTypeInApiCollectionEntity(handle, postgresql);
LOG.info("Successfully completed service type and connection type migrations");
} catch (Exception e) {
LOG.error("Error occurred during migration", e);
}
}
private static void migrateServiceTypeInApiEndPointServiceType(
Handle handle, boolean postgresql) {
LOG.info("Starting migrateServiceTypeInApiEndPointServiceType");
String query;
if (postgresql) {
query =
"UPDATE api_endpoint_entity SET json = jsonb_set(json, '{serviceType}', '\"Rest\"', false) WHERE jsonb_extract_path_text(json, 'serviceType') = 'REST'";
} else {
query =
"UPDATE api_endpoint_entity SET json = JSON_SET(json, '$.serviceType', 'Rest') WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'REST'";
}
try {
handle.execute(query);
} catch (Exception e) {
LOG.error("Error updating", e);
}
}
private static void migrateServiceTypeInApiServiceEntity(Handle handle, boolean postgresql) {
LOG.info("Starting migrateServiceTypeInApiServiceEntity");
String query;
if (postgresql) {
query =
"UPDATE api_service_entity SET json = jsonb_set(json, '{serviceType}', '\"Rest\"', false) WHERE jsonb_extract_path_text(json, 'serviceType') = 'REST'";
} else {
query =
"UPDATE api_service_entity SET json = JSON_SET(json, '$.serviceType', 'Rest') WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'REST'";
}
try {
handle.execute(query);
} catch (Exception e) {
LOG.error("Error updating", e);
}
}
private static void migrateServiceTypeInApiCollectionEntity(Handle handle, boolean postgresql) {
LOG.info("Starting runApiCollectionEntityServiceTypeDataMigrations");
String query;
if (postgresql) {
query =
"UPDATE api_collection_entity SET json = jsonb_set(json, '{serviceType}', '\"Rest\"', false) WHERE jsonb_extract_path_text(json, 'serviceType') = 'REST'";
} else {
query =
"UPDATE api_collection_entity SET json = JSON_SET(json, '$.serviceType', 'Rest') WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'REST'";
}
try {
handle.execute(query);
} catch (Exception e) {
LOG.error("Error updating", e);
}
}
private static void migrateConnectionTypeInApiServiceEntity(Handle handle, boolean postgresql) {
LOG.info("Starting runApiServiceEntityConnectionTypeMigrate");
String query;
if (postgresql) {
query =
"UPDATE api_service_entity SET json = jsonb_set(json, '{connection,config,type}', '\"Rest\"', false) WHERE jsonb_extract_path_text(json, 'connection', 'config', 'type') = 'REST'";
} else {
query =
"UPDATE api_service_entity SET json = JSON_SET(json, '$.connection.config.type', 'Rest') WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.connection.config.type')) = 'REST'";
}
try {
handle.execute(query);
} catch (Exception e) {
LOG.error("Error updating", e);
}
}
}