23 lines
865 B
PHP
23 lines
865 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Add sold_serial_id column
|
|
$sql_add_column = "ALTER TABLE warranty_registrations ADD COLUMN sold_serial_id INT NULL AFTER serial_number";
|
|
$pdo->exec($sql_add_column);
|
|
|
|
// Add foreign key constraint
|
|
$sql_add_fk = "ALTER TABLE warranty_registrations ADD CONSTRAINT fk_sold_serial FOREIGN KEY (sold_serial_id) REFERENCES sold_serials(id) ON DELETE SET NULL";
|
|
$pdo->exec($sql_add_fk);
|
|
|
|
echo "Table 'warranty_registrations' modified successfully." . PHP_EOL;
|
|
|
|
} catch (PDOException $e) {
|
|
// Check if column already exists to avoid fatal error on re-run
|
|
if (strpos($e->getMessage(), 'Duplicate column name') === false) {
|
|
die("DB ERROR: " . $e->getMessage());
|
|
}
|
|
echo "Column 'sold_serial_id' already exists in 'warranty_registrations'." . PHP_EOL;
|
|
}
|