-- audit-P2-3: 注册邀请码表（admin 批量生成，注册时校验 + 自动分配角色/班级）
CREATE TABLE IF NOT EXISTS `invitation_codes` (
  `id` serial PRIMARY KEY,
  `code` varchar(64) NOT NULL,
  `email` varchar(255),
  `role` varchar(50) NOT NULL,
  `class_id` varchar(128),
  `notes` varchar(500),
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` varchar(128),
  `expires_at` timestamp NULL,
  `used_by` varchar(128),
  `used_at` timestamp NULL,
  UNIQUE KEY `invitation_codes_code_unique` (`code`)
);

CREATE INDEX `invitation_codes_code_idx` ON `invitation_codes`(`code`);
CREATE INDEX `invitation_codes_email_idx` ON `invitation_codes`(`email`);
CREATE INDEX `invitation_codes_used_by_idx` ON `invitation_codes`(`used_by`);
