""" Migration script to add season, explicit, and naming_format fields to the database. """ import sqlite3 import os 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 season column if it doesn't exist if 'season' not in columns: print("Adding 'season' column to episodes table...") cursor.execute("ALTER TABLE episodes ADD COLUMN season INTEGER") # Add the explicit column if it doesn't exist if 'explicit' not in columns: print("Adding 'explicit' column to episodes table...") cursor.execute("ALTER TABLE episodes ADD COLUMN explicit BOOLEAN") # Check if the naming_format column already exists in the podcasts table cursor.execute("PRAGMA table_info(podcasts)") columns = [column[1] for column in cursor.fetchall()] # Add the naming_format column if it doesn't exist if 'naming_format' not in columns: print("Adding 'naming_format' column to podcasts table...") cursor.execute("ALTER TABLE podcasts ADD COLUMN naming_format TEXT") # Commit the changes and close the connection conn.commit() conn.close() print("Migration completed successfully!") return True