← back to Costa Rica
TK-10346: hacienda-enricher opt-in HACIENDA_JURIDICA_ONLY filter (skips ~13k physical-person cedulas that permanently 400 on the company-only fe/ae endpoint); default behavior unchanged
b0d524e23007778420da427f60f872d3f2f43657 · 2026-08-07 16:36:12 -0700 · Steve
Files touched
M scripts/ingest/hacienda-enricher.js
Diff
commit b0d524e23007778420da427f60f872d3f2f43657
Author: Steve <steve@designerwallcoverings.com>
Date: Fri Aug 7 16:36:12 2026 -0700
TK-10346: hacienda-enricher opt-in HACIENDA_JURIDICA_ONLY filter (skips ~13k physical-person cedulas that permanently 400 on the company-only fe/ae endpoint); default behavior unchanged
---
scripts/ingest/hacienda-enricher.js | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/scripts/ingest/hacienda-enricher.js b/scripts/ingest/hacienda-enricher.js
index 8eab661..24abc1e 100644
--- a/scripts/ingest/hacienda-enricher.js
+++ b/scripts/ingest/hacienda-enricher.js
@@ -31,12 +31,18 @@ function normalizeCedula(c) {
);
const runId = runIns[0].id;
+ // The fe/ae endpoint only serves JURIDICAL (company) cedulas (first digit 3);
+ // physical-person cedulas permanently HTTP-400. HACIENDA_JURIDICA_ONLY=1 skips
+ // them so a drain doesn't waste ~13k throttled calls on rows that can never succeed.
+ const JURIDICA_ONLY = process.env.HACIENDA_JURIDICA_ONLY === '1';
+ const juridicaClause = JURIDICA_ONLY ? "AND cedula_juridica ~ '^3'" : '';
let q;
if (RETRY_ERRORS) {
q = `SELECT id, slug, cedula_juridica
FROM places
WHERE cedula_juridica IS NOT NULL
AND (hacienda_enriched_at IS NULL OR hacienda_error IS NOT NULL)
+ ${juridicaClause}
ORDER BY hacienda_enriched_at NULLS FIRST, id
LIMIT $1`;
} else {
@@ -44,6 +50,7 @@ function normalizeCedula(c) {
FROM places
WHERE cedula_juridica IS NOT NULL
AND hacienda_enriched_at IS NULL
+ ${juridicaClause}
ORDER BY id
LIMIT $1`;
}
← 2ce3bf8 yoloforever: cycle 2 ledger — TK-10346
·
back to Costa Rica
·
costa-rica: move root migration files into scripts/ so the m 3f07d61 →