## Documentation - Align MCH-029 to MCH-032 with template-saas modules (SAAS-008 to SAAS-015) - Create MCH-034 (Analytics) and MCH-035 (Reports) from SAAS-016/017 - Update PLAN-DESARROLLO.md with Phase 7 and 8 - Update _MAP.md indexes (35 total epics) ## Database (5 new schemas, 14 tables) - Add storage schema: buckets, files, signed_urls - Add webhooks schema: endpoints, deliveries - Add audit schema: logs, retention_policies - Add features schema: flags, tenant_flags (14 seeds) - Add analytics schema: metrics, events, reports, report_schedules - Add auth.oauth_connections for MCH-030 - Add timestamptz_to_date() IMMUTABLE function - Update EXPECTED_SCHEMAS in recreate-database.sh ## Analysis Reports - ANALISIS-INTEGRACION-TEMPLATE-SAAS-2026-01-13.md - VALIDACION-COHERENCIA-2026-01-13.md - GAP-ANALYSIS-BD-2026-01-13.md - REPORTE-EJECUCION-2026-01-13.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
2.6 KiB
SQL
78 lines
2.6 KiB
SQL
-- =============================================================================
|
|
-- MICHANGARRITO - 01 SCHEMAS
|
|
-- =============================================================================
|
|
-- Creación de schemas del sistema
|
|
-- =============================================================================
|
|
|
|
-- Schema de autenticación
|
|
CREATE SCHEMA IF NOT EXISTS auth;
|
|
COMMENT ON SCHEMA auth IS 'Autenticación y usuarios';
|
|
|
|
-- Schema de catálogo
|
|
CREATE SCHEMA IF NOT EXISTS catalog;
|
|
COMMENT ON SCHEMA catalog IS 'Productos y categorías';
|
|
|
|
-- Schema de ventas
|
|
CREATE SCHEMA IF NOT EXISTS sales;
|
|
COMMENT ON SCHEMA sales IS 'Ventas, pagos y cortes';
|
|
|
|
-- Schema de inventario
|
|
CREATE SCHEMA IF NOT EXISTS inventory;
|
|
COMMENT ON SCHEMA inventory IS 'Stock y movimientos';
|
|
|
|
-- Schema de clientes
|
|
CREATE SCHEMA IF NOT EXISTS customers;
|
|
COMMENT ON SCHEMA customers IS 'Clientes y fiados';
|
|
|
|
-- Schema de pedidos
|
|
CREATE SCHEMA IF NOT EXISTS orders;
|
|
COMMENT ON SCHEMA orders IS 'Pedidos y entregas';
|
|
|
|
-- Schema de suscripciones
|
|
CREATE SCHEMA IF NOT EXISTS subscriptions;
|
|
COMMENT ON SCHEMA subscriptions IS 'Planes y tokens IA';
|
|
|
|
-- Schema de mensajería
|
|
CREATE SCHEMA IF NOT EXISTS messaging;
|
|
COMMENT ON SCHEMA messaging IS 'WhatsApp y notificaciones';
|
|
|
|
-- Permisos
|
|
GRANT USAGE ON SCHEMA auth TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA catalog TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA sales TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA inventory TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA customers TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA orders TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA subscriptions TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA messaging TO michangarrito_dev;
|
|
|
|
-- Schema de almacenamiento (MCH-029)
|
|
CREATE SCHEMA IF NOT EXISTS storage;
|
|
COMMENT ON SCHEMA storage IS 'Almacenamiento de archivos';
|
|
|
|
-- Schema de webhooks (MCH-029)
|
|
CREATE SCHEMA IF NOT EXISTS webhooks;
|
|
COMMENT ON SCHEMA webhooks IS 'Sistema de webhooks salientes';
|
|
|
|
-- Schema de auditoria (MCH-031)
|
|
CREATE SCHEMA IF NOT EXISTS audit;
|
|
COMMENT ON SCHEMA audit IS 'Logs de auditoria empresarial';
|
|
|
|
-- Schema de features (MCH-032)
|
|
CREATE SCHEMA IF NOT EXISTS features;
|
|
COMMENT ON SCHEMA features IS 'Feature flags por plan/tenant';
|
|
|
|
-- Schema de analytics (MCH-034, MCH-035)
|
|
CREATE SCHEMA IF NOT EXISTS analytics;
|
|
COMMENT ON SCHEMA analytics IS 'Metricas y reportes';
|
|
|
|
-- Permisos schemas base
|
|
GRANT USAGE ON SCHEMA storage TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA webhooks TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA audit TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA features TO michangarrito_dev;
|
|
GRANT USAGE ON SCHEMA analytics TO michangarrito_dev;
|
|
|
|
-- Permisos en public
|
|
GRANT ALL ON SCHEMA public TO michangarrito_dev;
|