From 08521f9c48da70a36667bc83bb75c24a32ea73cb Mon Sep 17 00:00:00 2001 From: hskwon Date: Tue, 11 Nov 2025 23:22:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AD=EC=A0=9C=EB=90=9C=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=B0=B1=EC=97=85=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - archived_records 테이블: 삭제된 tenant/user 메인 데이터 저장 - archived_record_relations 테이블: 관련 테이블 데이터 저장 - 읽기 전용 백업 시스템으로 복원 기능 없음 - 스키마 버전 관리 및 삭제자 추적 기능 --- ..._225245_create_archived_records_tables.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 database/migrations/2025_11_11_225245_create_archived_records_tables.php diff --git a/database/migrations/2025_11_11_225245_create_archived_records_tables.php b/database/migrations/2025_11_11_225245_create_archived_records_tables.php new file mode 100644 index 0000000..050dad2 --- /dev/null +++ b/database/migrations/2025_11_11_225245_create_archived_records_tables.php @@ -0,0 +1,57 @@ +id(); + $table->enum('record_type', ['tenant', 'user'])->comment('레코드 타입'); + $table->unsignedBigInteger('original_id')->comment('원본 레코드 ID'); + $table->json('main_data')->comment('메인 테이블 데이터 (JSON)'); + $table->string('schema_version', 50)->default('v1.0')->comment('스키마 버전'); + $table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자 ID'); + $table->timestamp('deleted_at')->comment('삭제 일시'); + $table->text('notes')->nullable()->comment('삭제 사유/비고'); + $table->timestamps(); + + $table->index(['record_type', 'original_id']); + $table->index('deleted_at'); + $table->index('deleted_by'); + }); + + // 삭제된 레코드의 관련 테이블 데이터 + Schema::create('archived_record_relations', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('archived_record_id')->comment('archived_records FK'); + $table->string('table_name', 100)->comment('테이블명'); + $table->json('data')->comment('해당 테이블의 모든 레코드 (JSON 배열)'); + $table->integer('record_count')->default(0)->comment('레코드 개수'); + $table->timestamps(); + + $table->foreign('archived_record_id') + ->references('id') + ->on('archived_records') + ->onDelete('cascade'); + + $table->index(['archived_record_id', 'table_name']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('archived_record_relations'); + Schema::dropIfExists('archived_records'); + } +};