feat: [archived-records] archived_records 테이블에 tenant_id 컬럼 추가

- 테넌트별 아카이브 필터링을 위한 tenant_id 컬럼 추가
- FK 제약조건 없음 (삭제된 테넌트 참조 가능)
- 기존 테넌트 레코드에 main_data.id로 tenant_id 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-01 00:40:17 +09:00
parent d60a29fb10
commit 47a6facb6b

View File

@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
* archived_records 테이블에 tenant_id 컬럼 추가
*
* NOTE: FK 제약조건 없음 (삭제된 테넌트를 참조할 수 있어야 함)
* - 테넌트 삭제 시: tenant_id = 삭제된 테넌트의 ID
* - 사용자 삭제 시: tenant_id = 현재 선택된 테넌트 ID (session)
*/
public function up(): void
{
Schema::table('archived_records', function (Blueprint $table) {
$table->unsignedBigInteger('tenant_id')->nullable()->after('record_type');
$table->index('tenant_id');
});
// 기존 데이터 처리: tenant 타입의 경우 main_data에서 id 추출
DB::statement("
UPDATE archived_records
SET tenant_id = JSON_UNQUOTE(JSON_EXTRACT(main_data, '$.id'))
WHERE record_type = 'tenant' AND tenant_id IS NULL
");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('archived_records', function (Blueprint $table) {
$table->dropIndex(['tenant_id']);
$table->dropColumn('tenant_id');
});
}
};