fix(event): backfill active event social media
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('tenants')
|
||||
->whereNotNull('active_event_id')
|
||||
->orderBy('id')
|
||||
->chunk(100, function ($tenants): void {
|
||||
foreach ($tenants as $tenant) {
|
||||
$eventId = DB::table('events')
|
||||
->where('id', $tenant->active_event_id)
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->value('id');
|
||||
|
||||
if ($eventId === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows = DB::table('tenant_social_media')
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->get()
|
||||
->map(fn ($network): array => [
|
||||
'event_id' => $eventId,
|
||||
'social_media_code' => $network->social_media_code,
|
||||
'url' => $network->url,
|
||||
'orden' => $network->orden,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
])
|
||||
->all();
|
||||
|
||||
if ($rows !== []) {
|
||||
DB::table('event_social_media')->insertOrIgnore($rows);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// The backfilled rows may have been edited after migration; deleting them would lose data.
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user