-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f29a56
commit aa2bd38
Showing
4 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
server/controller/db/metadb/migrator/schema/rawsql/mysql/issu/7.0.1.10.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
DROP PROCEDURE IF EXISTS AddColumnIfNotExists; | ||
|
||
CREATE PROCEDURE AddColumnIfNotExists( | ||
IN tableName VARCHAR(255), | ||
IN colName VARCHAR(255), | ||
IN colType VARCHAR(255), | ||
IN afterCol VARCHAR(255) | ||
) | ||
BEGIN | ||
DECLARE column_count INT; | ||
|
||
SELECT COUNT(*) | ||
INTO column_count | ||
FROM information_schema.columns | ||
WHERE TABLE_SCHEMA = DATABASE() | ||
AND TABLE_NAME = tableName | ||
AND column_name = colName; | ||
|
||
IF column_count = 0 THEN | ||
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD COLUMN ', colName, ' ', colType, ' AFTER ', afterCol); | ||
PREPARE stmt FROM @sql; | ||
EXECUTE stmt; | ||
DEALLOCATE PREPARE stmt; | ||
END IF; | ||
END; | ||
|
||
CALL AddColumnIfNotExists('data_source', 'query_time', "INTEGER NOT NULL COMMENT 'uint: minute'", 'retention_time'); | ||
|
||
DROP PROCEDURE AddColumnIfNotExists; | ||
|
||
DROP PROCEDURE IF EXISTS UpdateQueryTime; | ||
|
||
CREATE PROCEDURE UpdateQueryTime( | ||
IN tableName VARCHAR(255) | ||
) | ||
BEGIN | ||
-- 动态生成并执行 UPDATE 语句 | ||
SET @update_sql = CONCAT( | ||
'UPDATE data_source ', | ||
'SET query_time = 3600 ', | ||
'WHERE data_table_collection = "', tableName, '"' | ||
); | ||
|
||
-- 准备并执行动态 SQL | ||
PREPARE stmt FROM @update_sql; | ||
EXECUTE stmt; | ||
DEALLOCATE PREPARE stmt; | ||
END; | ||
|
||
-- 调用存储过程 | ||
CALL UpdateQueryTime('flow_log.l4_flow_log'); | ||
CALL UpdateQueryTime('flow_log.l7_flow_log'); | ||
CALL UpdateQueryTime('application_log.log'); | ||
|
||
DROP PROCEDURE UpdateQueryTime; | ||
|
||
UPDATE db_version SET version='7.0.1.10'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters