diff --git a/assets/config.php b/assets/config.php index c5c89c5b..00835cc7 100644 --- a/assets/config.php +++ b/assets/config.php @@ -25,7 +25,7 @@ return [ // 'localhost', ], 'database' => [ - 'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection. // todo2 test this + 'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection. 'prefix' => 'tenant', 'suffix' => '', ], diff --git a/src/Commands/Migrate.php b/src/Commands/Migrate.php index 7f68e37b..cf7b1c26 100644 --- a/src/Commands/Migrate.php +++ b/src/Commands/Migrate.php @@ -56,7 +56,7 @@ class Migrate extends MigrateCommand // See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection. // Database connections are cached by Illuminate\Database\ConnectionResolver. $this->input->setOption('database', 'tenant'); - tenancy()->initialize($tenant); // todo2 test that this works with multiple tenants with MySQL + tenancy()->initialize($tenant); // Migrate parent::handle(); diff --git a/tests/DatabaseManagerTest.php b/tests/DatabaseManagerTest.php index 1cf33ec4..bcc8de12 100644 --- a/tests/DatabaseManagerTest.php +++ b/tests/DatabaseManagerTest.php @@ -31,4 +31,19 @@ class DatabaseManagerTest extends TestCase $this->assertSame(config('database.connections.fooconn.database'), database_path('foodb')); } + + /** @test */ + public function the_default_db_is_used_when_based_on_is_null() + { + $this->assertSame('sqlite', config('database.default')); + config([ + 'database.connections.sqlite.foo' => 'bar', + 'tenancy.database.based_on' => null, + ]); + + tenancy()->init('test.localhost'); + + $this->assertSame('tenant', config('database.default')); + $this->assertSame('bar', config('database.connections.' . config('database.default') . '.foo')); + } }