Skip to main content

PostgreSQL - Diagrama ER y diccionario de datos

Convenciones​

  • Todas las tablas usan BIGSERIAL solo para PK tecnicas, y UUID para las claves de negocio cuando aplique.
  • Campos de auditoria: created_at, updated_at, created_by, updated_by.
  • Soft delete (donde aplique): deleted_at TIMESTAMP NULL.
  • Timezone: todos los timestamps en TIMESTAMPTZ (UTC).

Diagrama ER Mermaid​


Diccionario de datos​

Tabla partner​

PropósitoLlave primariaAudit fields
Catálogo de partners o socios (GEPP, Compañía B, etc.)id uuidcreated_at, updated_at

Campos:

CampoTipoDescripciónConstraints
iduuidPK técnicaPRIMARY KEY
partner_idvarchar(64)Clave de negocio (GEPP, etc.)UNIQUE NOT NULL
namevarchar(200)Nombre comercialNOT NULL
statusvarchar(16)ACTIVE / INACTIVENOT NULL, check in list
default_company_idvarchar(64)Company por defectoNULL
created_attimestamptzAltaNOT NULL default now()
updated_attimestamptzUltima actualizacionNOT NULL default now()

Indices: idx_partner_status(status).


Tabla partner_configuration​

PropósitoLlave primariaAudit fields
Configuracion parametrica por partner (mapeos, credencial refs, etc.)id uuidcreated_at, updated_at

Campos:

CampoTipoDescripciónConstraints
iduuidPKPRIMARY KEY
partner_iduuidFK a partnerNOT NULL REFERENCES partner(id)
config_keyvarchar(120)Clave (ej: fusion.credentials.ref)NOT NULL
config_valuejsonbValor JSONNOT NULL
versionintVersion semantico de la configuracionNOT NULL default 1
descriptionvarchar(255)NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Unique: UNIQUE(partner_id, config_key) (upsert por key). Indices: GIN idx_partner_config_value ON partner_configuration USING GIN(config_value).


Tabla validation_rule​

PropósitoLlave primariaAudit fields
Metadata de regla de validaciónid uuidcreated_at, updated_at, created_by, updated_by

Campos:

CampoTipoDescripciónConstraints
iduuidPKPRIMARY KEY
codevarchar(80)Código funcional (SUPPLIER_REQUIRED etc.)NOT NULL
partner_idvarchar(64)Partner (puede ser GLOBAL)NOT NULL
company_idvarchar(64)NULL indica todas las companiesNULL
source_systemvarchar(80)NULL indica todos los sistemasNULL
document_typesvarchar(255)[]Tipos de documento a los que aplicaNULL
groupvarchar(16)STRUCTURAL SYNTACTIC SEMANTIC BUSINESSNOT NULL
priorityintOrden 1..9999NOT NULL
statusvarchar(16)DRAFT ACTIVE INACTIVENOT NULL
created_byvarchar(120)Usuario/Service AccountNOT NULL
updated_byvarchar(120)NOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Indices:

  • UNIQUE(partner_id, company_id, source_system, code) con NULLS NOT DISTINCT
  • idx_vrule_status(status)
  • idx_vrule_scope(partner_id, company_id, source_system, status, priority)

Tabla validation_rule_version​

PropósitoLlave primariaAudit fields
Versionado de la expresion de regla (la definicion ejecutable)id uuidpublished_at, published_by

Campos:

CampoTipoDescripciónConstraints
iduuidPKPRIMARY KEY
rule_iduuidFK a validation_ruleNOT NULL REFERENCES validation_rule(id)
majorintVersion mayorNOT NULL
minorintVersion menorNOT NULL
expression_languagevarchar(32)Fijo NEXUS_RULE_DSLNOT NULL
expressiontextExpresion DSL (no codigo arbitrario)NOT NULL
severityvarchar(16)WARNING ERROR FATALNOT NULL
error_templatejsonbPlantilla del error (ValidationError)NOT NULL
published_attimestamptzNULL
published_byvarchar(120)NULL

Unique: UNIQUE(rule_id, major, minor). Indices: idx_vrv_rule_current(rule_id, major DESC, minor DESC).


Tabla purchase_order_request​

PropósitoLlave primariaAudit fields
Solicitud de OC (ciclo de vida end-to-end). La PK id es el requestId público.id uuidcreated_at, updated_at

Campos:

