Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/database/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/database/run_migration.php

<?php
/**
 * Database Migration Runner
 * Adds missing membershipcard_id column to members table
 */

require_once '../config/config.php';

try {
    $db = Database::getInstance()->getConnection();
    
    echo "<h2>Running Database Migration</h2>\n";
    echo "<p>Adding membershipcard_id column to members table...</p>\n";
    
    // Read the migration SQL
    $migrationSQL = file_get_contents(__DIR__ . '/migrations/add_membershipcard_id.sql');
    
    // Execute the migration
    $db->exec($migrationSQL);
    
    echo "<p style='color: green;'>✅ Migration completed successfully!</p>\n";
    echo "<p>The membershipcard_id column has been added to the members table.</p>\n";
    
    // Verify the column exists
    $stmt = $db->query("SHOW COLUMNS FROM members LIKE 'membershipcard_id'");
    $column = $stmt->fetch();
    
    if ($column) {
        echo "<p style='color: green;'>✅ Column verification: membershipcard_id column exists</p>\n";
        
        // Check if any records have membership card IDs
        $stmt = $db->query("SELECT COUNT(*) as count FROM members WHERE membershipcard_id IS NOT NULL AND membershipcard_id != ''");
        $result = $stmt->fetch();
        echo "<p>Records with membership card IDs: " . $result['count'] . "</p>\n";
    } else {
        echo "<p style='color: red;'>❌ Column verification failed: membershipcard_id column not found</p>\n";
    }
    
} catch (PDOException $e) {
    echo "<p style='color: red;'>❌ Migration failed: " . $e->getMessage() . "</p>\n";
    
    // If the error is about the column already existing, that's actually good
    if (strpos($e->getMessage(), 'Duplicate column name') !== false) {
        echo "<p style='color: orange;'>ℹ️ Column already exists - this is expected if migration was run before.</p>\n";
    }
} catch (Exception $e) {
    echo "<p style='color: red;'>❌ Error: " . $e->getMessage() . "</p>\n";
}

echo "<hr>";
echo "<p><a href='../dashboard.php'>← Back to Dashboard</a></p>";
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists