#!/usr/bin/env python3 """ Add video metadata columns to media_files table. This migration adds: - video_codec (VARCHAR 32) - video_bitrate (INTEGER) - video_fps (VARCHAR 16) - video_duration (FLOAT) """ import sqlite3 from pathlib import Path from rich.console import Console console = Console() def main(): db_path = Path("metadata/database/romfarmer.db") if not db_path.exists(): console.print(f"[red]Error:[/red] Database not found: {db_path}") return console.print("\n[bold cyan]Adding Video Metadata Columns[/bold cyan]\n") conn = sqlite3.connect(db_path) cursor = conn.cursor() # Check if columns already exist cursor.execute("PRAGMA table_info(media_files);") columns = {row[1] for row in cursor.fetchall()} new_columns = { "video_codec": "VARCHAR(32)", "video_bitrate": "INTEGER", "video_fps": "VARCHAR(16)", "video_duration": "FLOAT", } added = [] skipped = [] for col_name, col_type in new_columns.items(): if col_name in columns: skipped.append(col_name) console.print(f"[yellow]⊘[/yellow] Column '{col_name}' already exists") else: cursor.execute(f"ALTER TABLE media_files ADD COLUMN {col_name} {col_type};") added.append(col_name) console.print(f"[green]✓[/green] Added column '{col_name}' ({col_type})") conn.commit() conn.close() console.print("\n[bold]Summary:[/bold]") console.print(f" Added: {len(added)}") console.print(f" Skipped (already exist): {len(skipped)}") if added: console.print("\n[green]✓ Migration completed successfully![/green]") else: console.print("\n[yellow]All columns already exist - no changes made[/yellow]") if __name__ == "__main__": main()