From ec9614508422d1c48b2903cd9e19f8a11b67b16b Mon Sep 17 00:00:00 2001 From: Ollama Date: Wed, 18 Mar 2026 09:48:26 +0000 Subject: [PATCH] fix: check for core tables not migrations table in initial migration (#4447) When tests use refresh=true, CodeIgniter creates migrations table first, so listTables() was returning that table and skipping initial schema. Now checks for actual application tables (app_config, items, etc). --- .../Migrations/20170501000000_initial_schema.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Database/Migrations/20170501000000_initial_schema.php b/app/Database/Migrations/20170501000000_initial_schema.php index 9d781dc5d..18087a9e1 100644 --- a/app/Database/Migrations/20170501000000_initial_schema.php +++ b/app/Database/Migrations/20170501000000_initial_schema.php @@ -17,13 +17,19 @@ class Migration_Initial_Schema extends Migration */ public function up(): void { - // Check if database already has tables (existing install) + // Check if core application tables exist (existing install) + // Note: migrations table may exist even on fresh DB due to migration tracking $tables = $this->db->listTables(); - if (!empty($tables)) { - // Database already populated - skip initial schema - // This is an existing installation upgrading from older version - return; + // Check for a core application table, not just migrations table + foreach ($tables as $table) { + // Strip prefix if present for comparison + $tableName = str_replace($this->db->getPrefix(), '', $table); + if (in_array($tableName, ['app_config', 'items', 'employees', 'people'])) { + // Database already populated - skip initial schema + // This is an existing installation upgrading from older version + return; + } } // Fresh install - load initial schema