template-saas-database-v2/ddl/02-enums.sql
Adrian Flores Cortes ea4f8b18a0 [SAAS-018] feat: Add sales schema DDL
- Create sales schema (00-schema.sql)
- Add sales enums (01-enums.sql): lead_status, lead_source, opportunity_stage, activity_type, activity_status
- Add tables (02-tables.sql): pipeline_stages, leads, opportunities, activities
- Add functions (03-functions.sql): convert_lead_to_opportunity, update_opportunity_stage, calculate_lead_score, get_pipeline_summary, initialize_default_stages
- Add RLS policies (04-rls.sql) for tenant isolation
- Add indexes (05-indexes.sql) for performance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 20:49:35 -06:00

72 lines
3.9 KiB
SQL

-- ============================================
-- TEMPLATE-SAAS: Enum Types
-- Version: 1.0.0
-- ============================================
-- Auth enums
CREATE TYPE auth.token_type AS ENUM ('access', 'refresh', 'reset_password', 'email_verification', 'api_key');
CREATE TYPE auth.oauth_provider AS ENUM ('google', 'microsoft', 'github', 'apple');
CREATE TYPE auth.session_status AS ENUM ('active', 'expired', 'revoked');
-- Tenant enums
CREATE TYPE tenants.tenant_status AS ENUM ('pending', 'active', 'suspended', 'cancelled');
CREATE TYPE tenants.subscription_status AS ENUM ('trialing', 'active', 'past_due', 'cancelled', 'unpaid');
-- User enums
CREATE TYPE users.user_status AS ENUM ('pending', 'active', 'inactive', 'suspended', 'pending_verification', 'deleted');
CREATE TYPE users.invitation_status AS ENUM ('pending', 'accepted', 'expired', 'cancelled');
-- Billing enums
CREATE TYPE billing.payment_status AS ENUM ('pending', 'processing', 'succeeded', 'failed', 'refunded', 'cancelled');
CREATE TYPE billing.invoice_status AS ENUM ('draft', 'open', 'paid', 'void', 'uncollectible');
CREATE TYPE billing.billing_interval AS ENUM ('month', 'year');
CREATE TYPE billing.payment_method_type AS ENUM ('card', 'bank_transfer', 'oxxo');
CREATE TYPE billing.subscription_status AS ENUM ('trial', 'active', 'past_due', 'cancelled', 'expired');
-- Notification enums
CREATE TYPE notifications.channel AS ENUM ('email', 'push', 'in_app', 'sms', 'whatsapp');
CREATE TYPE notifications.notification_status AS ENUM ('pending', 'sent', 'delivered', 'failed', 'read');
CREATE TYPE notifications.priority AS ENUM ('low', 'normal', 'high', 'urgent');
CREATE TYPE notifications.queue_status AS ENUM ('queued', 'processing', 'sent', 'failed', 'retrying');
CREATE TYPE notifications.device_type AS ENUM ('web', 'mobile', 'desktop');
-- Feature flag enums
CREATE TYPE feature_flags.flag_status AS ENUM ('disabled', 'enabled', 'percentage', 'user_list');
CREATE TYPE feature_flags.rollout_stage AS ENUM ('development', 'internal', 'beta', 'general');
-- Audit enums
CREATE TYPE audit.action_type AS ENUM ('create', 'read', 'update', 'delete', 'login', 'logout', 'export', 'import');
CREATE TYPE audit.severity AS ENUM ('info', 'warning', 'error', 'critical');
-- Storage enums
CREATE TYPE storage.file_status AS ENUM ('uploading', 'processing', 'ready', 'failed', 'deleted');
CREATE TYPE storage.visibility AS ENUM ('private', 'tenant', 'public');
CREATE TYPE storage.storage_provider AS ENUM ('s3', 'r2', 'minio', 'gcs');
-- AI enums
CREATE TYPE ai.ai_provider AS ENUM ('openrouter', 'openai', 'anthropic', 'google');
CREATE TYPE ai.ai_model_type AS ENUM ('chat', 'completion', 'embedding', 'image');
CREATE TYPE ai.usage_status AS ENUM ('pending', 'completed', 'failed', 'cancelled');
-- Webhook enums
CREATE TYPE webhooks.delivery_status AS ENUM ('pending', 'delivered', 'failed', 'retrying');
CREATE TYPE webhooks.event_type AS ENUM (
'user.created', 'user.updated', 'user.deleted',
'subscription.created', 'subscription.updated', 'subscription.cancelled',
'invoice.paid', 'invoice.failed',
'file.uploaded', 'file.deleted',
'tenant.updated'
);
-- WhatsApp enums
CREATE TYPE whatsapp.message_status AS ENUM ('pending', 'sent', 'delivered', 'read', 'failed');
CREATE TYPE whatsapp.message_type AS ENUM ('text', 'template', 'image', 'document', 'audio', 'video', 'location', 'contacts', 'interactive');
CREATE TYPE whatsapp.message_direction AS ENUM ('outbound', 'inbound');
-- Sales enums (SAAS-018)
CREATE TYPE sales.lead_status AS ENUM ('new', 'contacted', 'qualified', 'unqualified', 'converted');
CREATE TYPE sales.lead_source AS ENUM ('website', 'referral', 'cold_call', 'event', 'advertisement', 'social_media', 'other');
CREATE TYPE sales.opportunity_stage AS ENUM ('prospecting', 'qualification', 'proposal', 'negotiation', 'closed_won', 'closed_lost');
CREATE TYPE sales.activity_type AS ENUM ('call', 'meeting', 'task', 'email', 'note');
CREATE TYPE sales.activity_status AS ENUM ('pending', 'completed', 'cancelled');