refactor(event): move event configuration onto tenant
This commit is contained in:
125
database/migrations/2026_08_07_000000_move_event_onto_tenant.php
Normal file
125
database/migrations/2026_08_07_000000_move_event_onto_tenant.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?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('tenants', function (Blueprint $table): void {
|
||||
$table->string('event_title')->nullable()->after('nombre');
|
||||
$table->string('event_location')->nullable()->after('event_title');
|
||||
});
|
||||
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->string('tenant_code')->nullable()->after('id');
|
||||
});
|
||||
|
||||
DB::table('tenants')
|
||||
->whereNotNull('active_event_id')
|
||||
->orderBy('id')
|
||||
->each(function (object $tenant): void {
|
||||
$event = DB::table('events')->where('id', $tenant->active_event_id)->first();
|
||||
|
||||
if ($event === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update([
|
||||
'event_title' => $event->name,
|
||||
'event_location' => $event->address,
|
||||
]);
|
||||
});
|
||||
|
||||
DB::table('events')->orderBy('id')->each(function (object $event): void {
|
||||
DB::table('event_dates')
|
||||
->where('event_id', $event->id)
|
||||
->update(['tenant_code' => $event->tenant_code]);
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('active_event_id');
|
||||
});
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
});
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
});
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
$table->string('tenant_code')->nullable(false)->change();
|
||||
$table->foreign('tenant_code')
|
||||
->references('codigo')
|
||||
->on('tenants')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::dropIfExists('events');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::create('events', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_code');
|
||||
$table->string('name');
|
||||
$table->string('address');
|
||||
$table->foreign('tenant_code')
|
||||
->references('codigo')
|
||||
->on('tenants')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('active_event_id')->nullable();
|
||||
});
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
|
||||
DB::table('tenants')->orderBy('id')->each(function (object $tenant): void {
|
||||
if ($tenant->event_title === null && $tenant->event_location === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventId = DB::table('events')->insertGetId([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'name' => $tenant->event_title ?? $tenant->nombre,
|
||||
'address' => $tenant->event_location ?? '',
|
||||
]);
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update(['active_event_id' => $eventId]);
|
||||
DB::table('catalog_items')->where('tenant_code', $tenant->codigo)->update(['event_id' => $eventId]);
|
||||
DB::table('compras')->where('tenant_codigo', $tenant->codigo)->update(['event_id' => $eventId]);
|
||||
DB::table('event_dates')->where('tenant_code', $tenant->codigo)->update(['event_id' => $eventId]);
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreign('active_event_id')->references('id')->on('events')->nullOnDelete();
|
||||
$table->dropColumn(['event_title', 'event_location']);
|
||||
});
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreign('event_id')->references('id')->on('events')->nullOnDelete();
|
||||
});
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->foreign('event_id')->references('id')->on('events')->nullOnDelete();
|
||||
});
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->dropForeign(['tenant_code']);
|
||||
$table->dropColumn('tenant_code');
|
||||
$table->foreign('event_id')->references('id')->on('events')->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('variantes', function (Blueprint $table): void {
|
||||
$table->index(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropUnique(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->unique(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropIndex(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -12,7 +12,6 @@ use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Services\CatalogService;
|
||||
use App\Domains\Event\Models\Event;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Enums\ValidityTimeType;
|
||||
use App\Domains\Ticket\Models\ValidityTime;
|
||||
@@ -38,18 +37,15 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
->update(['categoria_id' => null]);
|
||||
Category::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||
|
||||
$event = Event::query()->updateOrCreate(
|
||||
[
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'name' => 'Fiesta Nacional del Fútbol Infantil',
|
||||
],
|
||||
['address' => 'Sunchales, Santa Fe'],
|
||||
);
|
||||
$event->dates()->delete();
|
||||
$tenant->update([
|
||||
'event_title' => 'Fiesta Nacional del Fútbol Infantil',
|
||||
'event_location' => 'Sunchales, Santa Fe',
|
||||
]);
|
||||
$tenant->eventDates()->delete();
|
||||
|
||||
$eventDates = collect(['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'])
|
||||
->mapWithKeys(function (string $date) use ($event): array {
|
||||
$eventDate = $event->dates()->create([
|
||||
->mapWithKeys(function (string $date) use ($tenant): array {
|
||||
$eventDate = $tenant->eventDates()->create([
|
||||
'date' => $date,
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
@@ -58,9 +54,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
return [$date => $eventDate];
|
||||
});
|
||||
|
||||
$tenant->active_event_id = $event->id;
|
||||
$tenant->save();
|
||||
|
||||
$ticketCategory = Category::query()->firstOrCreate([
|
||||
'nombre' => 'Entradas',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
@@ -89,7 +82,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
|
||||
$generalAdmission = $this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'category_id' => $ticketCategory->id,
|
||||
'slug' => 'entrada-general',
|
||||
@@ -121,7 +113,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
foreach ($items as $item) {
|
||||
$createdItems[$item['slug']] = $this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'descripcion' => $item['descripcion'] ?? $item['nombre'],
|
||||
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
||||
@@ -133,7 +124,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
|
||||
$this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'type' => CatalogItemType::Bundle->value,
|
||||
'slug' => 'entrada-general-todos-los-dias',
|
||||
@@ -152,7 +142,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
|
||||
$this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'type' => CatalogItemType::Bundle->value,
|
||||
'slug' => 'combo-2-panchos-2-hamburguesas',
|
||||
|
||||
Reference in New Issue
Block a user