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

[9.x] Custom database migration in 9.21.0 does not work like it did in 9.20.0 #43325

Closed
streamingsystems opened this issue Jul 20, 2022 · 3 comments · Fixed by #43326
Closed
Assignees
Labels

Comments

@streamingsystems
Copy link

streamingsystems commented Jul 20, 2022

  • Laravel Version: 9.21.0
  • PHP Version: 8.1.8
  • Database Driver & Version: Mysql

Description:

Hi,

I have my own database migration for a multi-tenant system. This has been working for years (since Laravel 6) and all of a sudden when I upgraded from 9.20.0 to 9.21.0 it broke.


Each of my tenants has their own database and I run a migration on the new database to create all of the tables.

It used to run my migrations perfectly. Now, it does create a migrations table in the tenant database with all of the migration files as rows, but none of the actual tables are created. It's an empty database except for a single "migrations" table.


// This is an artisan command

protected $migrator;

public function __construct()
{
		parent::__construct();
        $this->migrator = app('migrator');
 }

public function handle()
{
		// up here I get a Tenant and set it to $tenant
		$this->migrate($tenant);
}

private function migrate(Tenant $tenant)
    {
        $this->prepareDatabase($tenant);
        $databasePath = database_path('migrations/tenants');  // this directory has all of the tenant-specific migration files
        Log::debug("Running migration for databasePath: $databasePath");
        $this->migrator->run($databasePath, []);
    }

    protected function prepareDatabase(Tenant $tenant)
    {
        $this->migrator->setConnection(Config::get('database.tenant_default'));
        Config::set('database.connections.tenant-remote.database', $tenant->getDatabaseName());
        if (!$this->migrator->repositoryExists()) {
            Log::debug("Repository does not exist, running migrate:install");
            $this->call('migrate:install');
        }
    }

I was looking through the fixes added to this version and can't seem to figure out what would have broken my code but when I revert the framework back to 9.20.0 it does work like it always has, but when I bring it back up to 9.21.0, it no longer creates my database tables as it should.

@nunomaduro
Copy link
Member

Found the issue, working on the fix right now.

@nunomaduro nunomaduro changed the title Custom database migration in 9.21.0 does not work like it did in 9.20.0 [9.x] Custom database migration in 9.21.0 does not work like it did in 9.20.0 Jul 20, 2022
@nunomaduro
Copy link
Member

@streamingsystems We already have prepared the fix for this issue. Taylor will review it soon.

@streamingsystems
Copy link
Author

Sounds great, thanks guys much appreciated. I thought I was going crazy for a few minutes this morning :)

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

Successfully merging a pull request may close this issue.

2 participants