Files
nabeh/backend/add_whatsapp_session_id_to_users.php
2026-05-23 01:13:51 +03:00

50 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
if (php_sapi_name() !== 'cli') {
http_response_code(403);
exit('Access denied.');
}
require_once __DIR__ . '/app/bootstrap.php';
use App\Core\Database;
try {
$pdo = Database::getConnection();
echo "=== Running Database Migrations: Adding whatsapp_session_id ===\n";
// Check if the column already exists
$stmt = $pdo->prepare("
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'users'
AND COLUMN_NAME = 'whatsapp_session_id'
");
$stmt->execute();
$columnExists = $stmt->fetch();
if (!$columnExists) {
echo "Adding column 'whatsapp_session_id' to 'users' table...\n";
// Add column
$pdo->exec("ALTER TABLE `users` ADD COLUMN `whatsapp_session_id` INT NULL DEFAULT NULL");
// Add foreign key constraint
$pdo->exec("
ALTER TABLE `users`
ADD CONSTRAINT `fk_users_whatsapp_session`
FOREIGN KEY (`whatsapp_session_id`)
REFERENCES `whatsapp_sessions` (`id`)
ON DELETE SET NULL
");
echo "✅ Column 'whatsapp_session_id' and foreign key created successfully!\n";
} else {
echo " Column 'whatsapp_session_id' already exists in 'users' table. Skipping.\n";
}
} catch (\Exception $e) {
echo "❌ Migration failed: " . $e->getMessage() . "\n";
}