1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 08:44:04 +00:00
This commit is contained in:
Samuel Štancl 2019-02-26 22:53:15 +01:00
parent e46af3676f
commit be7e64af93
2 changed files with 13 additions and 5 deletions

View file

@ -49,8 +49,6 @@ class Migrate extends MigrateCommand
$this->input->setOption('database', 'tenant'); $this->input->setOption('database', 'tenant');
dd($this->option('tenants'));
tenant()->all($this->option('tenants'))->each(function ($tenant) { tenant()->all($this->option('tenants'))->each(function ($tenant) {
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
$this->database->connectToTenant($tenant); $this->database->connectToTenant($tenant);

View file

@ -19,10 +19,13 @@ class CommandsTest extends TestCase
/** @test */ /** @test */
public function migrate_command_doesnt_change_the_db_connection() public function migrate_command_doesnt_change_the_db_connection()
{ {
$this->assertFalse(Schema::hasTable('users'));
$old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); $old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
Artisan::call('tenants:migrate'); Artisan::call('tenants:migrate');
$new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); $new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
$this->assertFalse(Schema::hasTable('users'));
$this->assertEquals($old_connection_name, $new_connection_name); $this->assertEquals($old_connection_name, $new_connection_name);
$this->assertNotEquals('tenant', $new_connection_name); $this->assertNotEquals('tenant', $new_connection_name);
} }
@ -33,20 +36,27 @@ class CommandsTest extends TestCase
$this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('users'));
Artisan::call('tenants:migrate'); Artisan::call('tenants:migrate');
$this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('users'));
tenancy()->init(); tenancy()->init('localhost');
$this->assertTrue(Schema::hasTable('users')); $this->assertTrue(Schema::hasTable('users'));
} }
/** @test */ /** @test */
public function migrate_command_works_with_tenants_option() public function migrate_command_works_with_tenants_option()
{ {
// connection is sqlite
dump(Schema::getConnection()->getName());
$tenant = tenant()->create('test.localhost'); $tenant = tenant()->create('test.localhost');
Artisan::call('tenants:migrate', [ Artisan::call('tenants:migrate', [
'--tenants' => [$tenant['uuid']] '--tenants' => [$tenant['uuid']]
]); ]);
// connection should be tenant at this point. is still sqlite
dump(Schema::getConnection()->getName());
// if you remove line 47, connection will be tenant at this point
$this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('users'));
tenancy()->init(); tenancy()->init('localhost');
$this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('users'));
tenancy()->init('test.localhost'); tenancy()->init('test.localhost');
@ -58,7 +68,7 @@ class CommandsTest extends TestCase
{ {
Artisan::call('tenants:migrate'); Artisan::call('tenants:migrate');
$this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('users'));
tenancy()->init(); tenancy()->init('localhost');
$this->assertTrue(Schema::hasTable('users')); $this->assertTrue(Schema::hasTable('users'));
Artisan::call('tenants:rollback'); Artisan::call('tenants:rollback');
$this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('users'));