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

uuid -> id (references in code)

This commit is contained in:
Samuel Štancl 2019-09-15 22:52:31 +02:00
parent a7bb709bd4
commit 79f912384b
17 changed files with 46 additions and 45 deletions

View file

@ -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',

View file

@ -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) {

View file

@ -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');
});
"
);

View file

@ -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.

View file

@ -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

View file

@ -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 = '') {

View file

@ -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

View file

@ -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']}");
});
}
}

View file

@ -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",
],
];

View file

@ -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());
}
}

View file

@ -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());
}

View file

@ -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');

View file

@ -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');

View file

@ -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');
});
}
}

View file

@ -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());
}
}

View file

@ -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);

View file

@ -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);
}
}