feat(catalog): add event_id to catalog items and backfill existing records
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('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')
|
||||
->nullable()
|
||||
->after('tenant_code')
|
||||
->constrained('events')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('tenants')
|
||||
->whereIn('codigo', ['desfile_pura_tendencia', 'fiesta_futbol_infantil'])
|
||||
->whereNotNull('active_event_id')
|
||||
->get(['codigo', 'active_event_id'])
|
||||
->each(function (object $tenant): void {
|
||||
DB::table('catalog_items')
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->update(['event_id' => $tenant->active_event_id]);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// The previous event associations cannot be recovered after this backfill.
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user