diff --git a/assets/config.php b/assets/config.php index 7cf4b184..6e2b4c2c 100644 --- a/assets/config.php +++ b/assets/config.php @@ -37,7 +37,7 @@ return [ ], 'filesystem' => [ // https://stancl-tenancy.netlify.com/docs/filesystem-tenancy/ 'suffix_base' => 'tenant', - // Disks which should be suffixed with the suffix_base + tenant UUID. + // Disks which should be suffixed with the suffix_base + tenant id. 'disks' => [ 'local', 'public', diff --git a/src/CacheManager.php b/src/CacheManager.php index 286723d0..e361bc5c 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -10,7 +10,7 @@ class CacheManager extends BaseCacheManager { public function __call($method, $parameters) { - $tags = [config('tenancy.cache.tag_base') . tenant('uuid')]; + $tags = [config('tenancy.cache.tag_base') . tenant('id')]; if ($method === 'tags') { if (\count($parameters) !== 1) { diff --git a/src/Commands/Install.php b/src/Commands/Install.php index 3c10cedb..b25f2603 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -66,7 +66,7 @@ class Install extends Command */ Route::get('/', function () { - return 'This is your multi-tenant application. The uuid of the current tenant is ' . tenant('uuid'); + return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id'); }); " ); diff --git a/src/Commands/Migrate.php b/src/Commands/Migrate.php index d3e73be0..1a016eb4 100644 --- a/src/Commands/Migrate.php +++ b/src/Commands/Migrate.php @@ -50,7 +50,7 @@ class Migrate extends MigrateCommand } tenant()->all($this->option('tenants'))->each(function ($tenant) { - $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); + $this->line("Tenant: {$tenant['id']} ({$tenant['domain']})"); // See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection. // Database connections are cached by Illuminate\Database\ConnectionResolver. diff --git a/src/Commands/Rollback.php b/src/Commands/Rollback.php index 42cdcfbb..f8a40706 100644 --- a/src/Commands/Rollback.php +++ b/src/Commands/Rollback.php @@ -52,7 +52,7 @@ class Rollback extends RollbackCommand $this->input->setOption('database', 'tenant'); tenant()->all($this->option('tenants'))->each(function ($tenant) { - $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); + $this->line("Tenant: {$tenant['id']} ({$tenant['domain']})"); $this->database->connectToTenant($tenant); // Migrate diff --git a/src/Commands/Run.php b/src/Commands/Run.php index 2762cb66..b7e955ed 100644 --- a/src/Commands/Run.php +++ b/src/Commands/Run.php @@ -37,7 +37,7 @@ class Run extends Command } tenant()->all($this->option('tenants'))->each(function ($tenant) { - $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); + $this->line("Tenant: {$tenant['id']} ({$tenant['domain']})"); tenancy()->init($tenant['domain']); $callback = function ($prefix = '') { diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index 6350f5eb..38c064da 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -50,7 +50,7 @@ class Seed extends SeedCommand $this->input->setOption('database', 'tenant'); tenant()->all($this->option('tenants'))->each(function ($tenant) { - $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); + $this->line("Tenant: {$tenant['id']} ({$tenant['domain']})"); $this->database->connectToTenant($tenant); // Seed diff --git a/src/Commands/TenantList.php b/src/Commands/TenantList.php index 2db3cdd1..5a6bb98d 100644 --- a/src/Commands/TenantList.php +++ b/src/Commands/TenantList.php @@ -31,7 +31,7 @@ class TenantList extends Command { $this->info('Listing all tenants.'); tenancy()->all()->each(function ($tenant) { - $this->line("[Tenant] uuid: {$tenant['uuid']} @ {$tenant['domain']}"); + $this->line("[Tenant] id: {$tenant['id']} @ {$tenant['domain']}"); }); } } diff --git a/src/TenancyBootstrappers/QueueTenancyBootstrapper.php b/src/TenancyBootstrappers/QueueTenancyBootstrapper.php index 404d667e..e6b41241 100644 --- a/src/TenancyBootstrappers/QueueTenancyBootstrapper.php +++ b/src/TenancyBootstrappers/QueueTenancyBootstrapper.php @@ -44,12 +44,12 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper return []; } - [$uuid, $domain] = tenant()->get(['uuid', 'domain']); + [$id, $domain] = tenant()->get(['id', 'domain']); return [ - 'tenant_id' => $uuid, + 'tenant_id' => $id, 'tags' => [ - "tenant:$uuid", + "tenant:$id", "domain:$domain", ], ]; diff --git a/tests/BootstrapsTenancyTest.php b/tests/BootstrapsTenancyTest.php index 860b56d1..b8c24d37 100644 --- a/tests/BootstrapsTenancyTest.php +++ b/tests/BootstrapsTenancyTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Redis; +// todo rename class BootstrapsTenancyTest extends TestCase { public $autoInitTenancy = false; @@ -31,7 +31,7 @@ class BootstrapsTenancyTest extends TestCase $this->initTenancy(); foreach (config('tenancy.redis.prefixed_connections', ['default']) as $connection) { - $prefix = config('tenancy.redis.prefix_base') . tenant('uuid'); + $prefix = config('tenancy.redis.prefix_base') . tenant('id'); $client = Redis::connection($connection)->client(); $this->assertEquals($prefix, $client->getOption($client::OPT_PREFIX)); } @@ -49,10 +49,10 @@ class BootstrapsTenancyTest extends TestCase $this->initTenancy(); $new_storage_path = storage_path(); - $this->assertEquals($old_storage_path . '/' . config('tenancy.filesystem.suffix_base') . tenant('uuid'), $new_storage_path); + $this->assertEquals($old_storage_path . '/' . config('tenancy.filesystem.suffix_base') . tenant('id'), $new_storage_path); foreach (config('tenancy.filesystem.disks') as $disk) { - $suffix = config('tenancy.filesystem.suffix_base') . tenant('uuid'); + $suffix = config('tenancy.filesystem.suffix_base') . tenant('id'); $current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix(); if ($override = config("tenancy.filesystem.root_override.{$disk}")) { @@ -75,7 +75,7 @@ class BootstrapsTenancyTest extends TestCase $this->assertSame(['foo'], cache()->tags('foo')->getTags()->getNames()); $this->initTenancy(); - $expected = [config('tenancy.cache.tag_base') . tenant('uuid'), 'foo', 'bar']; + $expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo', 'bar']; $this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames()); } } diff --git a/tests/CacheManagerTest.php b/tests/CacheManagerTest.php index 0f790083..336060d6 100644 --- a/tests/CacheManagerTest.php +++ b/tests/CacheManagerTest.php @@ -9,20 +9,20 @@ class CacheManagerTest extends TestCase /** @test */ public function default_tag_is_automatically_applied() { - $this->assertArrayIsSubset([config('tenancy.cache.tag_base') . tenant('uuid')], cache()->tags('foo')->getTags()->getNames()); + $this->assertArrayIsSubset([config('tenancy.cache.tag_base') . tenant('id')], cache()->tags('foo')->getTags()->getNames()); } /** @test */ public function tags_are_merged_when_array_is_passed() { - $expected = [config('tenancy.cache.tag_base') . tenant('uuid'), 'foo', 'bar']; + $expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo', 'bar']; $this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames()); } /** @test */ public function tags_are_merged_when_string_is_passed() { - $expected = [config('tenancy.cache.tag_base') . tenant('uuid'), 'foo']; + $expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo']; $this->assertEquals($expected, cache()->tags('foo')->getTags()->getNames()); } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 577792d7..a7e57c98 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -49,7 +49,7 @@ class CommandsTest extends TestCase { $tenant = tenant()->create('test.localhost'); Artisan::call('tenants:migrate', [ - '--tenants' => [$tenant['uuid']], + '--tenants' => [$tenant['id']], ]); $this->assertFalse(Schema::hasTable('users')); @@ -106,11 +106,11 @@ class CommandsTest extends TestCase /** @test */ public function run_commands_works() { - $uuid = tenant()->create('run.localhost')['uuid']; + $id = tenant()->create('run.localhost')['id']; - Artisan::call('tenants:migrate', ['--tenants' => $uuid]); + Artisan::call('tenants:migrate', ['--tenants' => $id]); - $this->artisan("tenants:run foo --tenants=$uuid --argument='a=foo' --option='b=bar' --option='c=xyz'") + $this->artisan("tenants:run foo --tenants=$id --argument='a=foo' --option='b=bar' --option='c=xyz'") ->expectsOutput("User's name is Test command") ->expectsOutput('foo') ->expectsOutput('xyz'); diff --git a/tests/DataSeparationTest.php b/tests/DataSeparationTest.php index 3f52715d..64f627b4 100644 --- a/tests/DataSeparationTest.php +++ b/tests/DataSeparationTest.php @@ -21,7 +21,7 @@ class DataSeparationTest extends TestCase $tenant1 = tenancy()->create('tenant1.localhost'); $tenant2 = tenancy()->create('tenant2.localhost'); \Artisan::call('tenants:migrate', [ - '--tenants' => [$tenant1['uuid'], $tenant2['uuid']], + '--tenants' => [$tenant1['id'], $tenant2['id']], ]); tenancy()->init('tenant1.localhost'); @@ -54,7 +54,7 @@ class DataSeparationTest extends TestCase $tenant3 = tenancy()->create('tenant3.localhost'); \Artisan::call('tenants:migrate', [ - '--tenants' => [$tenant1['uuid'], $tenant3['uuid']], + '--tenants' => [$tenant1['id'], $tenant3['id']], ]); tenancy()->init('tenant3.localhost'); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 132f7163..ab79631d 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -30,7 +30,7 @@ class QueueTest extends TestCase dispatch(new TestJob()); Event::assertDispatched(JobProcessing::class, function ($event) { - return $event->job->payload()['tenant_uuid'] === tenant('uuid'); + return $event->job->payload()['tenant_id'] === tenant('id'); }); } } diff --git a/tests/ReidentificationTest.php b/tests/ReidentificationTest.php index 96edda8f..fb5d5083 100644 --- a/tests/ReidentificationTest.php +++ b/tests/ReidentificationTest.php @@ -25,7 +25,7 @@ class ReidentificationTest extends TestCase tenancy()->init('second.localhost'); foreach (config('tenancy.filesystem.disks') as $disk) { - $suffix = config('tenancy.filesystem.suffix_base') . tenant('uuid'); + $suffix = config('tenancy.filesystem.suffix_base') . tenant('id'); $current_path_prefix = \Storage::disk($disk)->getAdapter()->getPathPrefix(); if ($override = config("tenancy.filesystem.root_override.{$disk}")) { @@ -51,7 +51,7 @@ class ReidentificationTest extends TestCase tenant()->create('second.localhost'); tenancy()->init('second.localhost'); - $suffix = config('tenancy.filesystem.suffix_base') . tenant('uuid'); + $suffix = config('tenancy.filesystem.suffix_base') . tenant('id'); $this->assertSame($original . "/$suffix", storage_path()); } } diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index 74fe7bd4..a11eaa39 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -28,7 +28,7 @@ class TenantManagerTest extends TestCase tenant()->create('foo.localhost'); tenancy()->init('foo.localhost'); - $this->assertSame(tenant('uuid'), tenant()('uuid')); + $this->assertSame(tenant('id'), tenant()('id')); } /** @test */ @@ -38,7 +38,7 @@ class TenantManagerTest extends TestCase $this->assertNotSame($tenant, tenancy()->tenant); - tenancy()->initById($tenant['uuid']); + tenancy()->initById($tenant['id']); $this->assertSame($tenant, tenancy()->tenant); } @@ -64,7 +64,7 @@ class TenantManagerTest extends TestCase tenant()->create('dev.localhost'); tenancy()->init('dev.localhost'); - $this->assertSame(tenant()->tenant, tenant()->find(tenant('uuid'))); + $this->assertSame(tenant()->tenant, tenant()->find(tenant('id'))); } /** @test */ @@ -72,7 +72,7 @@ class TenantManagerTest extends TestCase { $tenant = tenant()->create('foo.localhost'); - $this->assertSame($tenant, tenancy()->getTenantById($tenant['uuid'])); + $this->assertSame($tenant, tenancy()->getTenantById($tenant['id'])); } /** @test */ @@ -87,9 +87,9 @@ class TenantManagerTest extends TestCase public function initById_returns_the_tenant() { $tenant = tenant()->create('foo.localhost'); - $uuid = $tenant['uuid']; + $id = $tenant['id']; - $this->assertSame($tenant, tenancy()->initById($uuid)); + $this->assertSame($tenant, tenancy()->initById($id)); } /** @test */ @@ -185,7 +185,7 @@ class TenantManagerTest extends TestCase public function tenant_can_be_deleted() { $tenant = tenant()->create('foo.localhost'); - tenant()->delete($tenant['uuid']); + tenant()->delete($tenant['id']); $this->assertSame([], tenancy()->all()->toArray()); $tenant = tenant()->create('foo.localhost'); @@ -207,7 +207,7 @@ class TenantManagerTest extends TestCase $tenant = tenant()->create('foo.localhost', $data); $tenant_data = $tenant; - unset($tenant_data['uuid']); + unset($tenant_data['id']); unset($tenant_data['domain']); $this->assertSame($data, $tenant_data); diff --git a/tests/TenantStorageTest.php b/tests/TenantStorageTest.php index 5f95411d..a6482eea 100644 --- a/tests/TenantStorageTest.php +++ b/tests/TenantStorageTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; +use Stancl\Tenancy\StorageDrivers\Database\TenantModel; use Stancl\Tenancy\StorageDrivers\DatabaseStorageDriver; use Stancl\Tenancy\StorageDrivers\RedisStorageDriver; use Stancl\Tenancy\Tenant; @@ -17,7 +18,7 @@ class TenantStorageTest extends TestCase $this->assertTrue(tenant()->all()->contains($abc)); - tenant()->delete($abc['uuid']); + tenant()->delete($abc['id']); $this->assertFalse(tenant()->all()->contains($abc)); } @@ -62,11 +63,11 @@ class TenantStorageTest extends TestCase public function put_works_on_a_tenant_different_than_the_current_one_when_two_args_are_used() { $tenant = tenant()->create('second.localhost'); - $uuid = $tenant['uuid']; + $id = $tenant['id']; - tenancy()->put('foo', 'bar', $uuid); + tenancy()->put('foo', 'bar', $id); - $this->assertSame('bar', tenancy()->get('foo', $uuid)); + $this->assertSame('bar', tenancy()->get('foo', $id)); $this->assertNotSame('bar', tenant('foo')); } @@ -74,15 +75,15 @@ class TenantStorageTest extends TestCase public function put_works_on_a_tenant_different_than_the_current_one_when_a_single_arg_is_used() { $tenant = tenant()->create('second.localhost'); - $uuid = $tenant['uuid']; + $id = $tenant['id']; $keys = ['foo', 'abc']; $vals = ['bar', 'xyz']; $data = \array_combine($keys, $vals); - tenancy()->put($data, null, $uuid); + tenancy()->put($data, null, $id); - $this->assertSame($vals, tenancy()->get($keys, $uuid)); + $this->assertSame($vals, tenancy()->get($keys, $id)); $this->assertNotSame($vals, tenancy()->get($keys)); $this->assertFalse(\array_intersect($data, tenant()->tenant) == $data); // assert array not subset } @@ -152,7 +153,7 @@ class TenantStorageTest extends TestCase public function tenant_model_uses_correct_connection() { config(['tenancy.storage.db.connection' => 'foo']); - $this->assertSame('foo', (new Tenant)->getConnectionName()); + $this->assertSame('foo', (new TenantModel)->getConnectionName()); } /** @test */ @@ -196,6 +197,6 @@ class TenantStorageTest extends TestCase tenancy()->put(['foo' => 'bar', 'abc' => 'xyz']); $this->assertSame(['bar', 'xyz'], tenancy()->get(['foo', 'abc'])); - $this->assertSame('bar', \DB::connection('central')->table('tenants')->where('uuid', tenant('uuid'))->first()->foo); + $this->assertSame('bar', \DB::connection('central')->table('tenants')->where('id', tenant('id'))->first()->foo); } }