-- 038_create_ppt_generation_runs.sql
-- PPT 定期產出嘗試紀錄：保留每次日/週/月/季/半年/年排程的狀態與結果。

CREATE TABLE IF NOT EXISTS ppt_generation_runs (
    id SERIAL PRIMARY KEY,
    schedule_kind VARCHAR(40) NOT NULL,
    report_type VARCHAR(50) NOT NULL,
    target_label VARCHAR(160),
    status VARCHAR(30) NOT NULL,
    parameters_json TEXT,
    file_path VARCHAR(500),
    file_size INTEGER,
    error_msg TEXT,
    result_payload TEXT,
    started_at TIMESTAMP WITHOUT TIME ZONE,
    finished_at TIMESTAMP WITHOUT TIME ZONE
);

CREATE INDEX IF NOT EXISTS ix_ppt_generation_runs_report_type
    ON ppt_generation_runs (report_type);

CREATE INDEX IF NOT EXISTS ix_ppt_generation_runs_started_at
    ON ppt_generation_runs (started_at);

CREATE INDEX IF NOT EXISTS ix_ppt_generation_runs_schedule_kind
    ON ppt_generation_runs (schedule_kind);
