Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Database group ignored on migration #5664

Closed
JanniGrabe opened this issue Feb 7, 2022 · 2 comments
Closed

Bug: Database group ignored on migration #5664

JanniGrabe opened this issue Feb 7, 2022 · 2 comments

Comments

@JanniGrabe
Copy link

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

@JanniGrabe JanniGrabe added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 7, 2022
@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 7, 2022
@kenjis
Copy link
Member

kenjis commented Feb 7, 2022

I don't think the current migration is designed that way you want.

@JanniGrabe
Copy link
Author

Thanks for clarifying, I modified it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants