-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
PHP Version
8.0
CodeIgniter4 Version
4.1.8
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MySQL
What happened?
The 'group' parameter on $migration->latest($group) or php spark migrate -g group is being overwritten by the default database group or the $DBGroup of the Migration instance in MigrationRunner (migrate function, line 832):
$instance = new $class();
$group = $instance->getDBGroup() ?? config('Database')->defaultGroup;
Thus, making it impossible to dynamically run migrations against other/multiple database groups. In my use case, I have individual databases for each language version of my website, and I would like to run the same migrations against all of them by looping through the databases.
Steps to Reproduce
- Define two databases in Database config, e.g.
$defaultand$db2 - Create a migration class without specifying
$DBGroup - Create a migration controller and pass a database connection to the migration service, run migrations with db2:
$db = Database::connect('db2');
$migrate = Services::migrations(null, $db, false);
$migrate->latest('db2');
OR run php spark migrate -g db2
4. Check database and you'll see that the migrations were created on $default and not the specified $db2.
Expected Output
$db2 migrated and not $default, so that I can dynamically set the database group without hardcoding it into the Migration class.
Anything else?
No response