-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS project_sync_settings (
    id                BIGSERIAL PRIMARY KEY,
    provider          TEXT          NOT NULL,
    tenant            TEXT          NOT NULL,
    project           TEXT          NOT NULL,
    git_remote_url    TEXT          NOT NULL,
    source_branch     TEXT          NOT NULL,
    workspace_id      TEXT          NOT NULL,
    workspace_base_path TEXT        NOT NULL,
    repo_dir_name     TEXT          NOT NULL,
    active            BOOLEAN       NOT NULL DEFAULT TRUE,
    created_at        TIMESTAMPTZ   NOT NULL DEFAULT now(),
    updated_at        TIMESTAMPTZ   NOT NULL DEFAULT now()
);

-- Each provider/tenant/project combo has at most one active config.
CREATE UNIQUE INDEX ux_project_sync_active
    ON project_sync_settings (provider, tenant, project)
    WHERE active = TRUE;
-- +goose StatementEnd

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