Skip to content

Commit 7a1e54d

Browse files
committed
drop unique key only if it exists
1 parent fdb9a71 commit 7a1e54d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

engine/schema/src/main/resources/META-INF/db/schema-41910to41920.sql

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,20 @@
2222
-- Add last_id to the volumes table
2323
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'last_id', 'bigint(20) unsigned DEFAULT NULL');
2424

25-
ALTER TABLE `cloud`.`counter` DROP KEY `uc_counter__provider__source__value`;
26-
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.counter', 'uc_counter__provider__source__value_removed', '(provider, source, value, removed)');
25+
SELECT
26+
COUNT(*)
27+
INTO @exists
28+
FROM information_schema.STATISTICS
29+
WHERE TABLE_SCHEMA = 'cloud'
30+
AND TABLE_NAME = 'counter'
31+
AND INDEX_NAME = 'uc_counter__provider__source__value';
32+
33+
-- Drop the key if it exists
34+
SET @sql = IF(@exists > 0, 'ALTER TABLE counter DROP KEY uc_counter__provider__source__value', NULL);
35+
36+
-- Execute the drop statement if the index exists
37+
PREPARE stmt FROM @sql;
38+
EXECUTE stmt;
39+
DEALLOCATE PREPARE stmt;
40+
41+
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.counter', 'uc_counter__provider__source__value__removed', '(provider, source, value, removed)');

0 commit comments

Comments
 (0)