-- OCR Pipeline Sessions - Persistent session storage
-- Applied automatically by ocr_pipeline_session_store.init_ocr_pipeline_tables()

CREATE TABLE IF NOT EXISTS ocr_pipeline_sessions (
    id UUID PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    filename VARCHAR(255),
    status VARCHAR(50) DEFAULT 'active',
    current_step INT DEFAULT 1,
    original_png BYTEA,
    deskewed_png BYTEA,
    binarized_png BYTEA,
    dewarped_png BYTEA,
    deskew_result JSONB,
    dewarp_result JSONB,
    column_result JSONB,
    ground_truth JSONB DEFAULT '{}',
    auto_shear_degrees FLOAT,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

-- Index for listing sessions
CREATE INDEX IF NOT EXISTS idx_ocr_pipeline_sessions_created
    ON ocr_pipeline_sessions (created_at DESC);

CREATE INDEX IF NOT EXISTS idx_ocr_pipeline_sessions_status
    ON ocr_pipeline_sessions (status);
