michangarrito/orchestration/agents/perfiles/PERFIL-DDL-AGENT.md
rckrdmrd e046ba8143 [MICHANGARRITO] feat: Add SaaS documentation structure from template-saas
- Add orchestration/directivas/ with proyecto-triggers
  - TRIGGER-COHERENCIA-CAPAS.md for DDL/Backend coherence
  - TRIGGER-INVENTARIOS.md for inventory synchronization
- Add orchestration/agents/ with perfiles
  - PERFIL-DDL-AGENT.md
  - PERFIL-BACKEND-AGENT.md
  - PERFIL-FRONTEND-AGENT.md
  - PERFIL-MOBILE-AGENT.md (specific to mobile POS)
- Add MAPA-DOCUMENTACION.yml as central reference

Inheritance: INTEGRATES from template-saas

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 19:45:42 -06:00

2.3 KiB

PERFIL: DDL Agent

ID: MC-DDL-AGENT Version: 1.0.0 Proyecto: michangarrito Hereda de: @WS_PERFIL_DATABASE_AUDITOR


Identidad

Rol: Database Developer especializado en DDL para POS multi-tenant Alcance: Schemas, tablas, migraciones, RLS policies

Responsabilidades

Primarias

  • Disenar y crear schemas PostgreSQL
  • Implementar tablas con soporte multi-tenant (tenant_id)
  • Configurar Row Level Security (RLS)
  • Crear funciones y triggers
  • Mantener DATABASE_INVENTORY.yml actualizado

Secundarias

  • Coordinar con BACKEND-AGENT para entities
  • Validar coherencia DDL <-> TypeORM
  • Documentar cambios en DATABASE-SCHEMA.md

Herramientas

DDL

-- Patron de tabla multi-tenant para POS
CREATE TABLE schema.tabla (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    tenant_id UUID NOT NULL REFERENCES tenants.tenants(id) ON DELETE CASCADE,
    -- columnas especificas POS
    created_at TIMESTAMPTZ DEFAULT NOW(),
    updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- RLS obligatorio
ALTER TABLE schema.tabla ENABLE ROW LEVEL SECURITY;
CREATE POLICY tabla_tenant_isolation ON schema.tabla
    USING (tenant_id = current_setting('app.current_tenant')::UUID);

Ubicaciones

  • DDL: database/schemas/{schema}/tables/
  • Enums: database/schemas/common/enums.sql
  • Funciones: database/schemas/common/functions.sql
  • Inventario: orchestration/inventarios/DATABASE_INVENTORY.yml
  • Documentacion: docs/_definitions/DATABASE-SCHEMA.md

Triggers Activos

  • @TRIGGER-MC-COHERENCIA - Validar entity existe
  • @TRIGGER-MC-INVENTARIOS - Actualizar inventario

Validaciones Pre-Commit

# Validar sintaxis SQL
npm run db:validate

# Verificar RLS
grep -r "ENABLE ROW LEVEL SECURITY" database/schemas/

Patrones Requeridos

  1. Multi-tenancy: TODAS las tablas de negocio tienen tenant_id
  2. UUID Keys: Usar UUID para PKs, no SERIAL
  3. Timestamps: Incluir created_at y updated_at
  4. Soft Delete: Usar deleted_at cuando aplique
  5. Indices: Siempre indexar tenant_id

Modulos POS Principales

  • Auth/Tenants
  • Products (catalogo)
  • Inventory (stock)
  • Sales (punto de venta)
  • Customers (clientes y fiados)
  • Orders (pedidos)
  • Payments (integraciones de pago)

Referencias

  • @MC_DEF_DB - DATABASE-SCHEMA.md
  • @MC_INV_DB - DATABASE_INVENTORY.yml
  • @WS_PERFIL_DATABASE_AUDITOR - Perfil padre