CoolFace
Apppublic

hardbanrecords/Metadata-Engine

sourceHugging Faceotherupdated 8mo agoView on Hugging Face
0likes
migrate_db.py50 linesDownload Raw Back to backend
1"""2Database Migration Script (Clean)3Adds 'message', 'duration', 'structure', 'coverArt' columns to jobs table if missing.4"""5import sqlite36import os7 8DB_PATH = "music_metadata.db"9 10def migrate():11    if not os.path.exists(DB_PATH):12        print(f"Database {DB_PATH} does not exist.")13        return14    15    conn = sqlite3.connect(DB_PATH)16    cursor = conn.cursor()17    18    try:19        # Check current columns20        cursor.execute("PRAGMA table_info(jobs)")21        columns = [row[1] for row in cursor.fetchall()]22        print(f"Current columns in 'jobs': {columns}")23        24        cols_to_add = {25            'message': 'TEXT',26            'duration': 'REAL',27            'structure': 'JSON',28            'coverArt': 'TEXT'29        }30        31        for col, col_type in cols_to_add.items():32            if col not in columns:33                print(f"Adding '{col}' column to jobs table...")34                cursor.execute(f"ALTER TABLE jobs ADD COLUMN {col} {col_type}")35                conn.commit()36                print(f"  Column '{col}' added.")37            else:38                print(f"  Column '{col}' already exists.")39        40        print("Migration process finished.")41            42    except Exception as e:43        print(f"Migration failed: {e}")44        conn.rollback()45    finally:46        conn.close()47 48if __name__ == "__main__":49    migrate()50