BEGIN;

ALTER TABLE laying_transfers
    ADD COLUMN IF NOT EXISTS economic_cutoff_date DATE;

CREATE INDEX IF NOT EXISTS idx_laying_transfers_economic_cutoff_date
    ON laying_transfers(economic_cutoff_date);

UPDATE laying_transfers
SET economic_cutoff_date = COALESCE(economic_cutoff_date, effective_move_date, transfer_date)
WHERE economic_cutoff_date IS NULL;

COMMIT;
