-- 项目关键变更日志表：记录预算/周期/负责人/执行人/会议期数等字段前后值

CREATE TABLE IF NOT EXISTS project_key_change_log (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
    tenant_id BIGINT UNSIGNED NOT NULL COMMENT '租户ID',
    project_id BIGINT UNSIGNED NOT NULL COMMENT '项目ID',
    field_code VARCHAR(64) NOT NULL COMMENT '字段编码',
    field_name VARCHAR(128) NOT NULL COMMENT '字段名称',
    before_value VARCHAR(1000) NULL COMMENT '变更前值',
    after_value VARCHAR(1000) NULL COMMENT '变更后值',
    change_reason VARCHAR(500) NULL COMMENT '变更原因',
    handover_at DATETIME NULL COMMENT '交接时间（负责人/执行人变更时）',
    is_deleted TINYINT(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
    created_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '更新人',
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    KEY idx_tenant_project_time (tenant_id, project_id, created_at),
    KEY idx_tenant_field_time (tenant_id, field_code, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='项目关键变更日志';
