-- Stocklist import background jobs
-- Drop: DROP TABLE stocklists.stocklist_import_jobs;

CREATE TABLE stocklists.stocklist_import_jobs
(
    job_id           uuid         NOT NULL PRIMARY KEY,
    status           varchar(50),          -- Created | Started | Running | Complete | Error
    stocklist_id     integer,
    file_id          varchar(32),          -- public.file_uploads.file_id (hex, no extension)
    file_name        varchar(200),         -- safe filename (hex.ext)
    file_upload_id   bigint,               -- public.file_uploads.id
    progress         integer      DEFAULT 0,
    message          text,
    total_rows       integer,
    processed_rows   integer,
    matched_rows     integer,
    unmatched_rows   integer,
    rows_inserted    integer,
    batch_id         varchar(60),
    error_message    text,
    created_at       timestamp,
    started_at       timestamp,
    completed_at     timestamp,
    created_user_id  integer
);

ALTER TABLE stocklists.stocklist_import_jobs OWNER TO postgres;

CREATE INDEX stocklist_import_jobs_stocklist_idx
    ON stocklists.stocklist_import_jobs (stocklist_id);
