mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 12:24:04 +00:00
wip
This commit is contained in:
parent
e46af3676f
commit
be7e64af93
2 changed files with 13 additions and 5 deletions
|
|
@ -49,8 +49,6 @@ class Migrate extends MigrateCommand
|
|||
|
||||
$this->input->setOption('database', 'tenant');
|
||||
|
||||
dd($this->option('tenants'));
|
||||
|
||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
|
||||
$this->database->connectToTenant($tenant);
|
||||
|
|
|
|||
|
|
@ -19,10 +19,13 @@ class CommandsTest extends TestCase
|
|||
/** @test */
|
||||
public function migrate_command_doesnt_change_the_db_connection()
|
||||
{
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
|
||||
$old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
|
||||
Artisan::call('tenants:migrate');
|
||||
$new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
|
||||
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
$this->assertEquals($old_connection_name, $new_connection_name);
|
||||
$this->assertNotEquals('tenant', $new_connection_name);
|
||||
}
|
||||
|
|
@ -33,20 +36,27 @@ class CommandsTest extends TestCase
|
|||
$this->assertFalse(Schema::hasTable('users'));
|
||||
Artisan::call('tenants:migrate');
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
tenancy()->init();
|
||||
tenancy()->init('localhost');
|
||||
$this->assertTrue(Schema::hasTable('users'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function migrate_command_works_with_tenants_option()
|
||||
{
|
||||
// connection is sqlite
|
||||
dump(Schema::getConnection()->getName());
|
||||
|
||||
$tenant = tenant()->create('test.localhost');
|
||||
Artisan::call('tenants:migrate', [
|
||||
'--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'));
|
||||
tenancy()->init();
|
||||
tenancy()->init('localhost');
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
|
||||
tenancy()->init('test.localhost');
|
||||
|
|
@ -58,7 +68,7 @@ class CommandsTest extends TestCase
|
|||
{
|
||||
Artisan::call('tenants:migrate');
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
tenancy()->init();
|
||||
tenancy()->init('localhost');
|
||||
$this->assertTrue(Schema::hasTable('users'));
|
||||
Artisan::call('tenants:rollback');
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue