Preserva base local aceite de identidade e acessos
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tenants', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('companies', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->restrictOnDelete();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
$table->unique(['tenant_id', 'id']);
|
||||
});
|
||||
Schema::create('company_memberships', function (Blueprint $table): void {
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedBigInteger('tenant_id');
|
||||
$table->unsignedBigInteger('company_id');
|
||||
$table->foreign(['tenant_id', 'company_id'])->references(['tenant_id', 'id'])->on('companies')->restrictOnDelete();
|
||||
$table->primary(['user_id', 'tenant_id', 'company_id']);
|
||||
});
|
||||
Schema::create('units', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('tenant_id');
|
||||
$table->unsignedBigInteger('company_id');
|
||||
$table->foreign(['tenant_id', 'company_id'])->references(['tenant_id', 'id'])->on('companies')->restrictOnDelete();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('units');
|
||||
Schema::dropIfExists('company_memberships');
|
||||
Schema::dropIfExists('companies');
|
||||
Schema::dropIfExists('tenants');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user