Skip to content

Commit 7647e10

Browse files
ernjvrDaanHoogland
authored andcommitted
CLOUDSTACK-10278 idempotent column addition (#2449)
* CLOUDSTACK-10278 - WIP: need to test this script before create a pull request * CLOUDSTACK-10278 - added more idempotent stored procs and moved all lines, that end with a semicolon in existing proc, onto one line because com/cloud/utils/db/ScriptRunner.java executes the sql as soon as it reads in line with a semicolon delimeter at the end. * CLOUDSTACK-10278 - changed more sql statements to call idempotent stored procs * CLOUDSTACK-10278 - WIP: need to test this script before create a pull request * CLOUDSTACK-10278 - added more idempotent stored procs and moved all lines, that end with a semicolon in existing proc, onto one line because com/cloud/utils/db/ScriptRunner.java executes the sql as soon as it reads in line with a semicolon delimeter at the end. * CLOUDSTACK-10278 - changed more sql statements to call idempotent stored procs
1 parent 986ecfa commit 7647e10

1 file changed

Lines changed: 61 additions & 19 deletions

File tree

engine/schema/resources/META-INF/db/schema-41000to41100.sql

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,54 @@
1919
-- Schema upgrade from 4.10.0.0 to 4.11.0.0
2020
--;
2121

22+
--;
23+
-- Stored procedure to do idempotent column add;
24+
--;
25+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
26+
27+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
28+
IN in_table_name VARCHAR(200)
29+
, IN in_column_name VARCHAR(200)
30+
, IN in_column_definition VARCHAR(1000)
31+
)
32+
BEGIN
33+
34+
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
35+
36+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`;
37+
38+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY` (
39+
IN in_table_name VARCHAR(200)
40+
, IN in_foreign_key_name VARCHAR(200)
41+
)
42+
BEGIN
43+
44+
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' DROP FOREIGN KEY '); SET @ddl = CONCAT(@ddl, ' ', in_foreign_key_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
45+
46+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_INDEX`;
47+
48+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_INDEX` (
49+
IN in_index_name VARCHAR(200)
50+
, IN in_table_name VARCHAR(200)
51+
)
52+
BEGIN
53+
54+
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('DROP INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
55+
56+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX`;
57+
58+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX` (
59+
IN in_index_name VARCHAR(200)
60+
, IN in_table_name VARCHAR(200)
61+
, IN in_index_definition VARCHAR(1000)
62+
)
63+
BEGIN
64+
65+
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('CREATE UNIQUE INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', in_index_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
66+
2267
-- Add For VPC flag
23-
ALTER TABLE cloud.network_offerings ADD COLUMN for_vpc INT(1) NOT NULL DEFAULT 0;
68+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','for_vpc', 'INT(1) NOT NULL DEFAULT 0');
69+
2470
UPDATE cloud.network_offerings o
2571
SET for_vpc = 1
2672
where
@@ -88,7 +134,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`annotations` (
88134
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
89135

90136
DROP VIEW IF EXISTS `cloud`.`last_annotation_view`;
91-
CREATE VIEW `last_annotation_view` AS
137+
CREATE VIEW `cloud`.`last_annotation_view` AS
92138
SELECT
93139
`annotations`.`uuid` AS `uuid`,
94140
`annotations`.`annotation` AS `annotation`,
@@ -405,21 +451,18 @@ UPDATE `cloud`.`monitoring_services` SET pidfile="/var/run/apache2/apache2.pid"
405451
UPDATE `cloud`.`vm_template` SET guest_os_id=99 WHERE id=8;
406452

407453
-- Network External Ids
408-
ALTER TABLE `cloud`.`networks` ADD `external_id` varchar(255);
454+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.networks','external_id', 'varchar(255)');
409455

410456
-- Separate Subnet for CPVM and SSVM (system vms)
411-
ALTER TABLE `cloud`.`op_dc_ip_address_alloc`
412-
ADD COLUMN `forsystemvms` TINYINT(1) NOT NULL DEFAULT '0' COMMENT 'Indicates if IP is dedicated for CPVM or SSVM';
457+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.op_dc_ip_address_alloc','forsystemvms', 'TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''Indicates if IP is dedicated for CPVM or SSVM'' ');
413458

414-
ALTER TABLE `cloud`.`op_dc_ip_address_alloc`
415-
ADD COLUMN `vlan` INT(10) UNSIGNED NULL COMMENT 'Vlan the management network range is on';
459+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.op_dc_ip_address_alloc','vlan', 'INT(10) UNSIGNED NULL COMMENT ''Vlan the management network range is on'' ');
416460

417461
-- CLOUDSTACK-4757: Support multidisk OVA
418-
ALTER TABLE `cloud`.`vm_template` ADD COLUMN `parent_template_id` bigint(20) unsigned DEFAULT NULL COMMENT 'If datadisk template, then id of the root template this template belongs to';
462+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_template','parent_template_id', 'bigint(20) unsigned DEFAULT NULL COMMENT ''If datadisk template, then id of the root template this template belongs to'' ');
419463

420464
-- CLOUDSTACK-10146: Bypass Secondary Storage for KVM templates
421-
ALTER TABLE `cloud`.`vm_template`
422-
ADD COLUMN `direct_download` TINYINT(1) DEFAULT '0' COMMENT 'Indicates if Secondary Storage is bypassed and template is downloaded to Primary Storage';
465+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_template','direct_download', 'TINYINT(1) DEFAULT 0 COMMENT ''Indicates if Secondary Storage is bypassed and template is downloaded to Primary Storage'' ');
423466

424467
-- Changes to template_view for both multidisk OVA and bypass secondary storage for KVM templates
425468
DROP VIEW IF EXISTS `cloud`.`template_view`;
@@ -528,8 +571,7 @@ CREATE VIEW `cloud`.`template_view` AS
528571
OR (`resource_tags`.`resource_type` = 'ISO')))));
529572

