""" Migration: Add template_name column to site_deployments table This migration adds template tracking at the site/domain level. Each site will have a consistent template used for all articles and pages. """ import sqlite3 import sys from pathlib import Path # Add parent directory to path for imports sys.path.insert(0, str(Path(__file__).parent.parent)) from src.core.config import get_config def migrate(): """Add template_name column to site_deployments table""" config = get_config() db_path = config.database.url.replace("sqlite:///", "") print(f"Connecting to database: {db_path}") conn = sqlite3.connect(db_path) cursor = conn.cursor() try: # Check if column already exists cursor.execute("PRAGMA table_info(site_deployments)") columns = [column[1] for column in cursor.fetchall()] if 'template_name' in columns: print("✓ Column 'template_name' already exists in site_deployments table") return # Add template_name column print("Adding template_name column to site_deployments table...") cursor.execute(""" ALTER TABLE site_deployments ADD COLUMN template_name VARCHAR(50) DEFAULT 'basic' NOT NULL """) conn.commit() print("✓ Successfully added template_name column") # Show current sites cursor.execute("SELECT id, site_name, template_name FROM site_deployments") sites = cursor.fetchall() if sites: print(f"\nCurrent sites (all defaulted to 'basic' template):") for site_id, site_name, template in sites: print(f" Site {site_id}: {site_name} -> {template}") else: print("\nNo sites in database yet") except sqlite3.Error as e: print(f"✗ Migration failed: {e}") conn.rollback() raise finally: conn.close() if __name__ == "__main__": migrate()