diff --git a/database/migrations/2026_10_02_143800_fix_orders_employee_column.php b/database/migrations/2026_10_02_143800_fix_orders_employee_column.php new file mode 100644 index 00000000..71ea7c97 --- /dev/null +++ b/database/migrations/2026_10_02_143800_fix_orders_employee_column.php @@ -0,0 +1,68 @@ +whereNotNull('employee') + ->orderBy('id') + ->chunk(500, function ($orders): void { + foreach ($orders as $order) { + $data = json_decode((string) $order->employee, true); + if (! is_array($data)) { + continue; + } + + $site = $data['site'] ?? ''; + $site = match ($site) { + 'LDC SERVICES' => 'LDCSER', + 'LDC VOLAILLES' => 'LDCVOL', + 'LDC TER' => 'LDCTER', + default => $site, + }; + $data['site'] = $site; + + $service = $data['service'] ?? ''; + $data['service'] = (string) Str::of((string) $service) + ->replaceFirst((string) $site, '') + ->replaceMatches('/[^\d]/', ''); + + DB::table('orders') + ->where('id', $order->id) + ->update([ + 'employee' => json_encode($data, JSON_THROW_ON_ERROR), + ]); + } + }); + + DB::table('employees') + ->where('site', 'LDC SERVICES') + ->update(['site' => 'LDCSER']); + + DB::table('employees') + ->where('site', 'LDC VOLAILLES') + ->update(['site' => 'LDCVOL']); + + DB::table('employees') + ->where('site', 'LDC TER') + ->update(['site' => 'LDCTER']); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + throw new \Error('WONT ROLLBACK'); + } +};