feat: [account] tenant_id=1 계정과목을 KIS 5자리 표준으로 완전 교체

- 기존 3자리 코드 체계 삭제
- 서비스 표준(5자리 KIS) 458개 코드를 활성 상태로 복사
- 기존 전표 account_code 매핑은 수동 진행 예정
This commit is contained in:
김보곤
2026-03-17 11:13:51 +09:00
parent 921f1ecba7
commit ead546e268

View File

@@ -0,0 +1,68 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* tenant_id=1(코드브릿지엑스 본사)의 계정과목을 KIS 5자리 표준으로 완전 교체
*
* - 기존 3자리 코드 체계를 제거하고 서비스 표준(5자리 KIS)으로 통일
* - 기존 전표의 account_code 매핑은 수동으로 진행
* - 소스: tenant_id=287 (서비스 표준 시드 데이터)
*/
public function up(): void
{
// 소스 테넌트 (서비스 표준)
$sourceTenantId = DB::table('account_codes')
->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자리 데이터 복원 불가능)
// 필요 시 백업에서 복원
}
};