<?php
$host = '127.0.0.1';
$db = 'nexcore_pharma';
$user = 'nexcore_pharma';
$pass = 'nexova@2026';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8mb4", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Check if feature_email_alerts exists
    $stmt = $pdo->query("SHOW COLUMNS FROM tenants LIKE 'feature_email_alerts'");
    if ($stmt->rowCount() == 0) {
        $pdo->exec("ALTER TABLE tenants ADD COLUMN feature_email_alerts TINYINT(1) DEFAULT 1");
        echo "Added feature_email_alerts column.\n";
    } else {
        echo "feature_email_alerts already exists.\n";
    }

    // Check if feature_whatsapp_alerts exists
    $stmt = $pdo->query("SHOW COLUMNS FROM tenants LIKE 'feature_whatsapp_alerts'");
    if ($stmt->rowCount() == 0) {
        $pdo->exec("ALTER TABLE tenants ADD COLUMN feature_whatsapp_alerts TINYINT(1) DEFAULT 1");
        echo "Added feature_whatsapp_alerts column.\n";
    } else {
        echo "feature_whatsapp_alerts already exists.\n";
    }

    echo "Migration completed successfully.\n";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
