Especificación Técnica: mae_empresas¶
Esquema: core.identidad
Base de Datos: core
Servicio: svc-identidad
Tabla Legacy Origen: core_sigfa.mae_empresas
Propósito: Maestro de empresas del núcleo; identidad organizacional raíz para empresas, sucursales y operación.
1. Justificación y Mejoras de Arquitectura¶
- PK BIGINT con identity: integración natural con sistemas legados y jerarquías existentes.
- Identificación con tipo/pais/ciudad referenciados por UUID (F3 del modelo docs-site).
- Unique sobre identificacion evita dobles registros tributarios.
- Evolución del legacy core_sigfa.mae_empresas en core.identidad.
2. Definiciones de Implementación¶
Table core.identidad.mae_empresas {
id bigint [pk]
razon_social varchar(200) [not null]
nombre_comercial varchar(200)
identificacion varchar(20) [not null]
pais_id uuid [ref: > cat_paises.id]
ciudad_id uuid [ref: > cat_ciudades.id]
tipo_identificacion_id uuid [ref: > cat_tipos_identificacion.id]
zona_horaria varchar(50)
logo_documento_id uuid [ref: > mae_documentos.id]
direccion varchar(300)
telefono varchar(20)
email varchar(150)
// 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 {
(identificacion) [unique, name: 'uq_mae_empresas_identificacion']
}
}
CREATE TABLE IF NOT EXISTS core.identidad.mae_empresas (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
razon_social VARCHAR(200) NOT NULL,
nombre_comercial VARCHAR(200),
identificacion VARCHAR(20) NOT NULL,
pais_id UUID,
ciudad_id UUID,
tipo_identificacion_id UUID,
zona_horaria VARCHAR(50),
logo_documento_id UUID,
direccion VARCHAR(300),
telefono VARCHAR(20),
email VARCHAR(150),
-- 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_empresas_identificacion UNIQUE (identificacion),
CONSTRAINT fk_mae_empresas_pais FOREIGN KEY (pais_id) REFERENCES core.identidad.cat_paises (id),
CONSTRAINT fk_mae_empresas_ciudad FOREIGN KEY (ciudad_id) REFERENCES core.identidad.cat_ciudades (id),
CONSTRAINT fk_mae_empresas_tipo_identificacion FOREIGN KEY (tipo_identificacion_id) REFERENCES core.identidad.cat_tipos_identificacion (id),
CONSTRAINT fk_mae_empresas_logo_documento FOREIGN KEY (logo_documento_id) REFERENCES core.identidad.mae_documentos (id)
);
-- Comentarios
COMMENT ON COLUMN core.identidad.mae_empresas.razon_social IS 'Razón social de la empresa';
COMMENT ON COLUMN core.identidad.mae_empresas.nombre_comercial IS 'Nombre comercial';
COMMENT ON COLUMN core.identidad.mae_empresas.identificacion IS 'Número de identificación fiscal';
COMMENT ON COLUMN core.identidad.mae_empresas.pais_id IS 'País de la empresa';
COMMENT ON COLUMN core.identidad.mae_empresas.ciudad_id IS 'Ciudad de la empresa';
COMMENT ON COLUMN core.identidad.mae_empresas.tipo_identificacion_id IS 'Tipo de identificación';
COMMENT ON COLUMN core.identidad.mae_empresas.zona_horaria IS 'Zona horaria IANA (ej: America/Guayaquil)';
COMMENT ON COLUMN core.identidad.mae_empresas.logo_documento_id IS 'Documento que contiene el logo de la empresa';
COMMENT ON COLUMN core.identidad.mae_empresas.direccion IS 'Dirección principal';
COMMENT ON COLUMN core.identidad.mae_empresas.telefono IS 'Teléfono principal';
COMMENT ON COLUMN core.identidad.mae_empresas.email IS 'Correo principal';