update_tables.sql 1.3 KB

123456789101112131415161718192021222324
  1. -- 修改群组表,添加新字段
  2. ALTER TABLE groups
  3. ADD COLUMN fee_rate DECIMAL(5,2) DEFAULT 0.00 COMMENT '费率' AFTER group_name,
  4. ADD COLUMN exchange_rate DECIMAL(10,4) DEFAULT 1.0000 COMMENT '汇率' AFTER fee_rate,
  5. ADD COLUMN creator_id INT NOT NULL COMMENT '创建人ID' AFTER exchange_rate,
  6. ADD COLUMN admin_id INT NOT NULL COMMENT '管理员ID' AFTER creator_id,
  7. ADD CONSTRAINT fk_groups_creator FOREIGN KEY (creator_id) REFERENCES users(id),
  8. ADD CONSTRAINT fk_groups_admin FOREIGN KEY (admin_id) REFERENCES users(id);
  9. -- 创建入款出款记录表
  10. CREATE TABLE IF NOT EXISTS money_records (
  11. id INT AUTO_INCREMENT PRIMARY KEY,
  12. time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  13. amount DECIMAL(10,2) NOT NULL COMMENT '金额',
  14. operator_id INT NOT NULL COMMENT '操作人ID',
  15. responder_id INT NOT NULL COMMENT '回复人ID',
  16. group_id VARCHAR(50) NOT NULL COMMENT '关联群组ID',
  17. type ENUM('deposit', 'withdrawal') NOT NULL COMMENT '类型:入款/出款',
  18. status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending' COMMENT '状态',
  19. FOREIGN KEY (operator_id) REFERENCES users(id),
  20. FOREIGN KEY (responder_id) REFERENCES users(id),
  21. FOREIGN KEY (group_id) REFERENCES groups(group_id),
  22. INDEX idx_group_time (group_id, time)
  23. );