diff --git a/database/migrations/2025_12_01_002115_add_tenant_id_to_archived_records.php b/database/migrations/2025_12_01_002115_add_tenant_id_to_archived_records.php new file mode 100644 index 0000000..70f5f95 --- /dev/null +++ b/database/migrations/2025_12_01_002115_add_tenant_id_to_archived_records.php @@ -0,0 +1,43 @@ +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'); + }); + } +}; \ No newline at end of file