refactor(integrations): move configuration ownership to clients

This commit is contained in:
ncoronel 2026-08-18 16:16:39 -03:00
parent 38e87fff6c
commit ced7d594e8
2 changed files with 51 additions and 52 deletions

View File

@ -2,6 +2,7 @@
namespace App\Domains\Client\Models;
use App\Domains\Integration\Models\ClientIntegration;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
@ -20,4 +21,10 @@ class Client extends Model
{
return $this->hasMany(Tenant::class);
}
/** @return HasMany<ClientIntegration, $this> */
public function integrations(): HasMany
{
return $this->hasMany(ClientIntegration::class);
}
}

View File

@ -9,7 +9,6 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('client_integrations')) {
Schema::create('client_integrations', function (Blueprint $table): void {
$table->id();
$table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
@ -23,9 +22,7 @@ return new class extends Migration
->cascadeOnDelete();
$table->unique(['client_id', 'integration_code']);
});
}
if (Schema::hasTable('tenant_integration')) {
DB::table('tenant_integration')
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
->select([
@ -49,15 +46,11 @@ return new class extends Migration
],
);
});
}
if (! Schema::hasColumn('integrations', 'requires_client_configuration')) {
Schema::table('integrations', function (Blueprint $table): void {
$table->boolean('requires_client_configuration')->default(true);
});
}
if (Schema::hasColumn('integrations', 'requires_tenant_configuration')) {
DB::table('integrations')->update([
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
]);
@ -65,7 +58,6 @@ return new class extends Migration
Schema::table('integrations', function (Blueprint $table): void {
$table->dropColumn('requires_tenant_configuration');
});
}
Schema::dropIfExists('tenant_integration');
}