-- 添加用户角色字段 -- Migration: 003_add_user_roles.sql -- 添加角色字段到用户表 ALTER TABLE users ADD COLUMN role TEXT NOT NULL DEFAULT 'user'; -- 创建角色索引以提高查询性能 CREATE INDEX idx_users_role ON users(role); -- 更新现有用户为默认角色 UPDATE users SET role = 'user' WHERE role IS NULL OR role = ''; -- 添加角色约束检查 -- SQLite 不支持 CHECK 约束的 ALTER TABLE,所以我们在应用层处理验证