From 91a3823c7591219bae9fd736a4ac7ecb03be7c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Fri, 20 Mar 2026 14:55:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[db]=20daily=5Fwork=5Flogs=20sam?= =?UTF-8?q?=E2=86=92codebridge=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=9D=B4?= =?UTF-8?q?=EA=B4=80=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 2026_03_19_200000에서 existingTables 누락으로 데이터 미이관된 문제 해결 - 부모→자식 순서로 복사, 자식→부모 순서로 삭제 (FK 안전) - 건수 검증 후 sam 테이블 삭제 --- ..._migrate_daily_work_logs_to_codebridge.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 database/migrations/2026_03_20_120000_migrate_daily_work_logs_to_codebridge.php diff --git a/database/migrations/2026_03_20_120000_migrate_daily_work_logs_to_codebridge.php b/database/migrations/2026_03_20_120000_migrate_daily_work_logs_to_codebridge.php new file mode 100644 index 00000000..067972ad --- /dev/null +++ b/database/migrations/2026_03_20_120000_migrate_daily_work_logs_to_codebridge.php @@ -0,0 +1,84 @@ +copyOrder as $table) { + if (! Schema::hasTable($table)) { + continue; + } + + $samCount = DB::table($table)->count(); + if ($samCount === 0) { + continue; + } + + if (! Schema::connection($this->cb)->hasTable($table)) { + throw new \RuntimeException( + "[MIGRATION ABORT] codebridge.{$table} 테이블이 없습니다. " + .'2026_03_19_200000 마이그레이션을 먼저 실행하세요.' + ); + } + + $cbExisting = DB::connection($this->cb)->table($table)->count(); + if ($cbExisting > 0) { + continue; + } + + DB::connection($this->cb)->statement( + "INSERT INTO `{$cbDb}`.`{$table}` SELECT * FROM `{$samDb}`.`{$table}`" + ); + + $cbCount = DB::connection($this->cb)->table($table)->count(); + if ($samCount !== $cbCount) { + throw new \RuntimeException( + "[MIGRATION ABORT] 데이터 불일치! {$table}: sam={$samCount}, codebridge={$cbCount}" + ); + } + } + + // ─── Phase 2: sam 테이블 삭제 (자식 → 부모 순서) ─── + DB::statement('SET FOREIGN_KEY_CHECKS=0'); + foreach ($this->dropOrder as $table) { + Schema::dropIfExists($table); + } + DB::statement('SET FOREIGN_KEY_CHECKS=1'); + } + + public function down(): void + { + // 롤백은 수동 처리 — 데이터가 이미 codebridge에 있으므로 자동 롤백 불가 + } +};