From 7c2a084b3ec73b4052454c127274a563e2a6aeb5 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 23 Dec 2025 10:52:00 +0700 Subject: [PATCH] Add schema cache fallback for service account JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add fallback RPC method when PostgREST schema cache fails - Save service account JSON separately via raw SQL - Show warning message if manual save needed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../admin/settings/IntegrasiTab.tsx | 35 ++++++++++++++++++- verify-column.sql | 10 ++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 verify-column.sql diff --git a/src/components/admin/settings/IntegrasiTab.tsx b/src/components/admin/settings/IntegrasiTab.tsx index 1498f0b..ca81a97 100644 --- a/src/components/admin/settings/IntegrasiTab.tsx +++ b/src/components/admin/settings/IntegrasiTab.tsx @@ -116,7 +116,40 @@ export function IntegrasiTab() { .update(platformPayload) .eq('id', settings.id); - if (platformError) throw platformError; + if (platformError) { + // If schema cache error, try saving service account JSON separately via raw SQL + if (platformError.code === 'PGRST204' && settings.integration_google_service_account_json) { + console.log('Schema cache error, using fallback RPC method'); + const { error: rpcError } = await supabase.rpc('exec_sql', { + sql: `UPDATE platform_settings SET google_service_account_json = '${settings.integration_google_service_account_json.replace(/'/g, "''")}'::jsonb WHERE id = '${settings.id}'` + }); + + if (rpcError) { + // Save other fields without the problematic column + const { error: retryError } = await supabase + .from('platform_settings') + .update({ + integration_n8n_base_url: settings.integration_n8n_base_url, + integration_whatsapp_number: settings.integration_whatsapp_number, + integration_whatsapp_url: settings.integration_whatsapp_url, + integration_google_calendar_id: settings.integration_google_calendar_id, + integration_email_provider: settings.integration_email_provider, + integration_email_api_base_url: settings.integration_email_api_base_url, + integration_privacy_url: settings.integration_privacy_url, + integration_terms_url: settings.integration_terms_url, + integration_n8n_test_mode: settings.integration_n8n_test_mode, + }) + .eq('id', settings.id); + + if (retryError) throw retryError; + toast({ title: 'Peringatan', description: 'Pengaturan disimpan tapi Service Account JSON perlu disimpan manual. Hubungi admin.' }); + } else { + toast({ title: 'Berhasil', description: 'Service Account JSON disimpan via RPC' }); + } + } else { + throw platformError; + } + } } // Save email provider settings to notification_settings diff --git a/verify-column.sql b/verify-column.sql new file mode 100644 index 0000000..774acbb --- /dev/null +++ b/verify-column.sql @@ -0,0 +1,10 @@ +-- Check if column exists in database +SELECT + column_name, + data_type, + is_nullable, + column_default +FROM information_schema.columns +WHERE table_schema = 'public' +AND table_name = 'platform_settings' +ORDER BY ordinal_position;