| """ |
| Quick migration: add zai_api_key column to existing SQLite database |
| Run once: python migrate_zai.py |
| """ |
| import sqlite3 |
| import os |
|
|
| db_path = os.path.join(os.path.dirname(__file__), 'data', 'literature_cache.db') |
| print(f"Migrating: {db_path}") |
|
|
| conn = sqlite3.connect(db_path) |
| cursor = conn.cursor() |
|
|
| |
| cursor.execute("PRAGMA table_info(user)") |
| columns = [row[1] for row in cursor.fetchall()] |
| print(f"Existing columns: {columns}") |
|
|
| if 'zai_api_key' not in columns: |
| cursor.execute("ALTER TABLE user ADD COLUMN zai_api_key VARCHAR(200)") |
| conn.commit() |
| print("✅ Column 'zai_api_key' added successfully!") |
| else: |
| print("ℹ️ Column 'zai_api_key' already exists, skipping.") |
|
|
| conn.close() |
| print("Done. Restart your app now.") |
|
|