Copilot commented on code in PR #14490:
URL: https://github.com/apache/cloudstack/pull/14490#discussion_r4359537150
##########
engine/schema/src/main/resources/META-INF/db/schema-42300to2400.sql:
##########
@@ -239,3 +239,12 @@ CREATE TABLE IF NOT EXISTS
`cloud`.`instance_boot_group_details` (
PRIMARY KEY (`id`),
CONSTRAINT `fk_instance_boot_group_details__group_id` FOREIGN KEY
(`boot_group_id`) REFERENCES `instance_boot_group` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--- Add existing cross zone templates to the missing edge zones
Review Comment:
`---` is not a valid MySQL comment start (MySQL requires `-- ` with a space
after the two dashes, or `/* ... */`). As written, this line can cause a syntax
error when the migration runs. Change it to `-- Add existing cross zone
templates to the missing edge zones` (note the space) or use a block comment.
##########
engine/schema/src/main/resources/META-INF/db/schema-42300to2400.sql:
##########
@@ -239,3 +239,12 @@ CREATE TABLE IF NOT EXISTS
`cloud`.`instance_boot_group_details` (
PRIMARY KEY (`id`),
CONSTRAINT `fk_instance_boot_group_details__group_id` FOREIGN KEY
(`boot_group_id`) REFERENCES `instance_boot_group` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--- Add existing cross zone templates to the missing edge zones
+INSERT INTO cloud.template_zone_ref (zone_id, template_id, created,
last_updated)
+SELECT dc.id, vt.id, NOW(), NOW()
+FROM cloud.data_center dc
+JOIN cloud.vm_template vt ON vt.cross_zones = 1 AND vt.removed IS NULL
+WHERE dc.type = 'Edge' AND dc.removed IS NULL
+ AND NOT EXISTS (SELECT 1 FROM cloud.template_zone_ref tzr
+ WHERE tzr.zone_id = dc.id AND tzr.template_id = vt.id AND
tzr.removed IS NULL);
Review Comment:
The correlated `NOT EXISTS` subquery can be more expensive on large datasets
because it is evaluated per (zone, template) pair. Consider rewriting as a
`LEFT JOIN` to `template_zone_ref` with `WHERE tzr.template_id IS NULL` (and/or
ensuring there’s an index covering `(zone_id, template_id, removed)`) to
improve migration runtime on bigger installations.
##########
engine/schema/src/main/resources/META-INF/db/schema-42300to2400.sql:
##########
@@ -239,3 +239,12 @@ CREATE TABLE IF NOT EXISTS
`cloud`.`instance_boot_group_details` (
PRIMARY KEY (`id`),
CONSTRAINT `fk_instance_boot_group_details__group_id` FOREIGN KEY
(`boot_group_id`) REFERENCES `instance_boot_group` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--- Add existing cross zone templates to the missing edge zones
+INSERT INTO cloud.template_zone_ref (zone_id, template_id, created,
last_updated)
+SELECT dc.id, vt.id, NOW(), NOW()
Review Comment:
Using `NOW()` makes the inserted timestamps depend on the DB server/session
timezone. If the rest of the schema/migrations standardize on UTC timestamps
(common in CloudStack DB code), prefer `UTC_TIMESTAMP()` for
`created`/`last_updated` to keep data consistent across deployments.
--
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]