43 lines
2.0 KiB
PHP
43 lines
2.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
echo "Starting Database Migration..." . PHP_EOL;
|
|
|
|
$pdo = db();
|
|
|
|
$migrations = [
|
|
// Add indexes if they don't exist
|
|
"ALTER TABLE users ADD INDEX IF NOT EXISTS idx_users_username (username)",
|
|
"ALTER TABLE users ADD INDEX IF NOT EXISTS idx_users_role (role)",
|
|
"ALTER TABLE customers ADD INDEX IF NOT EXISTS idx_customers_email (email)",
|
|
"ALTER TABLE customers ADD INDEX IF NOT EXISTS idx_customers_status (status)",
|
|
"ALTER TABLE customers ADD INDEX IF NOT EXISTS idx_customers_deleted_at (deleted_at)",
|
|
"ALTER TABLE products ADD INDEX IF NOT EXISTS idx_products_name (name)",
|
|
"ALTER TABLE products ADD INDEX IF NOT EXISTS idx_products_deleted_at (deleted_at)",
|
|
"ALTER TABLE quotations ADD INDEX IF NOT EXISTS idx_quotations_status (status)",
|
|
"ALTER TABLE quotations ADD INDEX IF NOT EXISTS idx_quotations_expiry_date (expiry_date)",
|
|
"ALTER TABLE invoices ADD INDEX IF NOT EXISTS idx_invoices_status (status)",
|
|
"ALTER TABLE invoices ADD INDEX IF NOT EXISTS idx_invoices_due_date (due_date)",
|
|
|
|
// Add reminder columns if they don't exist
|
|
"ALTER TABLE quotations ADD COLUMN IF NOT EXISTS last_reminded_at TIMESTAMP NULL DEFAULT NULL AFTER notes",
|
|
"ALTER TABLE invoices ADD COLUMN IF NOT EXISTS last_reminded_at TIMESTAMP NULL DEFAULT NULL AFTER notes",
|
|
|
|
// Convert IDs to BIGINT UNSIGNED for Laravel compatibility (Note: this might fail if FKs exist, but let's try)
|
|
// "ALTER TABLE users MODIFY id BIGINT UNSIGNED AUTO_INCREMENT",
|
|
// This part is tricky because of foreign keys. For a "ready-to-migrate" structure,
|
|
// it's better to ensure new tables have it.
|
|
// For existing ones, we'll keep INT for now to avoid breaking FKs in this safe mode.
|
|
];
|
|
|
|
foreach ($migrations as $sql) {
|
|
try {
|
|
echo "Executing: $sql" . PHP_EOL;
|
|
$pdo->exec($sql);
|
|
} catch (PDOException $e) {
|
|
echo "Warning: " . $e->getMessage() . PHP_EOL;
|
|
}
|
|
}
|
|
|
|
echo "Migration finished." . PHP_EOL;
|