CampoTipoDescripciónConstraints
iduuidrequestId publicoPRIMARY KEY
partner_idvarchar(64)Partner origenNOT NULL
company_idvarchar(64)NOT NULL
source_systemvarchar(80)NOT NULL
external_referencevarchar(120)Referencia del socio (PO-123456)NOT NULL
idempotency_keyvarchar(128)NOT NULL
document_typevarchar(32)NOT NULL
statusvarchar(32)Estado actual de la maquinaNOT NULL
attemptintNumero de intentos (retry)NOT NULL default 1
submitted_attimestamptzHora de ingreso reportada por clienteNULL
request_jsonjsonbPayload canónico completoNOT NULL
canonical_hashuuidHash SHA256 del payload (duplicados funcionales)NULL
custom_fieldsjsonbCampos extendidosNULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Constraints de unicidad (claves de idempotencia):

  • UNIQUE(partner_id, idempotency_key) (API, Idempotency-Key)
  • UNIQUE(partner_id, source_system, external_reference) (Referencia externa por origen, preventiva)
  • UNIQUE(canonical_hash) (opcional, activable por partner)

Indices:

  • idx_po_req_status(status, updated_at DESC)
  • idx_po_req_partner(partner_id, company_id, source_system)
  • idx_po_req_created_at(created_at)
  • idx_po_req_external(external_reference, partner_id)

Tabla transaction_status_history​

PropósitoLlave primariaAudit fields
Registro de todas las transiciones de estado del request (historial inmutable).id bigserialat

Campos:

CampoTipoDescripciónConstraints
idbigserialPK tecnicaPRIMARY KEY
request_iduuidFK a purchase_order_requestNOT NULL
from_statusvarchar(32)NULL
to_statusvarchar(32)NOT NULL
event_iduuideventId que disparo la transicionNULL
componentvarchar(64)PO_API WORKER PUBLISHER MANUAL etc.NOT NULL
reasonvarchar(255)NULL
metadatajsonbNULL
attimestamptzNOT NULL default now()

Indices: idx_tsh_request_id(request_id, at).


Tabla validation_result​

PropósitoLlave primariaAudit fields
Resultado de ejecucion de reglas por requestid uuidat

Campos:

CampoTipoDescripciónConstraints
iduuidPKPRIMARY KEY
request_iduuidFKNOT NULL
rule_version_iduuidFK a la version de regla que se ejecutoNULL
validbooleanResultado final del bloque ejecutadoNOT NULL
errorsjsonbArray de ValidationErrorNULL
duration_msintTiempo de ejecucionNULL
attimestamptzNOT NULL default now()

Indices: idx_vr_request(request_id, at).


Tabla purchase_order​

PropósitoLlave primariaAudit fields
Orden de Compra creada en Oracle Fusionid uuidcreated_at, updated_at

Campos:

CampoTipoDescripciónConstraints
iduuidPKPRIMARY KEY
request_iduuidFK 1-1 con requestUNIQUE NOT NULL REFERENCES purchase_order_request(id)
oracle_purchase_ordervarchar(32)Id Fusion (mostrado al cliente)NOT NULL
oracle_po_numbervarchar(32)Numero de PO (visible en Fusion)NULL
total_amountnumeric(20,6)TotalNOT NULL
currency_codechar(3)ISO 4217NOT NULL
oracle_created_attimestamptzHora reportada por FusionNULL
supplier_codevarchar(64)NOT NULL
buyer_emailvarchar(200)NULL
fusion_payload_idvarchar(128)RequestId Fusion (para soporte)NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Unique: UNIQUE(oracle_purchase_order) (cada OC de Fusion se registra una vez). Indices: idx_po_oracle_num(oracle_po_number), idx_po_request(request_id).


Tabla purchase_order_line​

PropósitoLlave primariaAudit fields
Linea de la OC en Fusionid uuidSin audit fields individuales; se propaga de purchase_order.

Campos:

CampoTipoDescripciónConstraints
iduuidPKPRIMARY KEY
purchase_order_iduuidFKNOT NULL REFERENCES purchase_order(id)
line_numberintPosicion 1..NNOT NULL
skuvarchar(60)SKU del articuloNOT NULL
upcvarchar(40)NULL
descriptionvarchar(250)NOT NULL
quantitynumeric(20,6)NOT NULL
uomvarchar(12)UOM estandarNOT NULL
unit_pricenumeric(20,6)NOT NULL
line_amountnumeric(20,6)NOT NULL
cost_centervarchar(40)NULL
gl_codevarchar(120)NULL
custom_fieldsjsonbNULL

