CREATE TABLE campaigns (
    id              UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    repository_id   UUID NOT NULL REFERENCES repositories(id),
    name            TEXT NOT NULL,
    type            TEXT NOT NULL,
    status          TEXT NOT NULL DEFAULT 'running',
    started_at      TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    finished_at     TIMESTAMPTZ,
    tags            JSONB DEFAULT '{}',
    metadata        JSONB DEFAULT '{}',
    created_at      TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_campaigns_repo ON campaigns (repository_id);
CREATE INDEX idx_campaigns_status ON campaigns (status);

ALTER TABLE artifacts ADD COLUMN campaign_id UUID REFERENCES campaigns(id);
CREATE INDEX idx_artifacts_campaign ON artifacts (campaign_id);
