-- Migration 012: backup_log 備份記錄表
-- 用於 AI Agent 監控資料庫備份執行狀況

CREATE TABLE IF NOT EXISTS backup_log (
    id SERIAL PRIMARY KEY,
    backup_type VARCHAR(20) DEFAULT 'full',       -- full / incremental
    filename VARCHAR(255) NOT NULL,
    file_size_bytes BIGINT DEFAULT 0,
    duration_seconds FLOAT DEFAULT 0,
    status VARCHAR(20) DEFAULT 'pending',          -- pending / success / failed
    error_message TEXT,
    host VARCHAR(100),
    storage_path VARCHAR(500),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    completed_at TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_backup_log_status ON backup_log(status);
CREATE INDEX IF NOT EXISTS idx_backup_log_created ON backup_log(created_at DESC);
