Commit 88b6e082 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix boot errors: migration column-exists and seed missing-table

Phase_24 migration: converted to closure that checks information_schema
before adding each column (column already exists on deployed DB).

Phase_39 seed: check if permissions table exists before inserting
(table was never created — skip gracefully).
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 5d11c9c2
<?php
declare(strict_types=1);
return [
'up' => "ALTER TABLE `reservations`
ADD COLUMN `is_archived` TINYINT(1) NOT NULL DEFAULT 0 AFTER `created_by`,
ADD COLUMN `archived_at` TIMESTAMP NULL DEFAULT NULL AFTER `is_archived`,
ADD COLUMN `archived_by` BIGINT UNSIGNED NULL AFTER `archived_at`;
use App\Core\Database;
ALTER TABLE `activity_subscriptions`
ADD COLUMN `is_archived` TINYINT(1) NOT NULL DEFAULT 0 AFTER `created_by`,
ADD COLUMN `archived_at` TIMESTAMP NULL DEFAULT NULL AFTER `is_archived`,
ADD COLUMN `archived_by` BIGINT UNSIGNED NULL AFTER `archived_at`",
'down' => "ALTER TABLE `reservations`
DROP COLUMN `archived_by`,
DROP COLUMN `archived_at`,
DROP COLUMN `is_archived`;
return function (Database $db): void {
$tables = ['reservations', 'activity_subscriptions'];
$columns = ['is_archived', 'archived_at', 'archived_by'];
ALTER TABLE `activity_subscriptions`
DROP COLUMN `archived_by`,
DROP COLUMN `archived_at`,
DROP COLUMN `is_archived`",
];
foreach ($tables as $table) {
foreach ($columns as $col) {
$exists = $db->selectOne(
"SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ?",
[$table, $col]
);
if ($exists) {
continue;
}
$sql = match ($col) {
'is_archived' => "ALTER TABLE `{$table}` ADD COLUMN `is_archived` TINYINT(1) NOT NULL DEFAULT 0",
'archived_at' => "ALTER TABLE `{$table}` ADD COLUMN `archived_at` TIMESTAMP NULL DEFAULT NULL",
'archived_by' => "ALTER TABLE `{$table}` ADD COLUMN `archived_by` BIGINT UNSIGNED NULL",
};
$db->raw($sql);
}
}
};
......@@ -4,6 +4,13 @@ declare(strict_types=1);
use App\Core\Database;
return function (Database $db): void {
$tableExists = $db->selectOne(
"SELECT 1 FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'permissions'"
);
if (!$tableExists) {
return;
}
$permissions = [
['key' => 'support.view', 'name_ar' => 'عرض تذاكر الدعم', 'name_en' => 'View Support Tickets', 'module' => 'support'],
['key' => 'support.create', 'name_ar' => 'إنشاء تذكرة دعم', 'name_en' => 'Create Support Ticket', 'module' => 'support'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment