From c70649475a1b425ed59bcff9db7056c21b760d78 Mon Sep 17 00:00:00 2001 From: guoqingshan Date: Sat, 1 Aug 2026 21:27:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9Aworker?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=AE=A1=E7=90=86=E5=91=98=E5=94=AF=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/db.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/server/db.py b/server/db.py index 2a50230..cf06c4a 100644 --- a/server/db.py +++ b/server/db.py @@ -62,6 +62,7 @@ def get_db(): conn = sqlite3.connect(DB_PATH) conn.row_factory = sqlite3.Row conn.execute("PRAGMA foreign_keys = ON") + conn.execute("PRAGMA busy_timeout = 5000") return conn @@ -70,24 +71,19 @@ def init_db(): conn = get_db() try: conn.executescript(SCHEMA) + conn.execute( + """ + INSERT OR IGNORE INTO users + (username, password_hash, display_name, is_admin, is_active, created_at) + VALUES (?, ?, ?, 1, 1, ?) + """, + ( + "admin", + generate_password_hash("admin123"), + "管理员", + now_iso(), + ), + ) conn.commit() - - admin = conn.execute( - "SELECT id FROM users WHERE username = ?", ("admin",) - ).fetchone() - if admin is None: - conn.execute( - """ - INSERT INTO users (username, password_hash, display_name, is_admin, is_active, created_at) - VALUES (?, ?, ?, 1, 1, ?) - """, - ( - "admin", - generate_password_hash("admin123"), - "管理员", - now_iso(), - ), - ) - conn.commit() finally: conn.close()