"""
Create landing_pages table for AI-powered landing page generator.
Run with: python migrations/add_landing_pages_table.py
"""
import sys
import os

# Add the parent directory to the path so we can import from app
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.extensions import db
from app import create_app

def migrate():
    """Create landing_pages table."""
    app = create_app()

    with app.app_context():
        # Check if table exists
        inspector = db.inspect(db.engine)
        if 'landing_pages' in inspector.get_table_names():
            print("✓ Table 'landing_pages' already exists")
        else:
            # Import the model to ensure it's registered with SQLAlchemy
            from app.models.campaign import LandingPage

            # Create the table
            db.create_all()
            print("✓ Created 'landing_pages' table")

            print("\n✅ Migration completed successfully!")
            print("   - Landing pages can now be created from reports")
            print("   - AI-powered content generation is enabled")
            print("   - Bilingual support (AR/EN) is available")

if __name__ == "__main__":
    migrate()