diff --git a/database/migrations/2026_03_10_224806_add_tenant_id_to_document_detail_tables.php b/database/migrations/2026_03_10_224806_add_tenant_id_to_document_detail_tables.php new file mode 100644 index 0000000..b34858e --- /dev/null +++ b/database/migrations/2026_03_10_224806_add_tenant_id_to_document_detail_tables.php @@ -0,0 +1,46 @@ +unsignedBigInteger('tenant_id')->nullable()->after('id')->comment('테넌트 ID'); + $table->index('tenant_id'); + }); + + // 부모 테이블(documents)에서 tenant_id 채우기 + DB::statement(" + UPDATE {$table} t + JOIN documents d ON t.document_id = d.id + SET t.tenant_id = d.tenant_id + "); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $tables = ['document_data', 'document_approvals', 'document_attachments']; + + foreach ($tables as $table) { + Schema::table($table, function (Blueprint $table) { + $table->dropIndex(['tenant_id']); + $table->dropColumn('tenant_id'); + }); + } + } +}; \ No newline at end of file