Skip to content
Merged
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
2 changes: 1 addition & 1 deletion server/controller/db/metadb/migrator/schema/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ const (
RAW_SQL_ROOT_DIR = "/etc/metadb/schema/rawsql"

DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.6.1.67"
DB_VERSION_EXPECTED = "6.6.1.68"
)
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,8 @@ CREATE TABLE IF NOT EXISTS pod_group (
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME DEFAULT NULL,
INDEX pod_namespace_id_index(pod_namespace_id),
INDEX pod_cluster_id_index(pod_cluster_id)
INDEX pod_cluster_id_index(pod_cluster_id),
INDEX lcuuid_index(lcuuid)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE pod_group;

Expand All @@ -1138,7 +1139,8 @@ CREATE TABLE IF NOT EXISTS pod_group_port (
domain CHAR(64) DEFAULT '',
lcuuid CHAR(64) DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX lcuuid_index(lcuuid)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE pod_group_port;

Expand Down Expand Up @@ -1198,7 +1200,8 @@ CREATE TABLE IF NOT EXISTS pod (
INDEX epc_id_index(epc_id),
INDEX az_index(az),
INDEX region_index(region),
INDEX domain_index(domain)
INDEX domain_index(domain),
INDEX lcuuid_index(lcuuid)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE pod;

Expand Down Expand Up @@ -1264,7 +1267,8 @@ CREATE TABLE IF NOT EXISTS process (
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 deleted_at_index(deleted_at)
INDEX deleted_at_index(deleted_at),
INDEX lcuuid_index(lcuuid)
) ENGINE=innodb DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
TRUNCATE TABLE process;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
DROP PROCEDURE IF EXISTS AddIndexIfNotExists;

CREATE PROCEDURE AddIndexIfNotExists(
IN tableName VARCHAR(255),
IN indexName VARCHAR(255),
IN indexCol VARCHAR(255)
)
BEGIN
DECLARE index_count INT;

-- check if index exists on the target column (regardless of index name)
SELECT COUNT(*)
INTO index_count
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = tableName
AND column_name = indexCol;

-- if no index on this column, add index
IF index_count = 0 THEN
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD INDEX ', indexName, ' (', indexCol, ') USING BTREE');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddIndexIfNotExists('pod', 'lcuuid_index', 'lcuuid');
CALL AddIndexIfNotExists('pod_group', 'lcuuid_index', 'lcuuid');
CALL AddIndexIfNotExists('pod_group_port', 'lcuuid_index', 'lcuuid');
CALL AddIndexIfNotExists('process', 'lcuuid_index', 'lcuuid');

DROP PROCEDURE AddIndexIfNotExists;

UPDATE db_version SET version='6.6.1.68';
Loading