From a5c5f5b077a279ffbec10e1de1d4e4e098b2f6cf Mon Sep 17 00:00:00 2001 From: Yuyao Huang Date: Fri, 8 May 2026 16:23:00 +0800 Subject: [PATCH] Remove db.json migration logic --- database.py | 3 +-- schema.py | 46 ---------------------------------------------- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/database.py b/database.py index 994727c..7221600 100644 --- a/database.py +++ b/database.py @@ -8,9 +8,8 @@ def row_to_dict(row): def init_db(): - from schema import init_db as _init_db, migrate_from_tinydb + from schema import init_db as _init_db _init_db() - migrate_from_tinydb() def get_user_by_username(username): diff --git a/schema.py b/schema.py index 67b1388..a974fe4 100644 --- a/schema.py +++ b/schema.py @@ -1,6 +1,5 @@ import sqlite3 import os -import json import config @@ -69,48 +68,3 @@ def init_db(): conn.commit() finally: conn.close() - - -def migrate_from_tinydb(): - json_path = os.path.join(os.path.dirname(config.DB_PATH), "db.json") - if not os.path.exists(json_path): - return - - conn = get_connection() - try: - with open(json_path, "r") as f: - data = json.load(f) - - if "users" in data: - for doc_id, record in data["users"].items(): - record["id"] = int(doc_id) - if conn.execute("SELECT COUNT(*) FROM users WHERE id = ?", (record["id"],)).fetchone()[0] == 0: - conn.execute( - "INSERT INTO users (id, username, password_hash, role, max_goals) VALUES (?, ?, ?, ?, ?)", - (record["id"], record["username"], record["password_hash"], record["role"], record["max_goals"]) - ) - - if "goals" in data: - for doc_id, record in data["goals"].items(): - record["id"] = int(doc_id) - if conn.execute("SELECT COUNT(*) FROM goals WHERE id = ?", (record["id"],)).fetchone()[0] == 0: - conn.execute( - "INSERT INTO goals (id, user_id, title, activated) VALUES (?, ?, ?, ?)", - (record["id"], record["user_id"], record["title"], 1 if record.get("activated", True) else 0) - ) - - if "tasks" in data: - for doc_id, record in data["tasks"].items(): - record["id"] = int(doc_id) - if conn.execute("SELECT COUNT(*) FROM tasks WHERE id = ?", (record["id"],)).fetchone()[0] == 0: - conn.execute( - """INSERT INTO tasks (id, goal_id, title, desc, status, start_time, finished_time, "order") - VALUES (?, ?, ?, ?, ?, ?, ?, ?)""", - (record["id"], record["goal_id"], record["title"], record.get("desc", ""), - record.get("status", "todo"), record.get("start_time"), record.get("finished_time"), - record.get("order", 0.0)) - ) - - conn.commit() - finally: - conn.close()