bmc_hub/migrations/1018_economy_time_queue_settlement.sql
2026-08-25 01:09:45 +02:00

18 lines
864 B
SQL

-- Migration 1018: Preserve a trace from Economy Time Queue to the local order draft.
-- A time entry must leave the queue when a local draft has been created, while
-- still remaining available to the separate order/export workflow.
ALTER TABLE tmodule_times
ADD COLUMN IF NOT EXISTS economy_order_draft_id INTEGER
REFERENCES ordre_drafts(id) ON DELETE SET NULL,
ADD COLUMN IF NOT EXISTS economy_settled_at TIMESTAMP,
ADD COLUMN IF NOT EXISTS economy_settled_by INTEGER
REFERENCES users(user_id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_tmodule_times_economy_order_draft
ON tmodule_times(economy_order_draft_id)
WHERE economy_order_draft_id IS NOT NULL;
COMMENT ON COLUMN tmodule_times.economy_order_draft_id IS
'Local ordrekladde created by Economy Time Queue. Prevents a duplicate draft for the same time.';