CREATE TABLE IF NOT EXISTS email_templates ( id BIGSERIAL PRIMARY KEY, slug VARCHAR(100) NOT NULL UNIQUE, name VARCHAR(200) NOT NULL, subject TEXT NOT NULL, body_text TEXT NOT NULL, body_html TEXT NOT NULL, variables JSONB NOT NULL DEFAULT '[]'::jsonb, is_system BOOLEAN NOT NULL DEFAULT FALSE, status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE' CHECK (status IN ('ACTIVE', 'INACTIVE')), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ ); CREATE INDEX IF NOT EXISTS idx_email_templates_status ON email_templates(status); CREATE INDEX IF NOT EXISTS idx_email_templates_slug ON email_templates(slug); INSERT INTO email_templates (slug, name, subject, body_text, body_html, variables, is_system, status) VALUES ( 'otp', 'One-Time Password', 'Yimaru - One Time Password', 'Welcome to Yimaru Online Learning Platform{{if .FirstName}}, {{.FirstName}}{{end}}. Your OTP is {{.OTP}}. It expires in {{.ExpiresMinutes}} minutes. Please do not share it with anyone.', '

Welcome to Yimaru Online Learning Platform{{if .FirstName}}, {{.FirstName}}{{end}}.

Your one-time password is {{.OTP}}.

It expires in {{.ExpiresMinutes}} minutes. Please do not share it with anyone.

', '["OTP", "FirstName", "ExpiresMinutes"]'::jsonb, TRUE, 'ACTIVE' ), ( 'invitation', 'User Invitation', 'You are invited to join Yimaru', 'Hi{{if .FirstName}} {{.FirstName}}{{end}}, you have been invited{{if .InviterName}} by {{.InviterName}}{{end}} to join Yimaru Online Learning Platform. Accept your invitation: {{.InviteLink}}', '

Hi{{if .FirstName}} {{.FirstName}}{{end}},

You have been invited{{if .InviterName}} by {{.InviterName}}{{end}} to join Yimaru Online Learning Platform.

Accept your invitation

', '["FirstName", "InviterName", "InviteLink"]'::jsonb, TRUE, 'ACTIVE' ), ( 'password_reset', 'Password Reset', 'Reset your Yimaru password', 'Hi{{if .FirstName}} {{.FirstName}}{{end}}, use this link to reset your password: {{.ResetLink}}. The link expires in {{.ExpiresMinutes}} minutes.', '

Hi{{if .FirstName}} {{.FirstName}}{{end}},

Use the link below to reset your password. It expires in {{.ExpiresMinutes}} minutes.

Reset your password

', '["FirstName", "ResetLink", "ExpiresMinutes"]'::jsonb, TRUE, 'ACTIVE' ), ( 'welcome', 'Welcome Email', 'Welcome to Yimaru', 'Hi{{if .FirstName}} {{.FirstName}}{{end}}, welcome to Yimaru Online Learning Platform! Sign in at {{.LoginURL}} to get started.', '

Hi{{if .FirstName}} {{.FirstName}}{{end}},

Welcome to Yimaru Online Learning Platform!

Sign in to get started

', '["FirstName", "LoginURL"]'::jsonb, TRUE, 'ACTIVE' ), ( 'custom_message', 'Custom Message', '{{.Subject}}', '{{.Message}}', '

{{.Message}}

', '["Subject", "Message"]'::jsonb, TRUE, 'ACTIVE' ) ON CONFLICT (slug) DO NOTHING;