This commit is contained in:
lizandrogd
2026-01-21 01:02:17 -05:00
parent 4e3e02111b
commit 87b89b52a5
14 changed files with 387 additions and 36 deletions
@@ -0,0 +1,32 @@
<?php
/**
* Safe migration: show current column type, backup distinct statuses, then alter.
*/
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../classes/Database.php';
try {
$db = Database::getInstance();
echo "Current structure for conversations table:\n";
$rows = $db->fetchAll("SHOW COLUMNS FROM conversations LIKE 'status'");
print_r($rows);
$distinct = $db->fetchAll("SELECT DISTINCT status FROM conversations");
echo "Distinct status values in table:\n";
print_r(array_column($distinct, 'status'));
// Ask user confirmation (CLI only)
if (php_sapi_name() === 'cli') {
echo "About to alter column 'status' to ENUM('sent','delivered','read','failed','received') DEFAULT 'sent'. Continue? (y/N): ";
$resp = trim(fgets(STDIN));
if (strtolower($resp) !== 'y') {
echo "Aborted by user.\n";
exit;
}
}
$db->query("ALTER TABLE conversations MODIFY COLUMN status ENUM('sent','delivered','read','failed','received') DEFAULT 'sent'");
echo "ALTER OK\n";
} catch (Exception $e) {
echo "ERROR: " . $e->getMessage() . "\n";
}