merge: client-owned integrations into dev
This commit is contained in:
@@ -20,7 +20,6 @@ class ClientResource extends JsonResource
|
||||
'codigo' => $tenant->codigo,
|
||||
'nombre' => $tenant->nombre,
|
||||
'dominio' => $tenant->dominio,
|
||||
'base_path' => $tenant->base_path,
|
||||
])),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -9,35 +9,27 @@ return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('clients')) {
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
if (! Schema::hasColumn('tenants', 'client_id')) {
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('client_id')->nullable()->after('id')->constrained('clients')->restrictOnDelete();
|
||||
});
|
||||
}
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('client_id')->nullable()->after('id')->constrained('clients')->restrictOnDelete();
|
||||
});
|
||||
|
||||
DB::table('tenants')
|
||||
->select(['id', 'codigo', 'nombre', 'created_at', 'updated_at'])
|
||||
->orderBy('id')
|
||||
->each(function (object $tenant): void {
|
||||
$clientId = DB::table('clients')->where('code', $tenant->codigo)->value('id');
|
||||
|
||||
if ($clientId === null) {
|
||||
$clientId = DB::table('clients')->insertGetId([
|
||||
'code' => $tenant->codigo,
|
||||
'name' => $tenant->nombre,
|
||||
'created_at' => $tenant->created_at ?? now(),
|
||||
'updated_at' => $tenant->updated_at ?? now(),
|
||||
]);
|
||||
}
|
||||
$clientId = DB::table('clients')->insertGetId([
|
||||
'code' => $tenant->codigo,
|
||||
'name' => $tenant->nombre,
|
||||
'created_at' => $tenant->created_at ?? now(),
|
||||
'updated_at' => $tenant->updated_at ?? now(),
|
||||
]);
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update(['client_id' => $clientId]);
|
||||
});
|
||||
|
||||
@@ -9,63 +9,55 @@ 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();
|
||||
$table->string('integration_code');
|
||||
$table->longText('integration_data')->nullable();
|
||||
$table->timestamps();
|
||||
Schema::create('client_integrations', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
|
||||
$table->string('integration_code');
|
||||
$table->longText('integration_data')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('integration_code')
|
||||
->references('integration_code')
|
||||
->on('integrations')
|
||||
->cascadeOnDelete();
|
||||
$table->unique(['client_id', 'integration_code']);
|
||||
$table->foreign('integration_code')
|
||||
->references('integration_code')
|
||||
->on('integrations')
|
||||
->cascadeOnDelete();
|
||||
$table->unique(['client_id', 'integration_code']);
|
||||
});
|
||||
|
||||
DB::table('tenant_integration')
|
||||
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
|
||||
->select([
|
||||
'tenants.client_id',
|
||||
'tenant_integration.integration_code',
|
||||
'tenant_integration.integration_data',
|
||||
'tenant_integration.created_at',
|
||||
'tenant_integration.updated_at',
|
||||
])
|
||||
->orderBy('tenant_integration.id')
|
||||
->each(function (object $configuration): void {
|
||||
DB::table('client_integrations')->updateOrInsert(
|
||||
[
|
||||
'client_id' => $configuration->client_id,
|
||||
'integration_code' => $configuration->integration_code,
|
||||
],
|
||||
[
|
||||
'integration_data' => $configuration->integration_data,
|
||||
'created_at' => $configuration->created_at,
|
||||
'updated_at' => $configuration->updated_at,
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('tenant_integration')) {
|
||||
DB::table('tenant_integration')
|
||||
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
|
||||
->select([
|
||||
'tenants.client_id',
|
||||
'tenant_integration.integration_code',
|
||||
'tenant_integration.integration_data',
|
||||
'tenant_integration.created_at',
|
||||
'tenant_integration.updated_at',
|
||||
])
|
||||
->orderBy('tenant_integration.id')
|
||||
->each(function (object $configuration): void {
|
||||
DB::table('client_integrations')->updateOrInsert(
|
||||
[
|
||||
'client_id' => $configuration->client_id,
|
||||
'integration_code' => $configuration->integration_code,
|
||||
],
|
||||
[
|
||||
'integration_data' => $configuration->integration_data,
|
||||
'created_at' => $configuration->created_at,
|
||||
'updated_at' => $configuration->updated_at,
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
Schema::table('integrations', function (Blueprint $table): void {
|
||||
$table->boolean('requires_client_configuration')->default(true);
|
||||
});
|
||||
|
||||
if (! Schema::hasColumn('integrations', 'requires_client_configuration')) {
|
||||
Schema::table('integrations', function (Blueprint $table): void {
|
||||
$table->boolean('requires_client_configuration')->default(true);
|
||||
});
|
||||
}
|
||||
DB::table('integrations')->update([
|
||||
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
|
||||
]);
|
||||
|
||||
if (Schema::hasColumn('integrations', 'requires_tenant_configuration')) {
|
||||
DB::table('integrations')->update([
|
||||
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
|
||||
]);
|
||||
|
||||
Schema::table('integrations', function (Blueprint $table): void {
|
||||
$table->dropColumn('requires_tenant_configuration');
|
||||
});
|
||||
}
|
||||
Schema::table('integrations', function (Blueprint $table): void {
|
||||
$table->dropColumn('requires_tenant_configuration');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('tenant_integration');
|
||||
}
|
||||
|
||||
@@ -40,11 +40,7 @@ class DesfilePuraTendenciaSeeder extends Seeder
|
||||
$tenant = Tenant::query()->where('codigo', self::TENANT_CODE)->first();
|
||||
|
||||
if ($tenant) {
|
||||
$tenant->update([
|
||||
'client_id' => $client->id,
|
||||
'cart_editing_enabled' => false,
|
||||
'display_cart_item_images' => false,
|
||||
]);
|
||||
$tenant->update(['client_id' => $client->id]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ class TenantSeeder extends Seeder
|
||||
{
|
||||
private const ONTICKET_CLIENT_CODE = 'onticket';
|
||||
|
||||
private const SONDER_CLIENT_CODE = 'sonder';
|
||||
|
||||
private const SOCIAL_MEDIA = [
|
||||
[
|
||||
'code' => 'instagram',
|
||||
@@ -43,6 +45,11 @@ class TenantSeeder extends Seeder
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$sonderClient = Client::query()->firstOrCreate(
|
||||
['code' => self::SONDER_CLIENT_CODE],
|
||||
['name' => 'Sonder'],
|
||||
);
|
||||
|
||||
$onTicketClient = Client::query()->firstOrCreate(
|
||||
['code' => self::ONTICKET_CLIENT_CODE],
|
||||
['name' => 'OnTicket'],
|
||||
@@ -55,6 +62,7 @@ class TenantSeeder extends Seeder
|
||||
->delete();
|
||||
|
||||
$this->tenantService->create([
|
||||
'client_id' => $sonderClient->id,
|
||||
'codigo' => 'sonder',
|
||||
'nombre' => 'Sonder',
|
||||
'dominio' => 'localhost',
|
||||
|
||||
Reference in New Issue
Block a user