info('Starting optimized theme migration...'); $legacyConn = DB::connection('mysql_second'); $query = $legacyConn->table('proof_airing_themes'); $totalCount = $query->count(); if ($totalCount === 0) { $this->warn('No themes found in legacy database.'); return; } $this->info("Found {$totalCount} legacy theme records."); $query->orderBy('id')->chunk(50, function ($chunk) { foreach ($chunk as $legacy) { $this->processTheme($legacy); } }); $this->newLine(); $this->info('Theme migration completed successfully!'); } /** * Process a single legacy theme record. */ private function processTheme($legacy): void { $idText = "[#{$legacy->id}]"; $idOutput = $legacy->deleted_at ? "{$idText}" : "{$idText}"; $this->output->write("{$idOutput} Processing: ".Str::limit($legacy->name, 40).'... '); try { DB::table('themes')->updateOrInsert( ['id' => $legacy->id], [ 'name' => $legacy->name, 'is_active' => IsActive::ACTIVE->value, 'created_at' => $legacy->created_at ?? now(), 'updated_at' => $legacy->updated_at ?? now(), 'deleted_at' => $legacy->deleted_at, ] ); $this->output->writeln('DONE'); } catch (\Exception $e) { $this->output->writeln('FAILED: '.$e->getMessage().''); } } }