feat(events): associate purchases and integrations with events
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?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::table('events', function (Blueprint $table): void {
|
||||
$table->foreignId('client_id')
|
||||
->nullable()
|
||||
->after('id')
|
||||
->constrained('clients')
|
||||
->restrictOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('events', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('client_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')
|
||||
->nullable()
|
||||
->after('tenant_codigo')
|
||||
->constrained('events')
|
||||
->nullOnDelete();
|
||||
});
|
||||
|
||||
DB::table('compras')
|
||||
->orderBy('id')
|
||||
->each(function (object $purchase): void {
|
||||
$eventIds = DB::table('compra_items')
|
||||
->join('catalog_items', 'catalog_items.id', '=', 'compra_items.source_catalog_item_id')
|
||||
->where('compra_items.compra_id', $purchase->id)
|
||||
->whereNotNull('catalog_items.event_id')
|
||||
->distinct()
|
||||
->pluck('catalog_items.event_id');
|
||||
|
||||
if ($eventIds->count() === 1) {
|
||||
DB::table('compras')
|
||||
->where('id', $purchase->id)
|
||||
->update(['event_id' => $eventIds->first()]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const EVENT_TITLE = '26.º Fiesta de la Tradición y 4.º Encuentro de Agrupaciones Gauchas';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$clientId = DB::table('clients')
|
||||
->where('code', 'pyme_rural')
|
||||
->value('id');
|
||||
|
||||
if ($clientId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('events')
|
||||
->where('tenant_code', 'onticket')
|
||||
->where('title', self::EVENT_TITLE)
|
||||
->update(['client_id' => $clientId]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$clientId = DB::table('clients')
|
||||
->where('code', 'pyme_rural')
|
||||
->value('id');
|
||||
|
||||
if ($clientId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('events')
|
||||
->where('tenant_code', 'onticket')
|
||||
->where('title', self::EVENT_TITLE)
|
||||
->where('client_id', $clientId)
|
||||
->update(['client_id' => null]);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user