Skip to content

Instantly share code, notes, and snippets.

@Subv
Created March 17, 2026 14:04
Show Gist options
  • Select an option

  • Save Subv/0fc2cd3c8cdfff4f747ba222f272022f to your computer and use it in GitHub Desktop.

Select an option

Save Subv/0fc2cd3c8cdfff4f747ba222f272022f to your computer and use it in GitHub Desktop.
-- =========================
-- Tabla: accountingJournalEntries
-- =========================
CREATE TABLE accountingJournalEntries (
id BIGINT PRIMARY KEY,
createdAt TIMESTAMP NOT NULL,
integratedAt TIMESTAMP NULL,
accountingDate DATE NOT NULL,
totalDebitAmount NUMERIC(18,2) NOT NULL,
totalCreditAmount NUMERIC(18,2) NOT NULL,
description TEXT NULL,
status VARCHAR(30) NOT NULL,
metadata JSONB NULL,
lastSendAttemptAt TIMESTAMP NULL,
lastSendError TEXT NULL,
sourceType VARCHAR(50) NULL,
sourceId VARCHAR(100) NULL,
CONSTRAINT chk_accountingJournalEntries_balanced
CHECK (totalDebitAmount = totalCreditAmount)
);
COMMENT ON TABLE accountingJournalEntries IS
'Representa un asiento contable que agrupa múltiples líneas contables generadas a partir de hechos de negocio ocurridos en Tango.';
COMMENT ON COLUMN accountingJournalEntries.id IS
'Llave primaria del asiento contable.';
COMMENT ON COLUMN accountingJournalEntries.createdAt IS
'Fecha y hora en que se creó el registro del asiento en Tango.';
COMMENT ON COLUMN accountingJournalEntries.integratedAt IS
'Fecha y hora en que el asiento fue integrado exitosamente al sistema contable.';
COMMENT ON COLUMN accountingJournalEntries.accountingDate IS
'Fecha contable con la que el asiento debe registrarse en contabilidad.';
COMMENT ON COLUMN accountingJournalEntries.totalDebitAmount IS
'Valor total de los débitos de todas las líneas asociadas al asiento. Debe ser igual al total de créditos.';
COMMENT ON COLUMN accountingJournalEntries.totalCreditAmount IS
'Valor total de los créditos de todas las líneas asociadas al asiento. Debe ser igual al total de débitos.';
COMMENT ON COLUMN accountingJournalEntries.description IS
'Descripción legible del asiento contable.';
COMMENT ON COLUMN accountingJournalEntries.status IS
'Estado actual del asiento contable, por ejemplo: draft, pending, integrated, failed o cancelled.';
COMMENT ON COLUMN accountingJournalEntries.metadata IS
'Campo JSON flexible para almacenar metadatos o información contextual adicional del asiento.';
COMMENT ON COLUMN accountingJournalEntries.lastSendAttemptAt IS
'Fecha y hora del último intento de envío o integración del asiento al sistema contable.';
COMMENT ON COLUMN accountingJournalEntries.lastSendError IS
'Mensaje de error del último intento fallido de envío o integración, si aplica.';
COMMENT ON COLUMN accountingJournalEntries.sourceType IS
'Tipo de hecho o entidad de negocio que originó el asiento, por ejemplo: order, payment o refund.';
COMMENT ON COLUMN accountingJournalEntries.sourceId IS
'Identificador de la entidad o hecho de negocio en Tango que originó el asiento.';
COMMENT ON CONSTRAINT chk_accountingJournalEntries_balanced ON accountingJournalEntries IS
'Garantiza que el asiento esté cuadrado, es decir, que el total de débitos sea igual al total de créditos.';
-- =========================
-- Tabla: accountingJournalEntryLines
-- =========================
CREATE TABLE accountingJournalEntryLines (
id BIGINT PRIMARY KEY,
accountingJournalEntryId BIGINT NOT NULL REFERENCES accountingJournalEntries(id),
createdAt TIMESTAMP NOT NULL,
debitAmount NUMERIC(18,2) NOT NULL DEFAULT 0,
creditAmount NUMERIC(18,2) NOT NULL DEFAULT 0,
ledgerAccountId BIGINT NOT NULL,
description TEXT NULL,
metadata JSONB NULL,
thirdPartyIdentification VARCHAR(100) NULL,
CONSTRAINT chk_accountingJournalEntryLines_debitCreditXor
CHECK (
(debitAmount > 0 AND creditAmount = 0)
OR
(creditAmount > 0 AND debitAmount = 0)
)
);
COMMENT ON TABLE accountingJournalEntryLines IS
'Representa las líneas contables individuales de un asiento, cada una afectando una cuenta contable específica.';
COMMENT ON COLUMN accountingJournalEntryLines.id IS
'Llave primaria de la línea contable.';
COMMENT ON COLUMN accountingJournalEntryLines.accountingJournalEntryId IS
'Llave foránea que referencia el asiento contable al que pertenece la línea.';
COMMENT ON COLUMN accountingJournalEntryLines.createdAt IS
'Fecha y hora en que se creó el registro de la línea contable en Tango.';
COMMENT ON COLUMN accountingJournalEntryLines.debitAmount IS
'Valor débito de la línea. Debe ser mayor a cero únicamente cuando el crédito sea cero.';
COMMENT ON COLUMN accountingJournalEntryLines.creditAmount IS
'Valor crédito de la línea. Debe ser mayor a cero únicamente cuando el débito sea cero.';
COMMENT ON COLUMN accountingJournalEntryLines.ledgerAccountId IS
'Identificador de la cuenta contable del catálogo que afecta esta línea.';
COMMENT ON COLUMN accountingJournalEntryLines.description IS
'Descripción legible de la línea contable.';
COMMENT ON COLUMN accountingJournalEntryLines.metadata IS
'Campo JSON flexible para almacenar metadatos o información contextual adicional de la línea.';
COMMENT ON COLUMN accountingJournalEntryLines.thirdPartyIdentification IS
'Identificación del tercero asociado a la línea, por ejemplo cliente, proveedor u otro tercero contable.';
COMMENT ON CONSTRAINT chk_accountingJournalEntryLines_debitCreditXor ON accountingJournalEntryLines IS
'Garantiza que una línea contable tenga valor débito o valor crédito, pero nunca ambos al mismo tiempo.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment