# Internal Helper Script - NOT for production use
from django.db import connection, transaction
from core.models import Product

def fix_missing_columns():
    """
    Manually checks and adds missing columns if migrations fail.
    """
    with connection.cursor() as cursor:
        # Check is_service
        try:
            cursor.execute("SELECT is_service FROM core_product LIMIT 1")
        except Exception:
            print("Adding is_service column...")
            try:
                cursor.execute("ALTER TABLE core_product ADD COLUMN is_service tinyint(1) NOT NULL DEFAULT 0")
            except Exception as e:
                print(f"Error adding column: {e}")

        # Check is_active on PaymentMethod
        try:
            cursor.execute("SELECT is_active FROM core_paymentmethod LIMIT 1")
        except Exception:
            print("Adding is_active column to PaymentMethod...")
            try:
                cursor.execute("ALTER TABLE core_paymentmethod ADD COLUMN is_active tinyint(1) NOT NULL DEFAULT 1")
            except Exception as e:
                print(f"Error adding column: {e}")
