Repository navigation
fix(seed): rename the purchased-goods dimension from Destino to Origen - #644
Merged
Merged
Conversation
mrivas00
force-pushed
the
fix/mati/purchased-goods-origin
branch
3 times, most recently
from
September 21, 2026 15:32
e54cfbc to
d84e182
Compare
nivek0o0
reviewed
Sep 24, 2026
nivek0o0
left a comment
Collaborator
There was a problem hiding this comment.
1. Executive Summary
A small, well-scoped label fix. The migration and its write-up are careful work. Production readiness: Approve with Comments.
I checked these against the code and they hold:
- Targeting. The join path (
subcategory → category "Otras emisiones indirectas" → methodology_version "Metodología inicial" → country "PD") matches exactly whereProductos comprados_Destinosits inbase/methodologies.json. Matching oncoderather thannamecorrectly keeps theDisposición de residuos sólidos"Destino" dimension out of range. - Index safety. The
d."status" <> 'DELETED'filter matches the predicate ofemission_factor_dimension_subcategory_id_code_active_unique, so it targets at most one row per subcategory.nameis not part of any unique index, so the rename cannot collide. - Idempotency.
IS DISTINCT FROM 'Origen'makes a re-run a no-op, the same shape as20260825150000_update_business_travel_transport_explanation. - Migration discipline. It is a new additive migration and no existing one is edited. The timestamp
20260915150000sorts after20260915140000as the PR states. - No name-keyed consumers. Nothing in
apps/api,apps/webortools/seedlooks up a dimension byname. Emission factors reference it bydimensionCode, and the web only displaysname(maintainer screens, Excel export). The rename cannot break factor resolution or captured lines. - Scope. The diff matches the description, with no scope creep. CI is green.
3. Prioritized Findings
- 🟢 Low · Maintainability:
tools/seed/src/data/testing/methodologies.json:2613still names the dimension "Destino". Depending on when an environment was seeded, the testing dataset shows either label. Earlier content PRs (#606, #609, #619) kept both datasets in sync. Details are in the inline comment.
8. Final Recommendation
I'd approve once the testing dataset gets the same one-line rename (the author can decline it, since it only affects the testing dataset). The migration is correct, idempotent, scoped the same way as existing precedent, and touches only a display label. It changes no key, factor, captured value or computed total.
Advisory review: submitted as COMMENT.
Its values are "Primera mano", "Reutilizado" and "Con material reciclado", which describe where the purchased material comes from. "Destino" was inherited from the waste subcategory, where it is the correct word and stays — that is a separate dimension with its own code and is untouched. The `code` keeps its historical "Productos comprados_Destino" value: it is the key every emission factor of the subcategory references the dimension by, and it backs a partial unique index. Renaming it would move a key to fix a label.
The seed cannot carry the rename above to an installed deployment: seed.ts aborts the whole run when the database already contains data, so a running instance keeps serving the name it was seeded with. Same shape as the guide updates in 20260825150000: matched through the demo country's base methodology, so a country that maintains its own methodology decides for itself, and guarded by IS DISTINCT FROM so re-running touches zero rows. Verified against a scratch database seeded with the pre-migration state: one row updated on the first pass and zero on the second, with the waste dimension and a second country's rows left as they were.
…data Keeps the testing dataset in sync with base: fresh testing databases are seeded after migrations run, so the migration alone left them showing Destino.
mrivas00
force-pushed
the
fix/mati/purchased-goods-origin
branch
from
September 24, 2026 20:27
d3d6923 to
edf7026
Compare
nivek0o0
approved these changes
Sep 24, 2026
nivek0o0
left a comment
Collaborator
There was a problem hiding this comment.
Checked the follow-up and it looks good:
- The testing dataset now labels the dimension "Origen" too, with the
codeunchanged (16b60e8), so both seed files match. - The manual-testing doc table is updated (edf7026). The remaining "Destino" there belongs to the waste subcategory, where it's correct.
- The migration was renamed to
20260924120000and now sorts after the migrations merged since. The SQL is identical to the version reviewed earlier, and none of the new migrations touchemission_factor_dimension.
CI is green. Approving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Key changes & decisions
1. The seed label
tools/seed/src/data/base/methodologies.json· dd91382,tools/seed/src/data/testing/methodologies.json· 16b60e8namebecomes "Origen". Exactly one of the two"name": "Destino"entries in the file changes; the waste one is left. Thetestingdataset carries the same PD / "Metodología inicial" dimension and gets the same one-line change, keeping both datasets in sync as the earlier methodology-content PRs did (fresh testing databases are seeded after migrations run, so the migration alone would leave them on "Destino"). The manual-testing doc table header follows along (edf7026).codekeeps its historicalProductos comprados_Destinovalue. It is the key every emission factor of the subcategory references the dimension by (19 references in the same file) and it backs a partial unique index on("subcategory_id", "code"). Renaming it would move a key to fix a label — the same trade-off as the rate-unit abbreviation in the CO₂e PR, resolved the same way.2. The migration that lands it on installed deployments
packages/database/.../20260924120000_rename_purchased_goods_dimension_to_origin· 32f9227seed.tsaborts the whole run when the database already contains data (the country-count gate), so a running instance keeps serving the name it was seeded with. The seed edit alone reaches only fresh installs.UPDATE, matched by the dimension'scodeand scoped throughcategory → methodology_version → countryto the demo country's base methodology.20260825150000_update_business_travel_transport_explanation: scoping to the demo country's methodology means a country deployment maintaining its own methodology decides for itself, andIS DISTINCT FROM 'Origen'makes a re-run touch zero rows. Matching oncoderather than on the oldnameis what keeps the waste dimension out of range even though it carried the same name.Test plan
Gates that ran on this branch:
pnpm formatpnpm lint— 13/13, zero warningspnpm type-check— 13/13pnpm test:api -- /countrySectors/getAllCountrySectors --coverage=false— 15 tests passing, re-run after the rebase. This boots a Testcontainers Postgres and applies the full migration chain, so it proves the new migration is valid SQL and does not break the chain. It does not prove the rename targets the right row: that database is created empty, so the migration runs before any data exists.Targeting and idempotency verified separately (before the latest rebase; the migration SQL is byte-identical since, only its folder timestamp changed) against a scratch Postgres: full chain applied with
prisma migrate deploy, then rows inserted to mimic a seeded database — the demo countryPDand a second countryCL, each with both aProductos comprados_Destinoand aDisposición de residuos sólidos_Destinodimension, all four named "Destino". Result:First pass reported
UPDATE 1, second passUPDATE 0.codeunchanged on every row.Manual smoke checks (the app was not launched for this PR):
Risk / blast radius
emission_factor_dimension. No factor, no dimension value, no captured line and no computed total is touched.20260915150000→20260924120000, so it sorts after the three migrations merged meanwhile (20260915160000,20260916120000,20260921120000) and the folder order matches the apply order. None of them touch the tables thisUPDATEreads or writes, and the SQL is unchanged.Out of scope