1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 05:44:04 +00:00

Fix some tests

This commit is contained in:
Samuel Štancl 2019-09-16 16:57:55 +02:00
parent a632b545b7
commit 1532ccf019
15 changed files with 121 additions and 118 deletions

View file

@ -49,22 +49,23 @@ class Migrate extends MigrateCommand
return;
}
tenant()->all($this->option('tenants'))->each(function ($tenant) {
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
$originalTenant = tenancy()->getTenant();
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
$this->line("Tenant: {$tenant['id']}");
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
// Database connections are cached by Illuminate\Database\ConnectionResolver.
$this->input->setOption('database', 'tenant');
$this->database->connectToTenant($tenant); // todo test that this works with multiple tenants with MySQL
tenancy()->initialize($tenant); // todo test that this works with multiple tenants with MySQL
// Migrate
parent::handle();
});
if (tenancy()->initialized) {
tenancy()->switchDatabaseConnection();
if ($originalTenant) {
tenancy()->initialize($originalTenant);
} else {
$this->database->disconnect();
tenancy()->endTenancy();
}
}
}