-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS roadmap_sync_steps (
    id                       BIGSERIAL    PRIMARY KEY,
    roadmap_sync_identity_id BIGINT       NOT NULL REFERENCES roadmap_sync_identities(id) ON DELETE CASCADE,
    step                     TEXT         NOT NULL,
    completed_at             TIMESTAMPTZ  NOT NULL DEFAULT now(),
    CONSTRAINT roadmap_sync_steps_step_check
        CHECK (step IN ('develop_matched', 'original_comment_preserved', 'plane_body_updated', 'plane_todo_moved'))
);

-- Each identity records a given step at most once, so re-applying a completed
-- step is idempotent rather than appending a duplicate ledger row.
CREATE UNIQUE INDEX ux_roadmap_sync_steps_identity_step
    ON roadmap_sync_steps (roadmap_sync_identity_id, step);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS roadmap_sync_steps;
-- +goose StatementEnd
