Files
fm_be/migrations/20260609_fix_duty_roster_crews_fk.sql
2026-07-16 22:16:45 +07:00

34 lines
1.0 KiB
SQL

-- +goose Up
-- Rewire crew FK to point at duty_rosters.
ALTER TABLE duty_roster_crews
DROP FOREIGN KEY fk_hems_duty_rosters_crews,
ADD CONSTRAINT fk_duty_roster_crews_roster
FOREIGN KEY (roster_id) REFERENCES duty_rosters(id)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE duty_roster_other_persons
DROP FOREIGN KEY fk_duty_roster_other_persons_roster,
ADD CONSTRAINT fk_duty_roster_other_persons_roster
FOREIGN KEY (roster_id) REFERENCES duty_rosters(id)
ON DELETE CASCADE
ON UPDATE CASCADE;
-- +goose Down
-- Restore crew FK back to the legacy table.
ALTER TABLE duty_roster_crews
DROP FOREIGN KEY fk_duty_roster_crews_roster,
ADD CONSTRAINT fk_hems_duty_rosters_crews
FOREIGN KEY (roster_id) REFERENCES hems_duty_rosters(id)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE duty_roster_other_persons
DROP FOREIGN KEY fk_duty_roster_other_persons_roster,
ADD CONSTRAINT fk_duty_roster_other_persons_roster
FOREIGN KEY (roster_id) REFERENCES hems_duty_rosters(id)
ON DELETE CASCADE
ON UPDATE CASCADE;