CREATE TABLE jobs
(
    id            UUID PRIMARY KEY,
    type          VARCHAR(50)              NOT NULL,
    status        VARCHAR(50)              NOT NULL,
    project_id    UUID                     NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
    binary_id     UUID                     NOT NULL REFERENCES binaries (id) ON DELETE CASCADE,
    payload       jsonb,
    result        jsonb,
    error_message TEXT,
    retry_count   INTEGER                  NOT NULL DEFAULT 0,
    created_at    TIMESTAMP WITH TIME ZONE NOT NULL,
    updated_at    TIMESTAMP WITH TIME ZONE NOT NULL
);

CREATE INDEX idx_jobs_project_id ON jobs (project_id);
CREATE INDEX idx_jobs_status ON jobs (status);
CREATE INDEX idx_jobs_type ON jobs (type);
