Files
youtube-dl/manual_migration.py

44 lines
1.2 KiB
Python

import sqlite3
import os
db_path = '/Volumes/WD/Users/Work/python/flaskfarm/data/db/gds_dviewer.db'
table_name = 'gds_dviewer_file_index'
print(f"Checking DB: {db_path}")
if not os.path.exists(db_path):
print("Error: DB file not found")
exit(1)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Check columns
cursor.execute(f"PRAGMA table_info({table_name})")
columns = [row[1] for row in cursor.fetchall()]
print(f"Current columns: {columns}")
# Add columns if missing
changed = False
if 'meta_id' not in columns:
print(f"Adding meta_id to {table_name}")
cursor.execute(f"ALTER TABLE {table_name} ADD COLUMN meta_id VARCHAR(64)")
try:
cursor.execute(f"CREATE INDEX ix_{table_name}_meta_id ON {table_name} (meta_id)")
print("Created index for meta_id")
except Exception as e:
print(f"Index creation hint/error: {e}")
changed = True
if 'meta_poster' not in columns:
print(f"Adding meta_poster to {table_name}")
cursor.execute(f"ALTER TABLE {table_name} ADD COLUMN meta_poster VARCHAR(1024)")
changed = True
if changed:
conn.commit()
print("Migration successful")
else:
print("No changes needed")
conn.close()