From ead546e268c5766038fa734b0a3e8f6db652be30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Tue, 17 Mar 2026 11:13:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[account]=20tenant=5Fid=3D1=20=EA=B3=84?= =?UTF-8?q?=EC=A0=95=EA=B3=BC=EB=AA=A9=EC=9D=84=20KIS=205=EC=9E=90?= =?UTF-8?q?=EB=A6=AC=20=ED=91=9C=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EC=99=84?= =?UTF-8?q?=EC=A0=84=20=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 3자리 코드 체계 삭제 - 서비스 표준(5자리 KIS) 458개 코드를 활성 상태로 복사 - 기존 전표 account_code 매핑은 수동 진행 예정 --- ...enant1_account_codes_with_kis_standard.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 database/migrations/2026_03_17_111249_replace_tenant1_account_codes_with_kis_standard.php diff --git a/database/migrations/2026_03_17_111249_replace_tenant1_account_codes_with_kis_standard.php b/database/migrations/2026_03_17_111249_replace_tenant1_account_codes_with_kis_standard.php new file mode 100644 index 00000000..43bd5d63 --- /dev/null +++ b/database/migrations/2026_03_17_111249_replace_tenant1_account_codes_with_kis_standard.php @@ -0,0 +1,68 @@ +where('tenant_id', '!=', 1) + ->whereRaw('LENGTH(code) = 5') + ->value('tenant_id'); + + if (! $sourceTenantId) { + // 소스 테넌트가 없으면 스킵 + return; + } + + // 1. tenant_id=1 기존 데이터 전체 삭제 + DB::table('account_codes')->where('tenant_id', 1)->delete(); + + // 2. 소스 테넌트의 5자리 코드를 tenant_id=1로 복사 (활성 상태) + $sourceCodes = DB::table('account_codes') + ->where('tenant_id', $sourceTenantId) + ->whereRaw('LENGTH(code) = 5') + ->get(); + + $now = now(); + $inserts = $sourceCodes->map(fn ($row) => [ + 'tenant_id' => 1, + 'code' => $row->code, + 'name' => $row->name, + 'category' => $row->category, + 'sub_category' => $row->sub_category, + 'parent_code' => $row->parent_code, + 'depth' => $row->depth, + 'department_type' => $row->department_type, + 'description' => $row->description, + 'sort_order' => $row->sort_order, + 'is_active' => true, + 'created_at' => $now, + 'updated_at' => $now, + ])->toArray(); + + // chunk insert (한 번에 100건씩) + foreach (array_chunk($inserts, 100) as $chunk) { + DB::table('account_codes')->insert($chunk); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // 롤백 불가 (기존 3자리 데이터 복원 불가능) + // 필요 시 백업에서 복원 + } +};