Skip to content

Database migration table not correctly created when a non-default database connection is used #1531

Description

@hwiesmann

name: Bug report
about: Database migration not working when a non-default database connection is used


Describe the bug
Assuming that the passed connection interface $db is not equivalent to the default connection interface and no migration table exists the following code creates a migration table in the default database or crashes with an exception (in case the default connection interface is not initialised):

$migrate = \Config\Services::migrations(null,$db); // migration configuration must allow/enable migration!

The reason for this behaviour lies in MigrationRunner's ensureTable() function. It checks correctly if a migration table exists in the passed database.
if ($this->db->tableExists($this->table)) { return; }

But afterwards a forge variable is used with default connection settings to create the migration table. This is not correct.

The code

$forge = \Config\Database::forge();

should be replaced by

$forge = new \CodeIgniter\Database\Forge($this->db);

I believe.

CodeIgniter 4 version
CodeIgniter 4.0.0 Alpha 2

Affected module(s)
MigrationRunner.php

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseIssues or pull requests that affect the database layer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions