""" Migration script to add download_error and status_code fields to the Episode model. """ import sqlite3 from flask import current_app def run_migration(): """ Run the migration to add the new fields to the database. """ # Get the database path from the app config db_path = current_app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '') # Connect to the database conn = sqlite3.connect(db_path) cursor = conn.cursor() # Check if the columns already exist in the episodes table cursor.execute("PRAGMA table_info(episodes)") columns = [column[1] for column in cursor.fetchall()] # Add the download_error column if it doesn't exist if 'download_error' not in columns: print("Adding 'download_error' column to episodes table...") cursor.execute("ALTER TABLE episodes ADD COLUMN download_error TEXT") # Add the status_code column if it doesn't exist if 'status_code' not in columns: print("Adding 'status_code' column to episodes table...") cursor.execute("ALTER TABLE episodes ADD COLUMN status_code INTEGER") # Commit the changes and close the connection conn.commit() conn.close() print("Migration completed successfully!") return True