Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ CREATE TABLE IF NOT EXISTS process (
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME DEFAULT NULL,
INDEX domain_sub_domain_gid_updated_at_index(domain, sub_domain, gid, updated_at DESC),
INDEX domain_sub_domain_gid_updated_at_index(domain, sub_domain, gid, updated_at),
INDEX deleted_at_index(deleted_at),
INDEX lcuuid_index(lcuuid),
INDEX vtap_id_index(vtap_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ BEGIN
END IF;
END;

CALL AddIndexIfNotExists('process', 'domain_sub_domain_gid_updated_at_index', 'domain, sub_domain, gid, updated_at DESC');
CALL AddIndexIfNotExists('process', 'domain_sub_domain_gid_updated_at_index', 'domain, sub_domain, gid, updated_at');
CALL AddIndexIfNotExists('ch_chost_cloud_tag', 'domain_id_updated_at_index', 'domain_id, id, updated_at ASC');
CALL AddIndexIfNotExists('ch_pod_ns_cloud_tag', 'domain_sub_domain_id_updated_at_index', 'domain_id, sub_domain_id, id, updated_at ASC');
CALL AddIndexIfNotExists('ch_pod_service_k8s_label', 'domain_sub_domain_id_updated_at_index', 'domain_id, sub_domain_id, id, updated_at ASC');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,55 @@ CREATE PROCEDURE ChangeColumnIfExists(
IN tableName VARCHAR(255),
IN oldColName VARCHAR(255),
IN newColName VARCHAR(255),
IN colType VARCHAR(255)
IN colType VARCHAR(255),
OUT p_renamed TINYINT(1)
)
BEGIN
CALL ColumnExists(tableName, oldColName, @exists);
IF @exists THEN
SET p_renamed = 0;
CALL ColumnExists(tableName, oldColName, @old_exists);
CALL ColumnExists(tableName, newColName, @new_exists);
IF @old_exists AND NOT @new_exists THEN
SET @sql = CONCAT('ALTER TABLE ', tableName, ' CHANGE ', oldColName, ' ', newColName, ' ', colType);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET p_renamed = 1;
END IF;
END;

CALL ChangeColumnIfExists('custom_service', 'epc_id', 'epc_id_bak', 'INTEGER DEFAULT 0');
CALL ChangeColumnIfExists('custom_service', 'pod_cluster_id', 'pod_cluster_id_bak', 'INTEGER DEFAULT 0');
CALL ChangeColumnIfExists('custom_service', 'pod_namespace_id', 'pod_namespace_id_bak', 'INTEGER DEFAULT 0');
CALL ChangeColumnIfExists('custom_service', 'resource', 'resources', 'TEXT COMMENT "separated by ,"');
CALL ChangeColumnIfExists('custom_service', 'epc_id', 'epc_id_bak', 'INTEGER DEFAULT 0', @epc_renamed);
CALL ChangeColumnIfExists('custom_service', 'pod_cluster_id', 'pod_cluster_id_bak', 'INTEGER DEFAULT 0', @pod_cluster_renamed);
CALL ChangeColumnIfExists('custom_service', 'pod_namespace_id', 'pod_namespace_id_bak', 'INTEGER DEFAULT 0', @pod_ns_renamed);
CALL ChangeColumnIfExists('custom_service', 'resource', 'resources', 'TEXT COMMENT "separated by ,"', @resources_renamed);

-- MigrateData
DROP PROCEDURE IF EXISTS MigrateData;

CREATE PROCEDURE MigrateData(
IN tableName VARCHAR(255),
IN sourceColName VARCHAR(255),
IN targetColName VARCHAR(255)
IN targetColName VARCHAR(255),
IN shouldMigrate TINYINT(1)
)
BEGIN
CALL ColumnExists(tableName, sourceColName, @source_exists);
CALL ColumnExists(tableName, targetColName, @target_exists);
IF @source_exists AND @target_exists THEN
SET @sql = CONCAT('UPDATE ', tableName, ' SET ', targetColName, ' = ', sourceColName, ' WHERE ', sourceColName, ' > 0 AND (', targetColName, ' IS NULL OR ', targetColName, ' = "")');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = CONCAT('UPDATE ', tableName, ' SET ', targetColName, ' = "" WHERE ', sourceColName, ' = 0 AND (', targetColName, ' IS NULL OR ', targetColName, ' = "")');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
IF shouldMigrate THEN
CALL ColumnExists(tableName, sourceColName, @source_exists);
CALL ColumnExists(tableName, targetColName, @target_exists);
IF @source_exists AND @target_exists THEN
SET @sql = CONCAT('UPDATE ', tableName, ' SET ', targetColName, ' = ', sourceColName, ' WHERE ', sourceColName, ' > 0 AND (', targetColName, ' IS NULL OR ', targetColName, ' = "")');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = CONCAT('UPDATE ', tableName, ' SET ', targetColName, ' = "" WHERE ', sourceColName, ' = 0 AND (', targetColName, ' IS NULL OR ', targetColName, ' = "")');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END IF;
END;
CALL MigrateData('custom_service', 'epc_id_bak', 'epc_ids');
CALL MigrateData('custom_service', 'pod_cluster_id_bak', 'pod_cluster_ids');
CALL MigrateData('custom_service', 'pod_namespace_id_bak', 'pod_namespace_ids');
CALL MigrateData('custom_service', 'epc_id_bak', 'epc_ids', @epc_renamed);
CALL MigrateData('custom_service', 'pod_cluster_id_bak', 'pod_cluster_ids', @pod_cluster_renamed);
CALL MigrateData('custom_service', 'pod_namespace_id_bak', 'pod_namespace_ids', @pod_ns_renamed);

-- Cleanup
DROP PROCEDURE IF EXISTS ColumnExists;
Expand Down
Loading