Unique: UNIQUE(purchase_order_id, line_number). Indices: idx_pol_order(purchase_order_id).


Tabla integration_error​

PropósitoLlave primariaAudit fields
Registro de errores de integracion (validacion, Fusion, temporales, etc.)id bigserialat

Campos:

CampoTipoDescripciónConstraints
idbigserialPKPRIMARY KEY
request_iduuidFKNOT NULL
event_iduuidEvento (Pub/Sub) que genero el errorNULL
error_categoryvarchar(32)Ver taxonomia 8 categoriasNOT NULL
error_codevarchar(80)Codigo funcionalNOT NULL
messagetextNOT NULL
attemptintIntento al momento del errorNULL
componentvarchar(64)WORKER / PO_API / VALIDATION_ENGINE etc.NULL
detailsjsonbPayload de contextoNULL
attimestamptzNOT NULL default now()

Indices: idx_ierr_request(request_id, at), idx_ierr_cat(error_category, at).


Tabla outbox_event​

PropósitoLlave primariaAudit fields
Patrón Transactional Outbox: eventos pendientes de publish a Pub/Sub.id bigserialcreated_at, processed_at

Campos:

CampoTipoDescripciónConstraints
idbigserialPK (para SKIP LOCKED polling)PRIMARY KEY
event_iduuidId de negocio del eventoUNIQUE NOT NULL
request_iduuidFK al requestNOT NULL
topicvarchar(120)Topic Pub/Sub destinoNOT NULL
event_typevarchar(64)PURCHASE_ORDER_REQUESTED, RETRY_REQUESTED, etc.NOT NULL
versionintVersion schema (1, 2...)NOT NULL default 1
partner_idvarchar(64)NOT NULL
company_idvarchar(64)NULL
source_systemvarchar(80)NULL
ordering_keyvarchar(120)Para ordering de Pub/Sub (opcional por partner)NULL
payloadjsonbEnvelope completo publishableNOT NULL
attributesjsonbAttributes Pub/Sub (traceparent, etc.)NULL
processedbooleanNOT NULL default false
retriesintNOT NULL default 0
next_process_attimestamptzBackoff exponencial internoNOT NULL default now()
instancevarchar(120)Pod/instancia que lo procesaraNULL
created_attimestamptzNOT NULL default now()
processed_attimestamptzNULL

Indices:

  • idx_outbox_pending(processed, next_process_at, id) para el polling del publisher.
  • idx_outbox_request(request_id, created_at).
  • idx_outbox_event_id(event_id).

Tabla processed_event​

PropósitoLlave primariaAudit fields
Idempotent Consumer - registro de eventos ya procesados por worker.event_id uuidprocessed_at

Campos:

CampoTipoDescripciónConstraints
event_iduuidPK del evento Pub/SubPRIMARY KEY
request_iduuidFK al requestNOT NULL
topicvarchar(120)NOT NULL
consumer_instancevarchar(120)NULL
outcomevarchar(32)CREATED / FAILED / SKIPPED etc.NULL
processed_attimestamptzNOT NULL default now()

Indices: idx_pe_request(request_id).


Tabla audit_event​

PropósitoLlave primariaAudit fields
Registro inmutable de acciones relevantes (requests, reintentos, cambios de reglas, configuraciones).id bigserialat

Campos:

CampoTipoDescripciónConstraints
idbigserialPKPRIMARY KEY
request_iduuidNULL
rule_iduuidNULL
partner_idvarchar(64)NULL
user_idvarchar(120)Usuario o service accountNOT NULL
componentvarchar(64)PO_API CONFIG_API WORKER OPERATOR etc.NOT NULL
event_codevarchar(64)REQUEST_RECEIVED RULE_UPDATED RETRY_REQUESTED etc.NOT NULL
metadatajsonbNULL
attimestamptzNOT NULL default now()

Indices: idx_ae_request(request_id, at), idx_ae_rule(rule_id, at), idx_ae_event(event_code, at).


Triggers y convenciones​

Automatizacion recomendada
  • Todas las tablas con updated_at deben llevar un trigger BEFORE UPDATE que setea updated_at = now().
  • purchase_order_request y transaction_status_history deben ser particionables por created_at (mensual o semanal) cuando la volumetria lo requiera.
  • outbox_event y processed_event con TTL retention (TBD según política operativa), se recomiendan particiones por fecha.