From 90a034322381c587f91295e397c4f8c3d918a6a6 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 10 May 2023 13:07:08 +0200 Subject: [PATCH] Simplify UUID models --- tests/PostgresTest.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/PostgresTest.php b/tests/PostgresTest.php index 05e5fe23..3ab5680d 100644 --- a/tests/PostgresTest.php +++ b/tests/PostgresTest.php @@ -8,17 +8,19 @@ use Stancl\Tenancy\Tests\Etc\Tenant; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasMany; use Stancl\Tenancy\Events\TenancyEnded; use Illuminate\Database\Schema\Blueprint; use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Jobs\DeleteTenantsPostgresUser; +use Illuminate\Database\Eloquent\Concerns\HasUuids; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Stancl\Tenancy\Jobs\CreatePostgresUserForTenant; use Stancl\Tenancy\Listeners\RevertToCentralContext; +use Stancl\Tenancy\Database\Concerns\BelongsToTenant; use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel; use Stancl\Tenancy\Bootstrappers\Integrations\PostgresTenancyBootstrapper; -use Stancl\Tenancy\Database\Concerns\BelongsToTenant; beforeEach(function () { DB::purge('central'); @@ -44,7 +46,7 @@ beforeEach(function () { // Drop all existing policies foreach (DB::select('select * from pg_policies') as $policy) { - DB::statement("DROP POLICY IF EXISTS {$policy->policyname} ON {$policy->tablename};"); + DB::statement("DROP POLICY IF EXISTS {$policy->policyname} ON {$policy->tablename}"); } Schema::dropIfExists($secondaryModel->getTable()); @@ -182,6 +184,8 @@ test('queries are correctly scoped using RLS', function() { trait UsesUuidAsPrimaryKey { + use HasUuids; + protected static function boot() { parent::boot(); @@ -201,10 +205,7 @@ class UuidPost extends Model { use UsesUuidAsPrimaryKey, BelongsToTenant; - public $incrementing = false; - public $table = 'uuid_posts'; protected $guarded = []; - protected $keyType = 'string'; public function uuid_comments(): HasMany { @@ -222,12 +223,8 @@ class UuidComment extends Model use UsesUuidAsPrimaryKey; protected $guarded = []; - protected $keyType = 'string'; - public $incrementing = false; - public $table = 'uuid_comments'; - - public function uuid_post() + public function uuid_post(): BelongsTo { return $this->belongsTo(UuidPost::class); }