fix: 清理抽卡插件遗留迁移死代码

- 删除 claim_achievement_reward 中不可达的 _migrate_data() 调用
- 删除 _migrate_data() 方法(JSON→SQLite 迁移已完成,不再需要)
- 删除 config 中 DAILY_DRAWS_FILE / USER_STATS_FILE 遗留配置
This commit is contained in:
2026-04-05 21:35:14 +08:00
parent e773a7a1ef
commit 08ba1399ef
2 changed files with 2 additions and 68 deletions

View File

@@ -17,8 +17,6 @@ class Config(BaseSettings):
# 数据文件路径 # 数据文件路径
DB_FILE: str = "data/onmyoji_gacha/gacha.db" DB_FILE: str = "data/onmyoji_gacha/gacha.db"
DAILY_DRAWS_FILE: str = "data/onmyoji_gacha/daily_draws.json" # 保留用于迁移
USER_STATS_FILE: str = "data/onmyoji_gacha/user_stats.json" # 保留用于迁移
# 式神图片目录 # 式神图片目录
SHIKIGAMI_IMG_DIR: str = "data/chouka/" SHIKIGAMI_IMG_DIR: str = "data/chouka/"

View File

@@ -278,70 +278,6 @@ class DataManager:
conn.commit() conn.commit()
return cursor.rowcount > 0 return cursor.rowcount > 0
# 迁移现有JSON数据到SQLite
self._migrate_data()
def _migrate_data(self):
"""迁移JSON数据到SQLite"""
try:
# 迁移每日抽卡记录
if os.path.exists(config.DAILY_DRAWS_FILE):
with open(config.DAILY_DRAWS_FILE, 'r', encoding='utf-8') as f:
daily_draws = json.load(f)
with sqlite3.connect(config.DB_FILE) as conn:
cursor = conn.cursor()
for date, users in daily_draws.items():
for user_id, draws in users.items():
for draw in draws:
# 查找式神ID
cursor.execute(
"SELECT id FROM shikigami WHERE name=? AND rarity=?",
(draw["name"], draw["rarity"])
)
shikigami_id = cursor.fetchone()
if shikigami_id:
cursor.execute(
"INSERT INTO daily_draws (date, user_id, rarity, shikigami_id, timestamp) VALUES (?, ?, ?, ?, ?)",
(date, user_id, draw["rarity"], shikigami_id[0], draw["timestamp"])
)
conn.commit()
# 迁移用户统计数据
if os.path.exists(config.USER_STATS_FILE):
with open(config.USER_STATS_FILE, 'r', encoding='utf-8') as f:
user_stats = json.load(f)
with sqlite3.connect(config.DB_FILE) as conn:
cursor = conn.cursor()
for user_id, stats in user_stats.items():
cursor.execute(
"INSERT OR REPLACE INTO user_stats (user_id, total_draws, R_count, SR_count, SSR_count, SP_count) VALUES (?, ?, ?, ?, ?, ?)",
(user_id, stats["total_draws"], stats["R_count"], stats["SR_count"], stats["SSR_count"], stats["SP_count"])
)
# 迁移抽卡历史
for draw in stats.get("draw_history", []):
cursor.execute(
"SELECT id FROM shikigami WHERE name=? AND rarity=?",
(draw["name"], draw["rarity"])
)
shikigami_id = cursor.fetchone()
if shikigami_id:
cursor.execute(
"INSERT INTO draw_history (user_id, date, rarity, shikigami_id) VALUES (?, ?, ?, ?)",
(user_id, draw["date"], draw["rarity"], shikigami_id[0])
)
conn.commit()
except Exception as e:
logging.error(f"数据迁移失败: {e}")
def _load_shikigami_data(self) -> Dict[str, List[Dict[str, str]]]: def _load_shikigami_data(self) -> Dict[str, List[Dict[str, str]]]:
"""加载式神数据到数据库""" """加载式神数据到数据库"""