28 lines
769 B
PHP
28 lines
769 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
$pdo = db();
|
|
|
|
$tableStmt = $pdo->prepare(
|
|
'SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = :table LIMIT 1'
|
|
);
|
|
$tableStmt->execute(['table' => 'invoices']);
|
|
|
|
if ((bool)$tableStmt->fetchColumn()) {
|
|
$columnStmt = $pdo->prepare(
|
|
'SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = :table AND COLUMN_NAME = :column LIMIT 1'
|
|
);
|
|
$columnStmt->execute([
|
|
'table' => 'invoices',
|
|
'column' => 'due_date',
|
|
]);
|
|
|
|
if (!(bool)$columnStmt->fetchColumn()) {
|
|
$pdo->exec('ALTER TABLE `invoices` ADD COLUMN `due_date` DATE DEFAULT NULL AFTER `invoice_date`');
|
|
}
|
|
}
|
|
|
|
return true;
|