Copilot commented on code in PR #12144: URL: https://github.com/apache/cloudstack/pull/12144#discussion_r3552654666
########## engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql: ########## @@ -19,6 +19,21 @@ -- Schema upgrade from 4.22.1.0 to 4.23.0.0 --; +CREATE TABLE IF NOT EXISTS `cloud`.`service_offering_category` ( + `id` bigint unsigned NOT NULL auto_increment, + `name` varchar(255) NOT NULL, + `uuid` varchar(40), + `sort_key` int NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + CONSTRAINT `uc_service_offering_category__uuid` UNIQUE (`uuid`), + CONSTRAINT `uc_service_offering_category__name` UNIQUE (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + +INSERT INTO `cloud`.`service_offering_category` (id, name, uuid) VALUES (1, 'Default', UUID()); + +ALTER TABLE `cloud`.`service_offering` ADD COLUMN `category_id` bigint unsigned NOT NULL DEFAULT 1; +ALTER TABLE `cloud`.`service_offering` ADD CONSTRAINT `fk_service_offering__category_id` FOREIGN KEY (`category_id`) REFERENCES `cloud`.`service_offering_category` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE; Review Comment: The schema upgrade adds a default row and new column/constraint in a way that is not restart-safe: the `INSERT` will fail on reruns (duplicate id/name) and the `ALTER TABLE ... ADD COLUMN` will fail if the upgrade is partially applied and rerun. Make these steps idempotent so the upgrade can be safely retried. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
