fix: 修复多worker并发初始化时默认管理员唯一键冲突
This commit is contained in:
+3
-7
@@ -62,6 +62,7 @@ def get_db():
|
|||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
conn.execute("PRAGMA foreign_keys = ON")
|
conn.execute("PRAGMA foreign_keys = ON")
|
||||||
|
conn.execute("PRAGMA busy_timeout = 5000")
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
|
||||||
@@ -70,15 +71,10 @@ def init_db():
|
|||||||
conn = get_db()
|
conn = get_db()
|
||||||
try:
|
try:
|
||||||
conn.executescript(SCHEMA)
|
conn.executescript(SCHEMA)
|
||||||
conn.commit()
|
|
||||||
|
|
||||||
admin = conn.execute(
|
|
||||||
"SELECT id FROM users WHERE username = ?", ("admin",)
|
|
||||||
).fetchone()
|
|
||||||
if admin is None:
|
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO users (username, password_hash, display_name, is_admin, is_active, created_at)
|
INSERT OR IGNORE INTO users
|
||||||
|
(username, password_hash, display_name, is_admin, is_active, created_at)
|
||||||
VALUES (?, ?, ?, 1, 1, ?)
|
VALUES (?, ?, ?, 1, 1, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user