"""
Table for import jobs
"""

from yoyo import step

__depends__ = {'20231119_00_ASHrR6-fix-revisions-table-to-match-tags-type'}

steps = [
    step("""
CREATE TABLE jobs (
    job_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    queue_name TEXT NOT NULL,
    priority INTEGER NOT NULL,
    consumer_id TEXT,
    pids INTEGER[],
    started_at TIMESTAMP,
    last_heartbeat_at TIMESTAMP,
    job_input JSONB not NULL,
    job_status JSONB DEFAULT '{}'::jsonb,
    finished_at TIMESTAMP,
    error TEXT
);

CREATE INDEX jobs_finished_at_queue_name_job_input_key_idx ON public.jobs (finished_at, queue_name, (job_input->>'key'));

"""),
]
