-- Bot-Bridge + Verify 合并改造：数据库迁移脚本 (表创建部分)
-- CREATE TABLE 在表不存在时安全执行
-- ALTER TABLE 由 Python 脚本处理

CREATE TABLE IF NOT EXISTS mpm_results (
  id INT AUTO_INCREMENT PRIMARY KEY,
  entity_id INT NOT NULL,
  period VARCHAR(20) NOT NULL,
  source VARCHAR(50) DEFAULT 'finance-bot',
  raw_data JSON NOT NULL COMMENT '完整的MPM计算结果',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (entity_id) REFERENCES entities(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS bot_bridge_config (
  id INT AUTO_INCREMENT PRIMARY KEY,
  bot_name VARCHAR(50) NOT NULL UNIQUE,
  token VARCHAR(64) NOT NULL,
  is_active BOOLEAN DEFAULT TRUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT IGNORE INTO bot_bridge_config (bot_name, token) VALUES ('finance-bot', 'cma-bot-bridge-2026');
