mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-09-20 08:58:15 +00:00
fix: 已有用户自动迁移 admin 角色
当 role 列通过 ALTER TABLE 新增后,已有用户全部为 'user'。 新增迁移逻辑:若无 admin 用户,自动将首个注册用户升为 admin。
This commit is contained in:
@ -111,6 +111,15 @@ class EmbeddedGraphDB:
|
||||
if 'role' not in columns:
|
||||
cursor.execute("ALTER TABLE web_users ADD COLUMN role TEXT NOT NULL DEFAULT 'user'")
|
||||
|
||||
# 确保至少有一个 admin(当 role 列刚添加时,已有用户都是 user)
|
||||
cursor.execute("SELECT COUNT(*) as cnt FROM web_users WHERE role = 'admin'")
|
||||
has_admin = cursor.fetchone()[0] > 0
|
||||
if not has_admin:
|
||||
cursor.execute("SELECT id, username FROM web_users ORDER BY created_at ASC LIMIT 1")
|
||||
first_user = cursor.fetchone()
|
||||
if first_user:
|
||||
cursor.execute("UPDATE web_users SET role = 'admin' WHERE id = ?", (first_user[0],))
|
||||
|
||||
self.conn.commit()
|
||||
|
||||
def ensure_constraints(self):
|
||||
|
||||
Reference in New Issue
Block a user