#!/usr/bin/env python3
"""
Migration script to add content_text column to case_documents table
"""
from app import app
from models import db

with app.app_context():
    try:
        # Add the content_text column using SQLAlchemy 2.x syntax
        with db.engine.connect() as conn:
            conn.execute(db.text("""
                ALTER TABLE case_documents
                ADD COLUMN content_text TEXT DEFAULT NULL
            """))
            conn.commit()
        print("✅ Successfully added content_text column to case_documents table")
    except Exception as e:
        if "Duplicate column name" in str(e):
            print("⚠️  Column content_text already exists")
        else:
            print(f"❌ Error adding column: {e}")
            raise
