From fc40bde3338669059419a745e5d4e460c5ce24ff Mon Sep 17 00:00:00 2001 From: Theresa Kamerman Date: Wed, 17 Apr 2024 16:03:55 -0700 Subject: [PATCH] Add "order by" when populating a plan spec Avoids temporary priority gaps when initially populating the spec, which will cause a constraint violation --- .../merge_aerie_db/merge_db/migrate_scheduler_triggers.sql | 3 ++- .../scheduling_specification/scheduling_specification.sql | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/deployment/merge_aerie_db/merge_db/migrate_scheduler_triggers.sql b/deployment/merge_aerie_db/merge_db/migrate_scheduler_triggers.sql index 551e5e655e..94323d7c3b 100644 --- a/deployment/merge_aerie_db/merge_db/migrate_scheduler_triggers.sql +++ b/deployment/merge_aerie_db/merge_db/migrate_scheduler_triggers.sql @@ -38,7 +38,8 @@ begin insert into scheduler.scheduling_specification_goals (specification_id, goal_id, goal_revision, priority) select spec_id, msg.goal_id, msg.goal_revision, msg.priority from scheduler.scheduling_model_specification_goals msg - where msg.model_id = new.model_id; + where msg.model_id = new.model_id + order by msg.priority; insert into scheduler.scheduling_specification_conditions (specification_id, condition_id, condition_revision) select spec_id, msc.condition_id, msc.condition_revision diff --git a/deployment/postgres-init-db/sql/tables/scheduler/scheduling_specification/scheduling_specification.sql b/deployment/postgres-init-db/sql/tables/scheduler/scheduling_specification/scheduling_specification.sql index f84078cfff..c402c21fee 100644 --- a/deployment/postgres-init-db/sql/tables/scheduler/scheduling_specification/scheduling_specification.sql +++ b/deployment/postgres-init-db/sql/tables/scheduler/scheduling_specification/scheduling_specification.sql @@ -53,7 +53,8 @@ begin insert into scheduler.scheduling_specification_goals (specification_id, goal_id, goal_revision, priority) select spec_id, msg.goal_id, msg.goal_revision, msg.priority from scheduler.scheduling_model_specification_goals msg - where msg.model_id = new.model_id; + where msg.model_id = new.model_id + order by msg.priority; insert into scheduler.scheduling_specification_conditions (specification_id, condition_id, condition_revision) select spec_id, msc.condition_id, msc.condition_revision