Move Plan Revision From Scheduling Spec to Scheduling RQ
Follow-up to #971.
Summary taken from "Future Work" of #1141:
As mentioned in #971, part of the reason the bug was occurring was due to the structure of this part of the DB. The plan's revision, which should be part of scheduling_request, is instead on scheduling_specification. This means that the UI has to update the scheduling spec before it hits the schedule endpoint, which updates the specs revision, which allows for a duplicate request to be created (since the PK is currently (spec_id, spec_revision)).
The correct design is to have plan_revision be on scheduling_request, as well as other changes to synchronize the design of the scheduling rq and sim rq tables. This is not possible, however, because plan revision data is stored in the Merlin DB. There are a few solutions possible:
- Merge the Databases. We can then grant the scheduler read permission on the
plantable and it can properly fetch the plan's revision in the same way that sim rqs fetch revisions. - Create GraphQL requests in the Scheduler Server. This would require adding in additional envvars to the scheduler server container, and potentially duplicating some code from the
scheduler-driverpackage. Additionally, the place this GQL request would be made would be in the middle of a section of code that is reading from and then writing to Postgres inCachedSchedulerService. - Have the Scheduler Server exclusively use GQL requests. This would entirely alleviate the awkwardness of (2), while very likely being more work. Additionally, it would be odd that one container is not able to interact directly with a database that it owns.
As of April 2025, we have:
- merged the DBs and given the scheduler
readpermission on theplantable - added
plan_revisionto thescheduling_request - improved the primary key of the
scheduling_requesttable, and further improved the problematicuniqueconstraint of(spec_id, spec_revision)to(specification_id, specification_revision, plan_revision), removing the dependency on needing to update the spec to avoid duplicate requests.
Work to do:
- update the Schedule Server's
scheduleendpoint to fetch the plan revision data. It still currently uses the one on the scheduling specification. Specifically:ScheduleRequestshould haveplan_revisionadded to it, andSpecificationRevisionDatashould haveplan_revisionremoved.ScheduleAction::runshould add a method to get the plan revision data and use that value, similar to howGetSimulationResultsAction::runcallsthis.planService.getPlanRevisionData(planId)
- remove the column
plan_revisionfromscheduling_specification - update the UI to not update the
plan_revisionon the scheduling spec before calling thescheduleHasura Action- update the E2E Scheduling Tests that schedule more than once in the same way