- Backend: c426249 (class-validator decorators) - DATABASE_INVENTORY.yml: v3.4.0 with validation metrics - MASTER_INVENTORY.yml: v6.1.0 with coherence metrics Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
551 lines
14 KiB
YAML
551 lines
14 KiB
YAML
---
|
|
# DATABASE INVENTORY - Template SaaS
|
|
# Version: 3.4.0
|
|
# Ultima actualizacion: 2026-02-03
|
|
# Nota: Validacion Integral de Modelado BD completada (TASK-2026-02-03-VALIDACION-INTEGRAL-MODELADO-BD)
|
|
|
|
metadata:
|
|
proyecto: "template-saas"
|
|
tipo: "DATABASE"
|
|
version: "3.4.0"
|
|
updated: "2026-02-03"
|
|
motor: "PostgreSQL 16+"
|
|
version_motor: "16.x"
|
|
estado: "completado"
|
|
ultima_validacion: "2026-02-03"
|
|
validado_por: "Claude Opus 4.5 (Especialista BD)"
|
|
|
|
features:
|
|
- "Row-Level Security (RLS)"
|
|
- "Multi-tenant isolation"
|
|
- "UUID primary keys"
|
|
- "JSONB for settings"
|
|
|
|
schemas:
|
|
- nombre: "auth"
|
|
descripcion: "Autenticacion y sesiones"
|
|
estado: "completado"
|
|
tablas:
|
|
- sessions
|
|
- tokens
|
|
- oauth_connections
|
|
enums:
|
|
- token_type
|
|
- oauth_provider
|
|
- session_status
|
|
funciones:
|
|
- cleanup_expired_sessions
|
|
- set_current_tenant
|
|
- get_current_tenant
|
|
- set_current_user
|
|
- get_current_user
|
|
- clear_context
|
|
rls_policies:
|
|
- sessions_tenant_isolation
|
|
- tokens_tenant_isolation
|
|
- oauth_tenant_isolation
|
|
|
|
- nombre: "tenants"
|
|
descripcion: "Multi-tenancy y organizaciones"
|
|
estado: "completado"
|
|
tablas:
|
|
- tenants
|
|
- tenant_settings
|
|
enums:
|
|
- tenant_status
|
|
- subscription_status
|
|
funciones:
|
|
- update_updated_at
|
|
rls_policies:
|
|
- tenant_settings_isolation
|
|
|
|
- nombre: "users"
|
|
descripcion: "Usuarios, roles y permisos"
|
|
estado: "completado"
|
|
tablas:
|
|
- users
|
|
- roles
|
|
- invitations
|
|
enums:
|
|
- user_status
|
|
- invitation_status
|
|
funciones:
|
|
- update_updated_at
|
|
- expire_old_invitations
|
|
rls_policies:
|
|
- users_tenant_isolation
|
|
- roles_tenant_isolation
|
|
- invitations_tenant_isolation
|
|
|
|
- nombre: "plans"
|
|
descripcion: "Planes y limites"
|
|
estado: "completado"
|
|
tablas:
|
|
- plans
|
|
funciones:
|
|
- get_tenant_limits
|
|
- check_limit
|
|
- get_tenant_features
|
|
- has_feature
|
|
rls_policies: []
|
|
|
|
- nombre: "billing"
|
|
descripcion: "Suscripciones, facturas y pagos"
|
|
estado: "completado"
|
|
tablas:
|
|
- subscriptions
|
|
- invoices
|
|
- payment_methods
|
|
enums:
|
|
- payment_status
|
|
- invoice_status
|
|
- billing_interval
|
|
- payment_method_type
|
|
- subscription_status
|
|
funciones:
|
|
- generate_invoice_number
|
|
rls_policies:
|
|
- subscriptions_tenant_isolation
|
|
- invoices_tenant_isolation
|
|
- payments_tenant_isolation
|
|
|
|
- nombre: "notifications"
|
|
descripcion: "Sistema de notificaciones v2"
|
|
estado: "completado"
|
|
tablas:
|
|
- notifications
|
|
- extended_notifications
|
|
enums:
|
|
- channel
|
|
- notification_status
|
|
- priority
|
|
- queue_status
|
|
- device_type
|
|
funciones:
|
|
- update_updated_at
|
|
rls_policies:
|
|
- notifications_tenant_isolation
|
|
- user_preferences_tenant_isolation
|
|
|
|
- nombre: "feature_flags"
|
|
descripcion: "Feature toggles"
|
|
estado: "completado"
|
|
tablas:
|
|
- flags
|
|
enums:
|
|
- flag_status
|
|
- rollout_stage
|
|
funciones:
|
|
- evaluate_flag
|
|
rls_policies:
|
|
- tenant_flags_isolation
|
|
- user_flags_isolation
|
|
|
|
- nombre: "audit"
|
|
descripcion: "Auditoria y logs"
|
|
estado: "completado"
|
|
tablas:
|
|
- audit_logs
|
|
enums:
|
|
- action_type
|
|
- severity
|
|
funciones:
|
|
- log_event
|
|
- cleanup_old_logs
|
|
rls_policies:
|
|
- audit_logs_tenant_isolation
|
|
|
|
- nombre: "storage"
|
|
descripcion: "Almacenamiento de archivos"
|
|
estado: "completado"
|
|
tablas:
|
|
- files
|
|
- storage_usage
|
|
enums:
|
|
- file_status
|
|
- visibility
|
|
- storage_provider
|
|
funciones:
|
|
- update_storage_usage
|
|
rls_policies:
|
|
- files_tenant_isolation
|
|
- storage_usage_tenant_isolation
|
|
|
|
- nombre: "ai"
|
|
descripcion: "Integracion AI"
|
|
estado: "completado"
|
|
tablas:
|
|
- ai_configs
|
|
- ai_usage
|
|
enums:
|
|
- ai_provider
|
|
- ai_model_type
|
|
- usage_status
|
|
funciones:
|
|
- track_ai_usage
|
|
rls_policies:
|
|
- ai_configs_tenant_isolation
|
|
- ai_usage_tenant_isolation
|
|
|
|
- nombre: "webhooks"
|
|
descripcion: "Webhooks outbound"
|
|
estado: "completado"
|
|
tablas:
|
|
- webhooks
|
|
- deliveries
|
|
enums:
|
|
- delivery_status
|
|
- event_type
|
|
funciones:
|
|
- retry_webhook
|
|
- get_webhook_stats
|
|
rls_policies:
|
|
- webhooks_tenant_isolation
|
|
- deliveries_tenant_isolation
|
|
|
|
- nombre: "whatsapp"
|
|
descripcion: "WhatsApp Business API"
|
|
estado: "completado"
|
|
tablas:
|
|
- whatsapp_configs
|
|
- whatsapp_messages
|
|
enums:
|
|
- message_status
|
|
- message_type
|
|
- message_direction
|
|
funciones: []
|
|
rls_policies:
|
|
- whatsapp_configs_tenant_isolation
|
|
- whatsapp_messages_tenant_isolation
|
|
|
|
- nombre: "sales"
|
|
descripcion: "Sales Foundation - Leads, Oportunidades, Pipeline"
|
|
estado: "completado"
|
|
tablas:
|
|
- leads
|
|
- opportunities
|
|
- pipeline_stages
|
|
- activities
|
|
enums:
|
|
- lead_status
|
|
- lead_source
|
|
- opportunity_stage
|
|
- activity_type
|
|
- activity_status
|
|
funciones:
|
|
- convert_lead_to_opportunity
|
|
- update_opportunity_stage
|
|
- calculate_lead_score
|
|
- get_pipeline_summary
|
|
- initialize_default_stages
|
|
rls_policies:
|
|
- leads_tenant_isolation
|
|
- opportunities_tenant_isolation
|
|
- pipeline_stages_tenant_isolation
|
|
- activities_tenant_isolation
|
|
indices:
|
|
- leads_tenant_status_idx
|
|
- leads_assigned_to_idx
|
|
- leads_source_idx
|
|
- leads_score_idx
|
|
- opportunities_tenant_stage_idx
|
|
- opportunities_assigned_to_idx
|
|
- opportunities_expected_close_idx
|
|
- pipeline_stages_position_idx
|
|
- activities_tenant_type_idx
|
|
- activities_lead_idx
|
|
- activities_opportunity_idx
|
|
- activities_due_date_idx
|
|
nota: "SAAS-018 - Implementado 2026-01-24"
|
|
|
|
- nombre: "commissions"
|
|
descripcion: "Sistema de comisiones - Esquemas, Asignaciones, Entradas, Períodos"
|
|
estado: "completado"
|
|
tablas:
|
|
- schemes
|
|
- assignments
|
|
- entries
|
|
- periods
|
|
enums:
|
|
- scheme_type
|
|
- applies_to
|
|
- entry_status
|
|
- period_status
|
|
funciones:
|
|
- calculate_commission
|
|
- close_period
|
|
- get_user_earnings
|
|
- apply_tiered_rate
|
|
rls_policies:
|
|
- schemes_tenant_isolation_select
|
|
- schemes_tenant_isolation_insert
|
|
- schemes_tenant_isolation_update
|
|
- schemes_tenant_isolation_delete
|
|
- assignments_tenant_isolation_select
|
|
- assignments_tenant_isolation_insert
|
|
- assignments_tenant_isolation_update
|
|
- assignments_tenant_isolation_delete
|
|
- entries_tenant_isolation_select
|
|
- entries_tenant_isolation_insert
|
|
- entries_tenant_isolation_update
|
|
- entries_tenant_isolation_delete
|
|
- periods_tenant_isolation_select
|
|
- periods_tenant_isolation_insert
|
|
- periods_tenant_isolation_update
|
|
- periods_tenant_isolation_delete
|
|
indices:
|
|
- schemes_tenant_active_idx
|
|
- schemes_type_idx
|
|
- assignments_tenant_user_idx
|
|
- assignments_scheme_idx
|
|
- assignments_active_dates_idx
|
|
- entries_tenant_user_idx
|
|
- entries_scheme_idx
|
|
- entries_status_idx
|
|
- entries_period_idx
|
|
- entries_reference_idx
|
|
- entries_created_at_idx
|
|
- periods_tenant_status_idx
|
|
- periods_dates_idx
|
|
nota: "SAAS-020 - Implementado 2026-01-24"
|
|
|
|
- nombre: "portfolio"
|
|
descripcion: "Catálogo de productos/servicios - Categorías, Productos, Variantes, Precios"
|
|
estado: "completado"
|
|
tablas:
|
|
- categories
|
|
- products
|
|
- variants
|
|
- prices
|
|
enums:
|
|
- product_type
|
|
- product_status
|
|
- price_type
|
|
- attribute_type
|
|
funciones:
|
|
- update_updated_at (triggers)
|
|
rls_policies:
|
|
- categories_tenant_isolation_select
|
|
- categories_tenant_isolation_insert
|
|
- categories_tenant_isolation_update
|
|
- categories_tenant_isolation_delete
|
|
- products_tenant_isolation_select
|
|
- products_tenant_isolation_insert
|
|
- products_tenant_isolation_update
|
|
- products_tenant_isolation_delete
|
|
- variants_tenant_isolation_select
|
|
- variants_tenant_isolation_insert
|
|
- variants_tenant_isolation_update
|
|
- variants_tenant_isolation_delete
|
|
- prices_tenant_isolation_select
|
|
- prices_tenant_isolation_insert
|
|
- prices_tenant_isolation_update
|
|
- prices_tenant_isolation_delete
|
|
indices:
|
|
- categories_tenant_slug_idx
|
|
- categories_parent_idx
|
|
- categories_position_idx
|
|
- products_tenant_status_idx
|
|
- products_category_idx
|
|
- products_sku_idx
|
|
- products_barcode_idx
|
|
- products_slug_idx
|
|
- products_type_idx
|
|
- products_featured_idx
|
|
- products_visible_idx
|
|
- products_price_range_idx
|
|
- products_search_idx
|
|
- products_tags_idx
|
|
- variants_product_idx
|
|
- variants_sku_idx
|
|
- variants_barcode_idx
|
|
- variants_active_idx
|
|
- prices_product_idx
|
|
- prices_variant_idx
|
|
- prices_type_idx
|
|
- prices_currency_idx
|
|
- prices_active_dates_idx
|
|
nota: "SAAS-019 - Implementado 2026-01-25"
|
|
|
|
resumen:
|
|
total_schemas: 17
|
|
total_tablas: 52
|
|
total_enums: 58
|
|
total_funciones: 57
|
|
total_rls_policies: 95
|
|
total_indices: 217
|
|
total_triggers: 37
|
|
total_check_constraints: 45
|
|
total_foreign_keys: 143
|
|
|
|
planificado:
|
|
tablas_actuales: 52
|
|
tablas_objetivo: 52
|
|
estado: "100%"
|
|
nota: "Validacion integral completada 2026-02-03"
|
|
|
|
coherencia:
|
|
ddl_a_entity: "100%"
|
|
columnas: "95%"
|
|
tipos: "96.6%"
|
|
validadores: "0%"
|
|
rls_cobertura: "52%"
|
|
normalizacion: "100% (3NF)"
|
|
nota: "Metricas de validacion integral 2026-02-03"
|
|
|
|
issues_pendientes:
|
|
criticos: 3
|
|
altos: 5
|
|
medios: 8
|
|
total: 16
|
|
detalle:
|
|
- tipo: "critico"
|
|
descripcion: "Validadores DTOs no implementados"
|
|
- tipo: "critico"
|
|
descripcion: "RLS cobertura parcial (52%)"
|
|
- tipo: "critico"
|
|
descripcion: "Constraints check faltantes en algunas tablas"
|
|
- tipo: "alto"
|
|
descripcion: "5% columnas con discrepancias de mapeo"
|
|
- tipo: "alto"
|
|
descripcion: "Indices compuestos optimizables"
|
|
nota: "Identificados en validacion integral 2026-02-03"
|
|
|
|
ddl_structure:
|
|
base_files:
|
|
- "00-extensions.sql"
|
|
- "01-schemas.sql"
|
|
- "02-enums.sql"
|
|
- "03-functions.sql"
|
|
schema_files:
|
|
- "schemas/*/tables/*.sql"
|
|
- "schemas/*/rls/*.sql"
|
|
- "schemas/*/triggers/*.sql"
|
|
|
|
seeds:
|
|
prod:
|
|
- plans: 4
|
|
- permissions: 21
|
|
- feature_flags: 8
|
|
- notification_templates: 6
|
|
dev:
|
|
- sample_tenants: 3
|
|
- sample_users: 10
|
|
|
|
scripts:
|
|
- create-database.sh
|
|
- drop-and-recreate.sh
|
|
|
|
- nombre: "mlm"
|
|
descripcion: "Multi-Level Marketing - Estructuras, Rangos, Nodos, Comisiones, Bonos"
|
|
estado: "completado"
|
|
tablas:
|
|
- structures
|
|
- ranks
|
|
- nodes
|
|
- commissions
|
|
- bonuses
|
|
- rank_history
|
|
enums:
|
|
- structure_type
|
|
- node_status
|
|
- commission_type
|
|
- commission_status
|
|
- bonus_type
|
|
funciones:
|
|
- update_updated_at
|
|
rls_policies:
|
|
- structures_tenant_isolation_select
|
|
- structures_tenant_isolation_insert
|
|
- structures_tenant_isolation_update
|
|
- structures_tenant_isolation_delete
|
|
- ranks_tenant_isolation_select
|
|
- ranks_tenant_isolation_insert
|
|
- ranks_tenant_isolation_update
|
|
- ranks_tenant_isolation_delete
|
|
- nodes_tenant_isolation_select
|
|
- nodes_tenant_isolation_insert
|
|
- nodes_tenant_isolation_update
|
|
- nodes_tenant_isolation_delete
|
|
- commissions_tenant_isolation_select
|
|
- commissions_tenant_isolation_insert
|
|
- commissions_tenant_isolation_update
|
|
- commissions_tenant_isolation_delete
|
|
indices:
|
|
- structures_tenant_active_idx
|
|
- ranks_tenant_idx
|
|
- ranks_level_idx
|
|
- nodes_tenant_idx
|
|
- nodes_parent_idx
|
|
- nodes_path_idx
|
|
- commissions_tenant_idx
|
|
- commissions_node_idx
|
|
- commissions_period_idx
|
|
nota: "SAAS-021 - Verificado implementado 2026-01-27"
|
|
|
|
- nombre: "goals"
|
|
descripcion: "Sistema de Metas - Definiciones, Asignaciones, Progreso, Notificaciones"
|
|
estado: "completado"
|
|
tablas:
|
|
- definitions
|
|
- assignments
|
|
- progress_log
|
|
- milestone_notifications
|
|
enums:
|
|
- goal_type
|
|
- metric_type
|
|
- period_type
|
|
- data_source
|
|
- goal_status
|
|
- assignee_type
|
|
- assignment_status
|
|
- progress_source
|
|
funciones:
|
|
- update_updated_at
|
|
rls_policies:
|
|
- definitions_tenant_isolation_select
|
|
- definitions_tenant_isolation_insert
|
|
- definitions_tenant_isolation_update
|
|
- definitions_tenant_isolation_delete
|
|
- assignments_tenant_isolation_select
|
|
- assignments_tenant_isolation_insert
|
|
- assignments_tenant_isolation_update
|
|
- assignments_tenant_isolation_delete
|
|
- progress_log_tenant_isolation_select
|
|
- progress_log_tenant_isolation_insert
|
|
indices:
|
|
- definitions_tenant_status_idx
|
|
- definitions_type_idx
|
|
- assignments_tenant_user_idx
|
|
- assignments_goal_idx
|
|
- assignments_status_idx
|
|
- progress_log_assignment_idx
|
|
- progress_log_created_idx
|
|
nota: "SAAS-022 - Verificado implementado 2026-01-27"
|
|
|
|
ultima_actualizacion: "2026-02-03"
|
|
actualizado_por: "Claude Opus 4.5 (ST-5.2 - Actualizacion Inventarios)"
|
|
|
|
historial_validaciones:
|
|
- fecha: "2026-02-03"
|
|
tipo: "validacion_integral"
|
|
tarea: "TASK-2026-02-03-VALIDACION-INTEGRAL-MODELADO-BD"
|
|
agente: "Claude Opus 4.5 - Especialista BD"
|
|
entregables:
|
|
- INFORME-NORMALIZACION.md
|
|
- INFORME-INTEGRIDAD-REFERENCIAL.md
|
|
- INFORME-INDICES-PERFORMANCE.md
|
|
- MATRIZ-TABLA-ENTITY.yml
|
|
- INFORME-RLS-AUDIT.md
|
|
- INFORME-CONSTRAINTS-VALIDATION.md
|
|
- INVENTARIO-FUNCIONES-SQL.yml
|
|
- INFORME-TRIGGERS.md
|
|
- INFORME-PURGA-DOCUMENTAL.md
|
|
- MATRIZ-TRAZABILIDAD-BD.yml
|
|
hallazgos_criticos: 3
|
|
hallazgos_totales: 16
|
|
- fecha: "2026-01-27"
|
|
tipo: "verificacion"
|
|
nota: "MLM y Goals schemas verificados"
|
|
agente: "Claude Opus 4.5"
|