mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 19:14:03 +00:00
Simplify UUID models
This commit is contained in:
parent
974950c300
commit
90a0343223
1 changed files with 8 additions and 11 deletions
|
|
@ -8,17 +8,19 @@ use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
||||||
use Stancl\Tenancy\Events\TenancyEnded;
|
use Stancl\Tenancy\Events\TenancyEnded;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
use Stancl\Tenancy\Jobs\DeleteTenantsPostgresUser;
|
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\Jobs\CreatePostgresUserForTenant;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
|
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
|
||||||
use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel;
|
use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel;
|
||||||
use Stancl\Tenancy\Bootstrappers\Integrations\PostgresTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\Integrations\PostgresTenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
DB::purge('central');
|
DB::purge('central');
|
||||||
|
|
@ -44,7 +46,7 @@ beforeEach(function () {
|
||||||
|
|
||||||
// Drop all existing policies
|
// Drop all existing policies
|
||||||
foreach (DB::select('select * from pg_policies') as $policy) {
|
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());
|
Schema::dropIfExists($secondaryModel->getTable());
|
||||||
|
|
@ -182,6 +184,8 @@ test('queries are correctly scoped using RLS', function() {
|
||||||
|
|
||||||
trait UsesUuidAsPrimaryKey
|
trait UsesUuidAsPrimaryKey
|
||||||
{
|
{
|
||||||
|
use HasUuids;
|
||||||
|
|
||||||
protected static function boot()
|
protected static function boot()
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
@ -201,10 +205,7 @@ class UuidPost extends Model
|
||||||
{
|
{
|
||||||
use UsesUuidAsPrimaryKey, BelongsToTenant;
|
use UsesUuidAsPrimaryKey, BelongsToTenant;
|
||||||
|
|
||||||
public $incrementing = false;
|
|
||||||
public $table = 'uuid_posts';
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
protected $keyType = 'string';
|
|
||||||
|
|
||||||
public function uuid_comments(): HasMany
|
public function uuid_comments(): HasMany
|
||||||
{
|
{
|
||||||
|
|
@ -222,12 +223,8 @@ class UuidComment extends Model
|
||||||
use UsesUuidAsPrimaryKey;
|
use UsesUuidAsPrimaryKey;
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
protected $keyType = 'string';
|
|
||||||
|
|
||||||
public $incrementing = false;
|
public function uuid_post(): BelongsTo
|
||||||
public $table = 'uuid_comments';
|
|
||||||
|
|
||||||
public function uuid_post()
|
|
||||||
{
|
{
|
||||||
return $this->belongsTo(UuidPost::class);
|
return $this->belongsTo(UuidPost::class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue