diff --git a/system/Database/Config.php b/system/Database/Config.php index 92556c6d8fef..8c2a1cf52726 100644 --- a/system/Database/Config.php +++ b/system/Database/Config.php @@ -137,6 +137,16 @@ public static function seeder(?string $group = null) return new Seeder($config, static::connect($group)); } + /** + * Returns instance of Database Factory. + */ + public static function factory(): Database + { + static::ensureFactory(); + + return static::$factory; + } + /** * Ensures the database Connection Manager/Factory is loaded and ready to use. */ diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 241a9e6da5fa..ba279481a002 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -839,7 +839,8 @@ protected function migrate($direction, $migration): bool throw new RuntimeException($message); } - $instance = new $class(); + /** @var Migration $instance */ + $instance = new $class(Database::factory()->loadForge($this->db)); $group = $instance->getDBGroup() ?? config(Database::class)->defaultGroup; if (ENVIRONMENT !== 'testing' && $group === 'tests' && $this->groupFilter !== 'tests') {