From 3b8d7d186245b5fa0fb4d90c5c4146b993f30271 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 22 Dec 2025 08:44:53 -0500 Subject: [PATCH 1/3] Protect upgrades from failures --- .../cloud.idempotent_drop_column.sql | 31 +++++++++++++++++++ .../META-INF/db/schema-42010to42100.sql | 8 ++--- 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql diff --git a/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql b/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql new file mode 100644 index 000000000000..f8bbff143c15 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql @@ -0,0 +1,31 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_COLUMN`; + +CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_COLUMN` ( + IN in_table_name VARCHAR(200), + IN in_column_name VARCHAR(200) +) +BEGIN + DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; -- Error 1091: Can't DROP column; check that column/key exists + SET @stmt = CONCAT('ALTER TABLE ', in_table_name, ' DROP COLUMN ', in_column_name); + PREPARE stmt FROM @stmt; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; +END; + diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql b/engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql index 167dd92730cc..4c65f37e0fe0 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql @@ -301,7 +301,7 @@ CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.service_offering','fk_service_ CALL `cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY`('cloud.service_offering', 'fk_service_offering__vgpu_profile_id', '(vgpu_profile_id)', '`vgpu_profile`(`id`)'); -- Netris Plugin -CREATE TABLE `cloud`.`netris_providers` ( +CREATE TABLE IF NOT EXISTS `cloud`.`netris_providers` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `uuid` varchar(40), `zone_id` bigint unsigned NOT NULL COMMENT 'Zone ID', @@ -321,11 +321,11 @@ CREATE TABLE `cloud`.`netris_providers` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Drop the Tungsten and NSX columns from the network offerings (replaced by checking the provider on the ntwk_offering_service_map table) -ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `for_tungsten`; -ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `for_nsx`; +CALL `cloud`.`IDEMPOTENT_DROP_COLUMN`('cloud.network_offerings', 'for_tungsten'); +CALL `cloud`.`IDEMPOTENT_DROP_COLUMN`('cloud.network_offerings', 'for_nsx'); -- Drop the Tungsten and NSX columns from the VPC offerings (replaced by checking the provider on the vpc_offering_service_map table) -ALTER TABLE `cloud`.`vpc_offerings` DROP COLUMN `for_nsx`; +CALL `cloud`.`IDEMPOTENT_DROP_COLUMN`('cloud.vpc_offerings', 'for_nsx'); -- Add next_hop to the static_routes table CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.static_routes', 'next_hop', 'varchar(50) COMMENT "next hop of the static route" AFTER `vpc_gateway_id`'); From a6e3d3bd2a30aee6b28e1d3abae2d748427acc43 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 22 Dec 2025 09:00:47 -0500 Subject: [PATCH 2/3] remove newline --- .../META-INF/db/procedures/cloud.idempotent_drop_column.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql b/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql index f8bbff143c15..a8d056729ad2 100644 --- a/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql +++ b/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql @@ -28,4 +28,3 @@ BEGIN EXECUTE stmt; DEALLOCATE PREPARE stmt; END; - From df31ec8fb8e7ec48bad2430a76159609366ee2af Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 23 Dec 2025 12:36:08 -0500 Subject: [PATCH 3/3] fix syntax --- .../db/procedures/cloud.idempotent_drop_column.sql | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql b/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql index a8d056729ad2..31d5b9f500f0 100644 --- a/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql +++ b/engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_drop_column.sql @@ -15,16 +15,14 @@ -- specific language governing permissions and limitations -- under the License. +-- in cloud DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_COLUMN`; +-- Error 1091: Can't DROP column; check that column/key exists CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_COLUMN` ( IN in_table_name VARCHAR(200), IN in_column_name VARCHAR(200) ) BEGIN - DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; -- Error 1091: Can't DROP column; check that column/key exists - SET @stmt = CONCAT('ALTER TABLE ', in_table_name, ' DROP COLUMN ', in_column_name); - PREPARE stmt FROM @stmt; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; -END; + + DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name, ' DROP COLUMN ', in_column_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;