-- 数据清理日志表
CREATE TABLE IF NOT EXISTS tb_data_cleanup_log (
    id BIGSERIAL PRIMARY KEY,
    table_name VARCHAR(100) NOT NULL,
    cleanup_type VARCHAR(50) NOT NULL,
    retention_days INT NOT NULL,
    deleted_count BIGINT NOT NULL DEFAULT 0,
    duration_ms BIGINT NOT NULL DEFAULT 0,
    status VARCHAR(20) NOT NULL,
    error_message TEXT,
    started_at TIMESTAMP NOT NULL,
    completed_at TIMESTAMP,
    triggered_by BIGINT
);

-- 索引
CREATE INDEX idx_data_cleanup_log_table_name ON tb_data_cleanup_log(table_name);
CREATE INDEX idx_data_cleanup_log_started_at ON tb_data_cleanup_log(started_at);
CREATE INDEX idx_data_cleanup_log_status ON tb_data_cleanup_log(status);

-- 表注释
COMMENT ON TABLE tb_data_cleanup_log IS '数据清理日志表 - 记录所有数据清理操作';

-- 列注释
COMMENT ON COLUMN tb_data_cleanup_log.table_name IS '表名';
COMMENT ON COLUMN tb_data_cleanup_log.cleanup_type IS '清理类型：scheduled/manual';
COMMENT ON COLUMN tb_data_cleanup_log.retention_days IS '保留天数';
COMMENT ON COLUMN tb_data_cleanup_log.deleted_count IS '删除记录数';
COMMENT ON COLUMN tb_data_cleanup_log.duration_ms IS '执行耗时（毫秒）';
COMMENT ON COLUMN tb_data_cleanup_log.status IS '状态：success/failed/running';
COMMENT ON COLUMN tb_data_cleanup_log.error_message IS '错误信息';
COMMENT ON COLUMN tb_data_cleanup_log.started_at IS '开始时间';
COMMENT ON COLUMN tb_data_cleanup_log.completed_at IS '完成时间';
COMMENT ON COLUMN tb_data_cleanup_log.triggered_by IS '触发人ID（手动触发时）';
