Skip to content

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

@Ukuser36

Description

@Ukuser36

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for infoIssues or pull requests that need further clarification from the author

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions