#!/usr/bin/env python # -*- coding: utf-8 -*- import sqlite3 import os DATABASE_PATH = os.path.join(os.path.dirname(__file__), '../database/app.db') print('=== 数据库迁移 ===') if os.path.exists(DATABASE_PATH): print(f'数据库文件存在: {DATABASE_PATH}') conn = sqlite3.connect(DATABASE_PATH) cursor = conn.cursor() try: cursor.execute("PRAGMA table_info(tasks)") columns = [col[1] for col in cursor.fetchall()] if 'acceptor_id' not in columns: print('添加 acceptor_id 字段...') cursor.execute('ALTER TABLE tasks ADD COLUMN acceptor_id INTEGER') conn.commit() print('字段添加成功!') else: print('acceptor_id 字段已存在,跳过') print('\n迁移完成!') except Exception as e: print(f'迁移失败: {e}') import traceback traceback.print_exc() finally: conn.close() else: print('数据库文件不存在')