ALTER TABLE survey_modes
    ADD COLUMN IF NOT EXISTS source VARCHAR(20) NOT NULL DEFAULT 'USER';

ALTER TABLE survey_modes
    DROP CONSTRAINT IF EXISTS chk_survey_modes_source;

CREATE TABLE IF NOT EXISTS mode_booking (
    id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    mode_id BIGINT NOT NULL REFERENCES survey_modes(id) ON DELETE CASCADE,
    slot_id BIGINT NOT NULL,
    CONSTRAINT uq_mode_booking_mode_slot UNIQUE(mode_id, slot_id)
);

CREATE INDEX IF NOT EXISTS idx_mode_booking_mode_id ON mode_booking(mode_id);
CREATE INDEX IF NOT EXISTS idx_mode_booking_slot_id ON mode_booking(slot_id);
