From 30c4483ce9949654ffb381a04284f32192b8facb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 2 Oct 2026 14:39:47 +0200 Subject: [PATCH] fix(database): clean orders employee service code and legacy site names - Strip site prefix and non-digits from service code in orders.employee JSON snapshot - Normalize legacy site names with spaces (LDC SERVICES, LDC VOLAILLES, LDC TER) in orders.employee and employees tables --- ...0_02_143800_fix_orders_employee_column.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 database/migrations/2026_10_02_143800_fix_orders_employee_column.php 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'); + } +};