feat(migration): move integrations from tenants to clients and update schema
This commit is contained in:
@@ -9,6 +9,7 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
|
if (! Schema::hasTable('client_integrations')) {
|
||||||
Schema::create('client_integrations', function (Blueprint $table): void {
|
Schema::create('client_integrations', function (Blueprint $table): void {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
|
$table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
|
||||||
@@ -22,7 +23,9 @@ return new class extends Migration
|
|||||||
->cascadeOnDelete();
|
->cascadeOnDelete();
|
||||||
$table->unique(['client_id', 'integration_code']);
|
$table->unique(['client_id', 'integration_code']);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Schema::hasTable('tenant_integration')) {
|
||||||
DB::table('tenant_integration')
|
DB::table('tenant_integration')
|
||||||
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
|
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
|
||||||
->select([
|
->select([
|
||||||
@@ -46,11 +49,15 @@ return new class extends Migration
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! Schema::hasColumn('integrations', 'requires_client_configuration')) {
|
||||||
Schema::table('integrations', function (Blueprint $table): void {
|
Schema::table('integrations', function (Blueprint $table): void {
|
||||||
$table->boolean('requires_client_configuration')->default(true);
|
$table->boolean('requires_client_configuration')->default(true);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Schema::hasColumn('integrations', 'requires_tenant_configuration')) {
|
||||||
DB::table('integrations')->update([
|
DB::table('integrations')->update([
|
||||||
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
|
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
|
||||||
]);
|
]);
|
||||||
@@ -58,6 +65,7 @@ return new class extends Migration
|
|||||||
Schema::table('integrations', function (Blueprint $table): void {
|
Schema::table('integrations', function (Blueprint $table): void {
|
||||||
$table->dropColumn('requires_tenant_configuration');
|
$table->dropColumn('requires_tenant_configuration');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Schema::dropIfExists('tenant_integration');
|
Schema::dropIfExists('tenant_integration');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user