db->listTables(); // 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 helper('migration'); execute_script(APPPATH . 'Database/Migrations/sqlscripts/initial_schema.sql'); } /** * Revert a migration step. * Cannot revert initial schema - would lose all data. */ public function down(): void { // Cannot safely revert initial schema // Would require dropping all tables which would lose all data $this->db->query('SET FOREIGN_KEY_CHECKS = 0'); foreach ($this->db->listTables() as $table) { $this->db->query('DROP TABLE IF EXISTS `' . $table . '`'); } $this->db->query('SET FOREIGN_KEY_CHECKS = 1'); } }