Skip to content

Bug: Database group ignored on migration #5664

@JanniGrabe

Description

@JanniGrabe

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

  1. Define two databases in Database config, e.g. $default and $db2
  2. Create a migration class without specifying $DBGroup
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions