The catalog step seeds each domain's mappings, and a mapping is written only if the function still holds

How: `catalog_rows` turns the TOML's study codes, captions and each value's code, label and aliases into the
`catalogo` system's rows; the `catalogs` step adds the system and the forms with no row yet
(`mapeos_nuevos`). `register` normalizes the form and adds the row through `SourceMappingRepository.add`
with `check_stored`, which runs `check_function` on the stored rows of the same form; captions aren't
checked, since one caption may introduce several results. `ctx.repos.silver.mappings` is the domain's
repository.

Implications: the database keeps every mapping across deploys; a person's change is never overwritten, and
a second code for a form in force is refused before it's written. Loads still read the TOML's aliases.
This commit is contained in:
rockdrigo
2026-11-13 15:31:21 -06:00
parent 64d3d721e3
commit 73cbf0cfb8
5 changed files with 138 additions and 11 deletions
+12 -2
View File
@@ -27,6 +27,7 @@ from webapi.orchestration.reference.support import (
grupos_de_edad_de,
)
from webapi.orchestration.reference.catalogs import catalogo_desde_toml, ruta_de_catalogo
from webapi.orchestration.reference.source_mapping import catalog_rows
from webapi.orchestration.reference.rules import (
RUTA_PARAMETROS,
leer_parametros,
@@ -66,9 +67,18 @@ def migrate(ctx: Context) -> str:
def catalogs(migrate: str, ctx: Context) -> dict[str, int]:
"""`core/catalogos/<proyecto>.toml` -> `cat_estudio`, `cat_resultado`, `cat_valor`: agrega, actualiza y retira; no borra."""
"""`core/catalogos/<proyecto>.toml` -> `cat_estudio`, `cat_resultado`, `cat_valor`: agrega, actualiza y retira; no borra.
Then the catalog's own mappings (`cat_mapeo`, system `catalogo`): only the forms with no row yet are added, so a
mapping edited in the application survives every deploy."""
catalogo = catalogo_desde_toml(ruta_de_catalogo(ctx.project), tablas=tablas_de(ctx.project))
return ctx.repos.silver.catalogs.sync(catalogo.estudios, catalogo.resultados, catalogo.valores)
counts = ctx.repos.silver.catalogs.sync(catalogo.estudios, catalogo.resultados, catalogo.valores)
mappings = ctx.repos.silver.mappings
if mappings is not None:
system, rows = catalog_rows(ctx.project, mappings)
mappings.ensure_system(system)
counts["mapeos_nuevos"] = mappings.seed(rows)
return counts
def load(catalogs: dict[str, int], ctx: Context) -> SQLModel: