From f0464d4f8cbb39f41d323e31a68bf2695155e4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Wed, 11 Mar 2026 10:06:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[db]=20codebridge=20DB=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20=ED=9B=84=20=EA=B9=A8=EC=A7=84=20FK=20=EC=A0=9C?= =?UTF-8?q?=EC=95=BD=EC=A1=B0=EA=B1=B4=2052=EA=B0=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sam → codebridge 테이블 이동 후 users, tenants 등 참조하는 FK 잔존 - esign_field_templates INSERT 시 FK violation 발생 수정 --- ...op_broken_foreign_keys_from_codebridge.php | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 database/migrations/2026_03_11_100000_drop_broken_foreign_keys_from_codebridge.php diff --git a/database/migrations/2026_03_11_100000_drop_broken_foreign_keys_from_codebridge.php b/database/migrations/2026_03_11_100000_drop_broken_foreign_keys_from_codebridge.php new file mode 100644 index 0000000..d98e0c1 --- /dev/null +++ b/database/migrations/2026_03_11_100000_drop_broken_foreign_keys_from_codebridge.php @@ -0,0 +1,109 @@ +dropForeignKeySafe($connection, 'admin_api_bookmarks', 'admin_api_bookmarks_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_api_deprecations', 'admin_api_deprecations_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'admin_api_environments', 'admin_api_environments_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_api_histories', 'admin_api_histories_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_api_templates', 'admin_api_templates_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_meeting_logs', 'admin_meeting_logs_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_pm_daily_logs', 'admin_pm_daily_logs_deleted_by_foreign'); + $this->dropForeignKeySafe($connection, 'admin_pm_daily_logs', 'admin_pm_daily_logs_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'admin_pm_daily_logs', 'admin_pm_daily_logs_updated_by_foreign'); + $this->dropForeignKeySafe($connection, 'admin_pm_issues', 'admin_pm_issues_assignee_id_foreign'); + $this->dropForeignKeySafe($connection, 'ai_token_usages', 'ai_token_usages_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'business_income_payments', 'business_income_payments_confirmed_by_foreign'); + $this->dropForeignKeySafe($connection, 'business_income_payments', 'business_income_payments_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'business_income_payments', 'business_income_payments_updated_by_foreign'); + $this->dropForeignKeySafe($connection, 'business_income_payments', 'business_income_payments_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'business_income_payments', 'business_income_payments_deleted_by_foreign'); + $this->dropForeignKeySafe($connection, 'demo_links', 'demo_links_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'esign_contracts', 'esign_contracts_updated_by_foreign'); + $this->dropForeignKeySafe($connection, 'esign_contracts', 'esign_contracts_deleted_by_foreign'); + $this->dropForeignKeySafe($connection, 'esign_contracts', 'esign_contracts_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'esign_field_templates', 'esign_field_templates_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'login_tokens', 'login_tokens_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'sales_contract_products', 'sales_contract_products_created_by_foreign'); + $this->dropForeignKeySafe($connection, 'sales_manager_documents', 'sales_manager_documents_uploaded_by_foreign'); + $this->dropForeignKeySafe($connection, 'sales_manager_documents', 'sales_manager_documents_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'sales_scenario_checklists', 'sales_scenario_checklists_user_id_foreign'); + $this->dropForeignKeySafe($connection, 'tenant_prospects', 'tenant_prospects_converted_by_foreign'); + $this->dropForeignKeySafe($connection, 'tenant_prospects', 'tenant_prospects_registered_by_foreign'); + + // 참조 대상: tenants (16개) + $this->dropForeignKeySafe($connection, 'account_codes', 'account_codes_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_meeting_logs', 'admin_meeting_logs_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'admin_pm_daily_logs', 'admin_pm_daily_logs_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'ai_token_usages', 'ai_token_usages_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'barobill_bank_sync_status', 'barobill_bank_sync_status_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'barobill_bank_transaction_splits', 'barobill_bank_transaction_splits_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'barobill_bank_transactions', 'barobill_bank_transactions_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'barobill_card_transaction_hides', 'barobill_card_transaction_hides_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'barobill_members', 'barobill_members_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'business_income_payments', 'business_income_payments_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'esign_audit_logs', 'esign_audit_logs_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'esign_contracts', 'esign_contracts_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'esign_field_templates', 'esign_field_templates_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'esign_sign_fields', 'esign_sign_fields_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'esign_signers', 'esign_signers_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'expense_accounts', 'expense_accounts_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'hometax_invoices', 'hometax_invoices_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'sales_contract_products', 'sales_contract_products_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'sales_manager_documents', 'sales_manager_documents_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'sales_scenario_checklists', 'sales_scenario_checklists_tenant_id_foreign'); + $this->dropForeignKeySafe($connection, 'tenant_prospects', 'tenant_prospects_tenant_id_foreign'); + + // 참조 대상: departments (1개) + $this->dropForeignKeySafe($connection, 'admin_pm_issues', 'admin_pm_issues_department_id_foreign'); + + // 참조 대상: processes (1개) + $this->dropForeignKeySafe($connection, 'equipment_process', 'equipment_process_process_id_foreign'); + + // 참조 대상: prospects (1개) + $this->dropForeignKeySafe($connection, 'demo_links', 'demo_links_prospect_id_foreign'); + + // 참조 대상: clients (1개) + $this->dropForeignKeySafe($connection, 'expense_accounts', 'expense_accounts_vendor_id_foreign'); + + // 참조 대상: barobill_card_transactions (1개) + $this->dropForeignKeySafe($connection, 'barobill_card_transaction_amount_logs', 'bb_amount_log_trans_fk'); + } + + public function down(): void + { + // 복원 불필요: 크로스 DB FK는 의도적으로 제거한 것 + } + + private function dropForeignKeySafe(string $connection, string $table, string $foreignKey): void + { + $exists = DB::connection($connection)->select(" + SELECT 1 FROM information_schema.TABLE_CONSTRAINTS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = ? + AND CONSTRAINT_NAME = ? + AND CONSTRAINT_TYPE = 'FOREIGN KEY' + ", [$table, $foreignKey]); + + if (! empty($exists)) { + DB::connection($connection)->statement("ALTER TABLE `{$table}` DROP FOREIGN KEY `{$foreignKey}`"); + } + } +};