From c6250d2b47bc32df9cbf5c0a5259466d80f50c57 Mon Sep 17 00:00:00 2001 From: dwindown Date: Fri, 2 Jan 2026 13:41:30 +0700 Subject: [PATCH] Fix notification_templates table column names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update auth email template migration and edge function to use correct column names: - template_key → key - subject → email_subject - html_content → email_body_html Matches existing notification_templates schema used in NotifikasiTab. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- supabase/functions/send-auth-otp/index.ts | 6 ++-- .../20250102000002_auth_email_template.sql | 32 ++++--------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/supabase/functions/send-auth-otp/index.ts b/supabase/functions/send-auth-otp/index.ts index b9d7b3e..894b404 100644 --- a/supabase/functions/send-auth-otp/index.ts +++ b/supabase/functions/send-auth-otp/index.ts @@ -82,7 +82,7 @@ serve(async (req: Request) => { const { data: template, error: templateError } = await supabase .from('notification_templates') .select('*') - .eq('template_key', 'auth_email_verification') + .eq('key', 'auth_email_verification') .single(); if (templateError || !template) { @@ -110,13 +110,13 @@ serve(async (req: Request) => { }; // Process shortcodes in subject - let subject = template.subject; + let subject = template.email_subject; Object.entries(templateVars).forEach(([key, value]) => { subject = subject.replace(new RegExp(`{${key}}`, 'g'), value); }); // Process shortcodes in HTML body - let htmlBody = template.html_content; + let htmlBody = template.email_body_html; Object.entries(templateVars).forEach(([key, value]) => { htmlBody = htmlBody.replace(new RegExp(`{${key}}`, 'g'), value); }); diff --git a/supabase/migrations/20250102000002_auth_email_template.sql b/supabase/migrations/20250102000002_auth_email_template.sql index d181ad5..7b5ae06 100644 --- a/supabase/migrations/20250102000002_auth_email_template.sql +++ b/supabase/migrations/20250102000002_auth_email_template.sql @@ -4,18 +4,15 @@ -- Insert default auth email verification template INSERT INTO notification_templates ( - template_key, - template_name, - description, - subject, - html_content, + key, + name, is_active, - created_at, - updated_at + email_subject, + email_body_html ) VALUES ( 'auth_email_verification', 'Verifikasi Email - OTP', - 'Template untuk mengirim kode OTP verifikasi email saat pendaftaran', + true, 'Kode Verifikasi Email Anda - {platform_name}', '--- @@ -96,15 +93,6 @@ INSERT INTO notification_templates ( color: #666; border-top: 2px solid #000; } - .button { - display: inline-block; - background: #000; - color: #fff; - padding: 12px 24px; - text-decoration: none; - font-weight: 600; - margin-top: 10px; - } @@ -146,14 +134,8 @@ INSERT INTO notification_templates ( ----', - true, - NOW(), - NOW() -) ON CONFLICT (template_key) DO NOTHING; - --- Add comment -COMMENT ON TABLE notification_templates IS 'Contains email templates for various notifications including auth emails'; +---' +) ON CONFLICT (key) DO NOTHING; -- Return success message DO $$