530573
-- CLOUDSTACK-10109: Enable dedication of public IPs to SSVM and CPVM
531-
ALTER TABLE `cloud`.`user_ip_address`
532-
ADD COLUMN `forsystemvms` TINYINT(1) NOT NULL DEFAULT '0' COMMENT 'true if IP is set to system vms, false if not';
574+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.user_ip_address','forsystemvms', 'TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''true if IP is set to system vms, false if not'' ');
533575

534576
-- ldap binding on domain level
535577
CREATE TABLE IF NOT EXISTS `cloud`.`domain_details` (
@@ -541,11 +583,11 @@ CREATE TABLE IF NOT EXISTS `cloud`.`domain_details` (
541583
CONSTRAINT `fk_domain_details__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE
542584
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
543585

544-
ALTER TABLE cloud.ldap_configuration ADD COLUMN domain_id BIGINT(20) DEFAULT NULL;
545-
ALTER TABLE cloud.ldap_trust_map ADD COLUMN account_id BIGINT(20) DEFAULT 0;
546-
ALTER TABLE cloud.ldap_trust_map DROP FOREIGN KEY fk_ldap_trust_map__domain_id;
547-
DROP INDEX uk_ldap_trust_map__domain_id ON cloud.ldap_trust_map;
548-
CREATE UNIQUE INDEX uk_ldap_trust_map__bind_location ON ldap_trust_map (domain_id, account_id);
586+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration','domain_id', 'BIGINT(20) DEFAULT NULL');
587+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_trust_map','account_id', 'BIGINT(20) DEFAULT 0');
588+
CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.ldap_trust_map','fk_ldap_trust_map__domain_id');
589+
CALL `cloud`.`IDEMPOTENT_DROP_INDEX`('uk_ldap_trust_map__domain_id','cloud.ldap_trust_map');
590+
CALL `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX`('uk_ldap_trust_map__bind_location','cloud.ldap_trust_map', '(domain_id, account_id)');
549591

550592
CREATE TABLE IF NOT EXISTS `cloud`.`netscaler_servicepackages` (
551593
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
@@ -565,5 +607,5 @@ CREATE TABLE IF NOT EXISTS `cloud`.`external_netscaler_controlcenter` (
565607
PRIMARY KEY (`id`)
566608
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
567609

568-
ALTER TABLE `cloud`.`sslcerts` ADD COLUMN `name` varchar(255) NULL default NULL COMMENT 'Name of the Certificate';
569-
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `service_package_id` varchar(255) NULL default NULL COMMENT 'Netscaler ControlCenter Service Package';
610+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.sslcerts','name', 'varchar(255) NULL default NULL COMMENT ''Name of the Certificate'' ');
611+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','service_package_id', 'varchar(255) NULL default NULL COMMENT ''Netscaler ControlCenter Service Package'' ');

0 commit comments

Comments
 (0)