From 20a9c1bb1256868bbf8709c88be1a0ff39c9be92 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 2 May 2026 18:24:06 +0000 Subject: [PATCH] another editing installation --- db/install_baseline_migrations.php | 1 - .../20260502_zzzz_default_outlet_guard.sql | 18 ++++++++++++++++++ refresh_complete_schema.php | 13 ++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 db/migrations/20260502_zzzz_default_outlet_guard.sql diff --git a/db/install_baseline_migrations.php b/db/install_baseline_migrations.php index 3fe5232..37572eb 100644 --- a/db/install_baseline_migrations.php +++ b/db/install_baseline_migrations.php @@ -43,7 +43,6 @@ return [ '20260221_fix_pos_invoices_columns.sql', '20260221_fix_supplier_foreign_keys.sql', '20260318_add_outlet_id_to_purchases.sql', - '20260318_create_outlets_table.sql', '20260318_multi_outlet_schema.sql', '20260318_local_definitions.sql', '20260318_user_outlets_table.sql', diff --git a/db/migrations/20260502_zzzz_default_outlet_guard.sql b/db/migrations/20260502_zzzz_default_outlet_guard.sql new file mode 100644 index 0000000..7d48083 --- /dev/null +++ b/db/migrations/20260502_zzzz_default_outlet_guard.sql @@ -0,0 +1,18 @@ +-- Ensure the default outlet exists for installs created from complete_schema.sql snapshots. +-- Fresh installs can otherwise miss outlet ID 1 if the outlet seed migration was marked as already executed. + +CREATE TABLE IF NOT EXISTS `outlets` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `address` text DEFAULT NULL, + `phone` varchar(50) DEFAULT NULL, + `status` enum('active','inactive') DEFAULT 'active', + `created_at` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +INSERT INTO `outlets` (`id`, `name`, `address`, `phone`, `status`, `created_at`) +SELECT 1, 'Main Outlet', 'Head Office', '', 'active', NOW() +WHERE NOT EXISTS ( + SELECT 1 FROM `outlets` WHERE `id` = 1 +); diff --git a/refresh_complete_schema.php b/refresh_complete_schema.php index aedb3c2..3ed3e64 100644 --- a/refresh_complete_schema.php +++ b/refresh_complete_schema.php @@ -103,6 +103,16 @@ function isLegacyNumberedSnapshotMigrationFile(string $filePath): bool return preg_match('/^\d{1,7}_/', basename($filePath)) === 1; } +function isInstallBaselineExcludedMigrationFile(string $filePath): bool +{ + // These migrations include required default data that is not embedded in complete_schema.sql. + // Keep them out of the install baseline so fresh installs still execute them. + return in_array(basename($filePath), [ + '20260318_create_outlets_table.sql', + '20260502_zzzz_default_outlet_guard.sql', + ], true); +} + function fetchInstallBaselineMigrationNames(): array { $files = array_merge( @@ -111,7 +121,8 @@ function fetchInstallBaselineMigrationNames(): array ); $files = array_values(array_filter($files, static function (string $filePath): bool { - return !isLegacyNumberedSnapshotMigrationFile($filePath); + return !isLegacyNumberedSnapshotMigrationFile($filePath) + && !isInstallBaselineExcludedMigrationFile($filePath); })); usort($files, static function (string $left, string $right): int {