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: Migration runner allows a $db but its never passed to the Migration files #8060

Closed
Ukuser36 opened this issue Oct 18, 2023 · 1 comment · Fixed by #8221
Closed

Bug: Migration runner allows a $db but its never passed to the Migration files #8060

Ukuser36 opened this issue Oct 18, 2023 · 1 comment · Fixed by #8221
Labels
waiting for info Issues or pull requests that need further clarification from the author

Comments

@Ukuser36
Copy link

PHP Version

8.0

CodeIgniter4 Version

4.3.4

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

Mysql

What happened?

When running a new MigrationRunner($config, $db); we are allowed to pass in a $db as the second param. However this $db is never passed to the actual migration files which means that it will fall back to the default one when running latest/up/regress etc. Furthermore, it can't be assumed that $db is a group because it could be a custom config.

Steps to Reproduce

  1. Create a $group and pass it to $forge = \Config\Database::forge($group);
  2. Run a migration file and outtput $this->forge and you'll see it reverts to the default

Expected Output

The migration files should be using the same $db group / config as the Migration runner.

The solution is to:

  1. Amend MigrationRunner $instance = new $class(Database::forge($this->db));
  2. Within your Migration files add a construct which calls the parent.
	public function __construct($forge = null){
		if ($forge) parent::__construct($forge);
	}

Anything else?

No response

@Ukuser36 Ukuser36 added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 18, 2023
@kenjis
Copy link
Member

kenjis commented Oct 18, 2023

The migration files should be using the same $db group / config as the Migration runner.

Why do you think so?

Passing a non-default DB group to MigrationRunner seems like a misuse.
Why is it changeable? Only for testing?

See also #7894 (comment)

@kenjis kenjis added the waiting for info Issues or pull requests that need further clarification from the author label Oct 21, 2023
@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants