46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* Migration script to add updated_at column to ticket_comments table
|
||
|
|
* Run this on the production server: php scripts/add_comment_updated_at.php
|
||
|
|
*/
|
||
|
|
|
||
|
|
require_once dirname(__DIR__) . '/config/config.php';
|
||
|
|
|
||
|
|
echo "Adding updated_at column to ticket_comments table...\n";
|
||
|
|
|
||
|
|
try {
|
||
|
|
$conn = new mysqli(
|
||
|
|
$GLOBALS['config']['DB_HOST'],
|
||
|
|
$GLOBALS['config']['DB_USER'],
|
||
|
|
$GLOBALS['config']['DB_PASS'],
|
||
|
|
$GLOBALS['config']['DB_NAME']
|
||
|
|
);
|
||
|
|
|
||
|
|
if ($conn->connect_error) {
|
||
|
|
throw new Exception("Connection failed: " . $conn->connect_error);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Check if column already exists
|
||
|
|
$result = $conn->query("SHOW COLUMNS FROM ticket_comments LIKE 'updated_at'");
|
||
|
|
|
||
|
|
if ($result->num_rows > 0) {
|
||
|
|
echo "Column 'updated_at' already exists in ticket_comments table.\n";
|
||
|
|
} else {
|
||
|
|
// Add the column
|
||
|
|
$sql = "ALTER TABLE ticket_comments ADD COLUMN updated_at TIMESTAMP NULL DEFAULT NULL AFTER created_at";
|
||
|
|
|
||
|
|
if ($conn->query($sql)) {
|
||
|
|
echo "Successfully added 'updated_at' column to ticket_comments table.\n";
|
||
|
|
} else {
|
||
|
|
throw new Exception("Failed to add column: " . $conn->error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$conn->close();
|
||
|
|
echo "Done!\n";
|
||
|
|
|
||
|
|
} catch (Exception $e) {
|
||
|
|
echo "Error: " . $e->getMessage() . "\n";
|
||
|
|
exit(1);
|
||
|
|
}
|