Especificación Técnica: mae_grupos_destinatarios¶
Esquema: core.notificaciones
Base de Datos: core
Servicio: svc-notificaciones
Propósito: Grupos de destinatarios por empresa para dirigir mensajes a un conjunto de usuarios sin enumerarlos en cada envío.
1. Justificación y Mejoras de Arquitectura¶
- Maestro con tenencia por empresa: cada grupo pertenece a una única empresa.
- Llave alterna
uq_mae_grupos_destinatarios_empresa_id UNIQUE (empresa_id, id): habilita la FK compuesta derel_grupo_destinatario_usuarioy el motor impide cruzar filas entre empresas. - Unique parcial
UNIQUE (empresa_id, codigo) WHERE deleted_at IS NULL: un código de grupo por empresa; reutilizable tras borrado lógico. - Sin dependencias internas: se crea antes que la relación N:M con usuarios.
2. Definiciones de Implementación¶
Table core.notificaciones.mae_grupos_destinatarios {
id uuid [pk, default: `gen_random_uuid()`]
empresa_id bigint [not null]
codigo text [not null]
nombre text [not null]
// Auditoría General
is_activo boolean [not null, default: `true`, note: 'Estado lógico del registro']
created_at timestamptz [not null, default: `now()`, note: 'Fecha de creación']
updated_at timestamptz [not null, default: `now()`, note: 'Fecha de última actualización']
deleted_at timestamptz [note: 'Fecha de eliminación lógica']
created_by uuid [note: 'Usuario creador']
updated_by uuid [note: 'Usuario modificador']
Indexes {
(empresa_id, id) [unique, name: 'uq_mae_grupos_destinatarios_empresa_id']
(empresa_id, codigo) [unique, name: 'uq_mae_grupos_destinatarios_empresa_codigo', note: 'WHERE deleted_at IS NULL']
(empresa_id) [name: 'ix_mae_grupos_destinatarios_empresa_id']
}
}
CREATE TABLE IF NOT EXISTS core.notificaciones.mae_grupos_destinatarios (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
empresa_id BIGINT NOT NULL,
codigo TEXT NOT NULL,
nombre TEXT NOT NULL,
-- Auditoría General
is_activo BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
deleted_at TIMESTAMPTZ,
created_by UUID,
updated_by UUID,
CONSTRAINT uq_mae_grupos_destinatarios_empresa_id UNIQUE (empresa_id, id)
);
CREATE UNIQUE INDEX IF NOT EXISTS uq_mae_grupos_destinatarios_empresa_codigo ON core.notificaciones.mae_grupos_destinatarios (empresa_id, codigo) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS ix_mae_grupos_destinatarios_empresa_id ON core.notificaciones.mae_grupos_destinatarios (empresa_id);
-- Comentarios
COMMENT ON COLUMN core.notificaciones.mae_grupos_destinatarios.empresa_id IS 'Empresa propietaria del grupo';
COMMENT ON COLUMN core.notificaciones.mae_grupos_destinatarios.codigo IS 'Código único del grupo por empresa';
COMMENT ON COLUMN core.notificaciones.mae_grupos_destinatarios.nombre IS 'Nombre descriptivo del grupo';