Skip to content

Issue #1513: feat: convert the seed's overlays and clean it as dev was cleaned - #1520

Merged
bjagg merged 4 commits into
mainfrom
issue-1513-convert-seed
Nov 17, 2026
Merged

bjagg merged 4 commits into
mainfrom
issue-1513-convert-seed

Conversation

@bjagg

@bjagg bjagg commented Nov 16, 2026

Copy link
Copy Markdown
Contributor
Description of Change

Steps 3–5 of #1513, first part: backup.sql gets what dev got in #1388 and #1393. In both public and tenant_lif_team:

  1. scripts/cleanup_export_blockers.py --apply (Issue #1393: feat: one-time cleanup of the data that keeps models and groups from exporting #1444's rules)
  2. scripts/remove_test_data.py --apply (model 25 and the pinned test rows)
  3. scripts/convert_overlays.py --apply (models 17 and 18 become self-contained; its self-check passed for models 1, 16, 17 and 18 in all 16 flag combinations, in both schemas)
  4. Model 16 removed, as on dev: the model, its 15 entities, 59 attributes, the 10 entity associations with an end in it, and groups 15 and 16. No script does this, so it's the SQL below, which checks each count before it writes. Nothing else referenced the model.

This is Dereck's order from his hand-off. Replacing models 3, 6, 14 and 17 with dev's content and removing 29 (the decision) is the next PR.

What export refuses afterwards (scripts/measure_export_blockers.py):

Schema Before After
public 3 of 21 models export, 2 overlays; 2 of 9 groups 15 of 19 models; 6 of 6 groups
tenant_lif_team 1 of 20 models, 2 overlays 18 of 18 models; 6 of 6 groups

public's 4 refusals are models 3, 6, 14 and 29, all for attributes with DataType entity, which the next PR replaces.

How the dump was made, and how it was checked
  • Same tools as the last regeneration. backup.sql says pg_dump 18.6 (Debian 18.6-1.pgdg13+2), so everything ran in a postgres:18.6 container. The seed was loaded as restore.sh does it (backup.sql, then every V1.*.sql except V1.1).
  • No dump noise. A dump of an unchanged copy matches main's backup.sql line for line, except pg_dump 18's random \restrict token. So every other changed line comes from the steps above.
  • Every changed row is accounted for. No table's schema changed and no row was deleted; only data rows and sequence values moved. Of the 4,204 rows that differ, 4,030 are ones the three scripts reported (their output and convert_overlays.py's undo records), and the other 174 are model 16's removal (87 per schema). Rows added are exactly the conversion's copies: 37 entities, 157 attributes, 2 value sets, 124 values, 50 entity associations and 229 attribute associations per schema.
  • The migrations replay cleanly on top. Loading the new dump and replaying V1.2–V1.11, as restore.sh does, changes no row (the two dumps are equal as sets of lines; a few rows only move position).
Model 16's removal
DO $$
DECLARE s text; n bigint;
BEGIN
  FOREACH s IN ARRAY ARRAY['public', 'tenant_lif_team'] LOOP
    EXECUTE format('SELECT count(*) FROM %I."Entities" WHERE "DataModelId" = 16 AND NOT "Deleted"', s) INTO n;
    IF n <> 15 THEN RAISE EXCEPTION '%: % entities, expected 15', s, n; END IF;
    EXECUTE format('SELECT count(*) FROM %I."Attributes" WHERE "DataModelId" = 16 AND NOT "Deleted"', s) INTO n;
    IF n <> 59 THEN RAISE EXCEPTION '%: % attributes, expected 59', s, n; END IF;
    EXECUTE format('UPDATE %I."EntityAssociation" SET "Deleted" = true WHERE NOT "Deleted" AND ("ParentEntityId" IN (SELECT "Id" FROM %I."Entities" WHERE "DataModelId" = 16) OR "ChildEntityId" IN (SELECT "Id" FROM %I."Entities" WHERE "DataModelId" = 16))', s, s, s);
    GET DIAGNOSTICS n = ROW_COUNT; IF n <> 10 THEN RAISE EXCEPTION '%: % entity associations, expected 10', s, n; END IF;
    EXECUTE format('UPDATE %I."Attributes" SET "Deleted" = true WHERE "DataModelId" = 16 AND NOT "Deleted"', s);
    EXECUTE format('UPDATE %I."Entities" SET "Deleted" = true WHERE "DataModelId" = 16 AND NOT "Deleted"', s);
    EXECUTE format('UPDATE %I."TransformationsGroup" SET "Deleted" = true WHERE "Id" IN (15, 16) AND NOT "Deleted" AND (16 IN ("SourceDataModelId", "TargetDataModelId"))', s);
    GET DIAGNOSTICS n = ROW_COUNT; IF n <> 2 THEN RAISE EXCEPTION '%: % groups, expected 2', s, n; END IF;
    EXECUTE format('UPDATE %I."DataModels" SET "Deleted" = true WHERE "Id" = 16 AND NOT "Deleted"', s);
    GET DIAGNOSTICS n = ROW_COUNT; IF n <> 1 THEN RAISE EXCEPTION '%: model 16 not live', s; END IF;
  END LOOP;
END $$;
Tests

The converted seed failed 62 tests. Dereck counted 61 before model 16's removal.

Tests that need overlays keep the old seed, as a fixture (Dereck's option (a)). test/fixtures/backup-unconverted.sql is main's backup.sql byte for byte, so it's the same git blob that's already in history and adds nothing to the repository's size. Its tests stay meaningful: the one-time scripts still have to run on unconverted data (demo, step 6), and the overlay code paths still exist for demo.

  • test/scripts: cleanup_export_blockers, convert_overlays, remove_test_data and measure_overlay_conversion load the fixture (23 tests).
  • test/bases/lif/mdr_restapi: conftest.py gains unconverted_postgres and unconverted_db_session. test_overlay_converter, test_overlay_attribute_list, test_overlay_attribute_inclusions and test_base_model_lookup override seed_postgres / test_db_session with them, so their API-client tests run on it too (17 tests).

Tests changed for the new seed:

  • test_v1_7_portability_columns_sql, test_v1_10_element_flags_resync_sql: they relied on the seed's live own-element inclusion rows, which were on models 17 and 18. Each now inserts the inclusion row it checks, with flags that aren't the defaults, so it doesn't depend on the seed.
  • test_schema_generation_element_flags: its precondition was "17 is an overlay". Model 17 is still Type OrgLIF and now has no inclusion rows, so the precondition is inverted, which states the test's point (Type doesn't make an overlay) more directly.
  • test_portable_seed_round_trip: 15 models now export (was 3), so the groups and crosswalks on model 1 round-trip too, byte for byte. The first install's sequences now start at 500 as well as the second's at 1000, so their Ids can't overlap the seed's.
  • test_crosswalk_converter: 6 crosswalks and 714 entries. 343 → 347 was model 25's test value set.
  • test_portable_endpoints: the not-migrated example is model 3, since model 1 now exports.
  • test_measure_export_blockers: the figures above.
  • Schema snapshots, regenerated. Every changed output was diffed against the old seed's, value by value:
    • models 3, 4, 6, 10, 13, 14, 26 and 29 are unchanged;
    • 2, 5, 7, 8, 9, 11, 12 and 15 change only DataType → string (cleanup);
    • model 1 changes the DataModelId of the 8 attributes the conversion moved, and value 3649's Extension (cleanup);
    • 17 and 18 change only Ids from the conversion's Id map, Extension true → false and AssociationExtendedByDataModelId 17 → null on what are now their own elements, and the order (never the set) of required lists. Model 18 also loses TestEntity5, test data;
    • 16 and 25 are deleted and left the manifest.

Docs: the handbook (backend chapters 3 and 7, frontend chapter 2) now says the local seed is converted and only demo still has overlays.

test/scripts, test/bases/lif/mdr_restapi and test/components/lif/mdr_services: 729 passed, 1 skipped (PG 16.15 locally). Two fewer than before because models 16 and 25 left the snapshot set.

Related Issues

Refs #1513

Type of Change
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update
Project Area(s) Affected
  • projects/
  • test/ or e2e/
  • Documentation (docs/, READMEs, ARCHITECTURE.md, CLAUDE.md)

Checklist
  • commit message follows commit guidelines (see commitlint.config.mjs)
  • tests are included (unit and/or integration tests)
  • code passes linting checks (uv run ruff check)
  • code passes formatting checks (uv run ruff format)
  • pre-commit hooks have been run successfully
Additional Notes
  • Conflicts with Issue #1513: feat: count crosswalks in measure_export_blockers.py #1519 in test/scripts/test_measure_export_blockers.py: Issue #1513: feat: count crosswalks in measure_export_blockers.py #1519 pins 7 crosswalks for the old seed, and this seed has 6. Whichever merges second updates the figure.
  • The diff is data and hard to review line by line, so here's what could go wrong with it, and what checks it:
    • A row changed that no step meant to change. The row reconciliation above.
    • A migration rewrites converted rows on a fresh local stack. The replay check.
    • A generated schema changed beyond Ids and the cleanup's intended edits. The snapshot diff.
    • The converted model 17 serves a different schema to GraphQL, the Translator and semantic search locally. The conversion's own self-check, and the snapshot diff.

🤖 Generated with Claude Code

…s cleaned

Runs cleanup_export_blockers.py, remove_test_data.py and convert_overlays.py
on backup.sql in public and tenant_lif_team, and removes model 16, as dev got
in #1388 and #1393. Dumped with pg_dump 18.6, as the seed last was.

Tests that need overlays load the unconverted seed, kept as
test/fixtures/backup-unconverted.sql (the same blob as the old backup.sql).
The rest pin the converted seed; the snapshots are regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg and others added 2 commits November 16, 2026 13:17
…kup.sql

backup.sql is no longer a snapshot of V1.1's content. Per the decision on
#1513 step 4, no migration converts a fresh environment; the deployment
guide now says so and names the scripts that give it the seed's content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f V1.1

Comment only. backup.sql still replaces V1.1 locally, but its content has
moved past V1.1's; point at the deployment guide's note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cbeach47 cbeach47 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude:

The approach looks right to me. Option (a) costs nothing, since the fixture is the same blob as main's backup.sql (2a3f79b). I also loaded the new dump and checked model 16's removal. In both schemas, no live entity association, attribute association, value set, inclusion or group rule still points at model 16.

There's one thing to sequence with #1468 that doesn't need a change here. overlay_converter.py:211 checks itself with generate_openapi_schema on the overlay, and the fixture's overlay tests call it too. #1468's last PR makes generation refuse NOT_MIGRATED, overlays included. That would stop convert_overlays.py, which demo (step 6) and this PR's fresh-environment note both depend on. So either that PR waits until demo is converted and #1514 replaces the scripts, or the converter calls the generator without the check. I'll note it on #1468.

Three inline comments below.

Comment thread docs/operations/guides/deployment.md Outdated
- **Deployed envs** run migrations via Flyway (tracked in `flyway_schema_history`).
- **Local docker-compose** loads `backup.sql` (a pg_dump snapshot of V1.1 content) and then runs every `V1.*.sql` file in the Flyway directory through `psql` — it does *not* use real Flyway and does *not* track history. See `projects/lif_mdr_database/restore.sh`.
- **Local docker-compose** loads `backup.sql` and then runs every `V1.*.sql` file in the Flyway directory through `psql` — it does *not* use real Flyway and does *not* track history. See `projects/lif_mdr_database/restore.sh`.
- **A fresh deployed environment doesn't get `backup.sql`.** Flyway builds it from V1.1, which was last copied from the seed in September 2026. V1.1 still has the overlays and the models that #1513 converted or replaced. Applied migrations aren't edited, V1.1 included, so the two stay out of sync until #1514 changes how content ships. To give a fresh environment the seed's content, run `scripts/remove_test_data.py`, `scripts/cleanup_export_blockers.py` and `scripts/convert_overlays.py` against it, as was done on dev. Models 3, 6, 14 and 17 also differ (#1521).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude:

The recipe is incomplete. No script removes model 16. Its SQL is only in the PR description, so following this note leaves model 16 live and export refuses it. Model 29 isn't listed either. Could the model-16 SQL go into scripts/ and be listed here? Also, these scripts have only run against backup.sql and dev, never against a database Flyway built from V1.1. The note should say that, unless someone has tried it.

# The seed as it was before #1513 converted it: models 17 and 18 are still overlays of model 1. Tests of
# overlay behavior (and of code that still has to handle overlays, on demo or a fresh install from V1.1)
# load this instead of backup.sql.
UNCONVERTED_SEED_PATH = Path(__file__).parent.parent.parent.parent.parent / "test/fixtures/backup-unconverted.sql"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude:

_load_seed loads a dump and doesn't replay any migrations. So a future V1.12 has to be applied to this fixture as well as to backup.sql. Otherwise the overlay tests run against an older schema than the code expects. Could this comment say so, or could the fixture loader replay V1.2+ the way restore.sh does?

assert await is_overlay_model(session, 17)
# What makes a model an overlay is its inclusion rows, not its Type. In the seed, #1513 converted model
# 17: it is still Type OrgLIF, with no inclusion rows, so it is not an overlay.
assert not await is_overlay_model(session, 17)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude:

The precondition is that 17 is still Type OrgLIF, but only the comment says so. Could it be asserted (SELECT "Type" FROM "DataModels" WHERE "Id" = 17)? #1521 re-imports 17 from dev, and if its Type changes there, this test would still pass without testing anything.

@cbeach47

Copy link
Copy Markdown
Contributor

From Claude:

@bjagg, this corrects the #1468 note in my review above. The plan is that once #1513 lands, overlays no longer exist anywhere. All overlay code then goes, including convert_overlays.py, the overlay converter and this PR's backup-unconverted.sql fixture. After that, #1468's last PR can make generation refuse overlays and NOT_MIGRATED, and nothing needs it to accept them. The converter's self-check (overlay_converter.py:211) is the only caller that does. So the right order is to delete the overlay code first, not to make the converter bypass the check.

Two gaps stand in the way of "no overlays anywhere":

  1. Demo. Your status comment on MDR portability: convert or remove every seed model that export refuses, and confirm dev and demo #1513 says step 6 isn't started, but we think demo may already be converted. Is it? If so, could MDR portability: convert or remove every seed model that export refuses, and confirm dev and demo #1513 record it, with step 8's measure_export_blockers.py counts for every demo schema?
  2. A fresh environment. Flyway builds it from V1.1, which still has 17 and 18 as overlays. This PR's deployment note fixes that with convert_overlays.py, so deleting the script leaves a fresh environment with no way to convert them. MDR portability: ship MDR content as a portable reference set, and leave backup.sql and the migrations schema-only #1514 is a long way off. Which route should a fresh environment take instead?

Whichever you pick, the deployment note in this PR changes to match.

…veat, model 17 precondition

- deployment.md: a fresh Flyway environment has no supported path to the
  seed's content until #1514; the scripts were never run against V1.1.
- conftest.py: backup-unconverted.sql replays no migrations, so a later
  migration has to be applied to it too.
- test_type_name_does_not_select_the_overlay_path asserts model 17 is
  Type OrgLIF instead of only saying so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 16, 2026
#1520's review added an assertion that model 17 is Type OrgLIF. Here 17 is
dev's copy, Type SourceSchema; assert that, and note the OrgLIF case is
tested through MODEL_ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bjagg

bjagg commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

From Claude:

Thanks, @cbeach47. I pushed 66d62be for the three inline points. Here's where each one landed, and answers to your two questions:

@cbeach47 cbeach47 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude:

@bjagg, thanks. 66d62be covers all three inline points, and CI is green.

One change of direction: demo won't be converted. It's being decommissioned shortly, so dev and demo don't need to stay in sync with this work. What that changes:

  1. Nothing is left blocking the overlay code's removal. Demo was the only environment still running overlays, and this PR's note says a fresh environment isn't supported until #1514. Once #1513 lands, overlays exist only in V1.1 and in backup-unconverted.sql. The removal can follow straight after, and the fixture and the script tests go with it.
  2. This PR still says the overlay code is kept for demo. Could the wording follow the new plan?
    • Handbook: backend chapter 3 (the "Overlays are on their way out" section, lines 66–92), chapter 7 line 15 and frontend chapter 2 line 128 still say demo is "not yet, #1513". Chapter 7 still gives demo's recipe (add to model 1, then include in 17). Saying demo won't be converted and is being decommissioned would let the overlay recipe go, or shrink to a pointer.
    • Comments: conftest.py:27 and the four test/scripts files say the scripts run on demo. Saying the fixture lasts until the overlay code is removed would be enough.
  3. #1513's scope: step 6 and the demo half of step 8 drop out, and "Done means" no longer needs "on dev or demo". #1521's choice of dev's content still holds on its own merits (#1511's file names Ed-Fi v5 1.0), so it doesn't need revisiting.

@cbeach47 cbeach47 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static spot checked.

Approving.

@bjagg
bjagg merged commit 9a0deb3 into main Nov 17, 2026
4 checks passed
@bjagg
bjagg deleted the issue-1513-convert-seed branch November 17, 2026 00:34
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Current Community Efforts Nov 17, 2026
bjagg added a commit that referenced this pull request Nov 17, 2026
#1520's head (66d62be) is already in this branch, and main's tree equals it,
so this records the squash without changing any file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 17, 2026
Per #1520's review: handbook chapter 3 now says overlays are gone (dev and
the seed converted, demo won't be), lists the seed's 18 live models, and
replaces the overlay walkthrough with a pointer. Chapter 7's add-a-field step
adds to model 17 directly (checked against the seed: 201, field in 17's
generated schema). The fixture comments say the unconverted seed lasts until
the overlay code is removed, not that the scripts run on demo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 18, 2026
…1520

#1520 removed the seed's test data, which took the 343 -> 347 crosswalk with it,
so the seed now has 6 crosswalks. The refusal and pair tests use 315 -> 290 instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 18, 2026
…-mapping rule

Review feedback on #1519:

- crosswalk_converter now holds the §2 live-mapping filter once, in
  _live_mappings, and lists every pair with list_crosswalk_pairs, reached
  through portability_converter. measure_export_blockers.py uses it instead
  of its own copy of the joins and Deleted checks (#1468).
- The script's docstring says it counts what the converters refuse: through
  GET /portable/crosswalks, a missing value set is a 404 before the converter
  runs. Its long line is rewrapped.
- Spec §7's seed figures are re-measured after #1520: in public, 1,654
  value mappings that aren't deleted, 940 to soft-deleted targets, and 714
  live across 6 pairs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 20, 2026
)

##### Description of Change

Step 2 of #1513: `scripts/measure_export_blockers.py` now counts
crosswalks alongside models and mapping groups, so "no refused model,
group or crosswalk" can be measured. The crosswalk converter wasn't on
`main` when the script was written (#1442), so it only counted models
and groups.

**What counts as a crosswalk.** A crosswalk has no row of its own
(Portability Spec §7): it's the live value mappings from one value set
to another. So the script measures every value-set pair that has at
least one live value mapping. The crosswalk converter lists the pairs,
as `list_crosswalk_pairs`, with the same live-mapping filter
`export_crosswalk` reads (§2): the mapping, both of its values, and its
group if it has one. The filter is written once, in
`crosswalk_converter._live_mappings`, and the script reaches the list
through `portability_converter`. The pair comes from the values, not
from the mapping's `SourceValueSetId`/`TargetValueSetId`, which are NULL
on most of the seed's rows. Value sets and models aren't filtered, so
the count is what `export_crosswalk` refuses: a pair whose value set or
model is gone is counted as refused. Through `GET /portable/crosswalks`,
a missing value set is a 404 before the converter runs.

Each pair runs through `export_crosswalk` the same way models and groups
run through their converters: in a savepoint, with refusals counted
under their reason and any other exception as `ERROR`. The summary line
per schema gains `crosswalks N export, M refused`.

**Today's figures.** Nothing is refused yet, so the reason lists don't
change:
- the seed (`backup.sql`): 6 crosswalks in `public` and 6 in
`tenant_lif_team`, all export;
- dev (2026-11-15, all 10 schemas, run read-only in the `mdr-api`
container): 6 per schema in `public` and 7 of the eval schemas, 10 in
eval-5, and 7 in `tenant_lif_team`. All export.

The model and group refusals on dev are the two #1513 already lists:
model 28 in `tenant_lif_team`, and one group in eval-5 (#1434).

##### Related Issues

Refs #1513

##### Type of Change

- [x] New feature (non-breaking change which adds functionality)

##### Project Area(s) Affected

- [x] components/
- [x] scripts/
- [x] test/ or e2e/
- [x] Documentation (docs/, READMEs, ARCHITECTURE.md, CLAUDE.md)

---

##### Checklist

- [x] commit message follows commit guidelines (see
commitlint.config.mjs)
- [x] tests are included (unit and/or integration tests)
- [x] code passes linting checks (`uv run ruff check`)
- [x] code passes formatting checks (`uv run ruff format`)
- [x] code passes type checking (`uv run ty check`)
- [x] pre-commit hooks have been run successfully

##### Testing

`uv run pytest test/scripts/test_measure_export_blockers.py` (needs a
local PostgreSQL; 7 passed locally on PG 16.15). New tests:

- **The seed test** pins `(6, 6, 0)` crosswalks for `public`.
- **`test_measure_counts_a_refused_crosswalk_under_its_reason`:** a
crosswalk refusal is counted under its reason and the crosswalk's label,
and shows in the summary line.
- **`test_crosswalk_pairs_skip_a_pair_with_no_live_mapping`:** in a
transaction that's rolled back, four of the seed's six pairs lose their
live mappings, each a different way (mapping deleted, source values
deleted, target values deleted, group deleted), and only the other two
are listed. Removing any one of the three value and group filters from
the query fails this test (checked by hand).
- **Spec §7:** the seed figures are re-measured after #1520. In
`public`, 1,654 value mappings aren't deleted, 940 of them point at
soft-deleted target values, and the 714 live ones cover 6 pairs.
`tenant_lif_team` has the same 714 and 6.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 20, 2026
…move 29 (#1521)

##### Description of Change

#1520 is merged, and this branch has `main` merged in, including #1523.

Step 1 of #1513, applied to the seed, as
[decided](#1513 (comment)):
models 3 (CLR v2), 6 (Ed-Fi v5), 14 (CASE) and 17 (StateU LIF) take
dev's content, and model 29 (Open Badges v3) is removed. Dev has no
separate Open Badges v3; its model 3 covers both. Dev's `public` and
`tenant_lif_team` hold the same 3, 6 and 14, byte for byte. For 17, the
seed takes `tenant_lif_team`'s version, which the reference mappings
were written against. In both of the seed's schemas:

1. **Groups:** the live groups touching those models (23–26, all `→ 17`)
are exported and soft-deleted with their rules.
2. **Each model:** the old model is soft-deleted with everything in it.
Dev's export of it (`GET /portable/models/{id}` from dev's
`tenant_lif_team`, 2026-11-15) is imported, and the two Ids are swapped,
so the new content keeps the model's Id (17 is pinned in every compose
file's `OPENAPI_DATA_MODEL_ID`) and the old soft-deleted rows move to
the new Id. `DataModels.Id` is `GENERATED ALWAYS`, so the swap relaxes
it to `BY DEFAULT` and restores it in the same transaction.
3. **Model 29:** soft-deleted with everything in it (`public` only; the
seed's `tenant_lif_team` has none).
4. **Groups again:** groups 23–26 are re-imported against the new model
17, all rules resolving (0, 0, 4 and 1), each with its old group's
`ActivationDate`, so the local stack translates as before.
5. **V1.11:** dev's model 17 has 35 Reference associations per schema
with `Array` true, the V1.7 copies V1.11 (#1471) resets. `restore.sh`
replays V1.11 on every local load anyway, so it's applied before the
dump, and `backup.sql` holds what a local stack loads.

No live crosswalk goes through any of these models. 91 value mappings
start at model 3's and 14's values, but each ends at a value of a model
1 value set deleted long ago.

**Result** (`scripts/measure_export_blockers.py`): every model and group
in the seed exports, 18 of 18 and 6 of 6 in each schema.

##### Behaviour change

**Model 17's `Type` is now `SourceSchema`, not `OrgLIF`.** The portable
format doesn't carry `Type`, so `import_model` writes `SourceSchema`,
which fits ADR data_model/0004. In the local MDR UI, StateU LIF moves
from the Org LIF group to the source schemas, and Data Extensions (`GET
/datamodels/orglif`) shows nothing. Model 18, converted in place, stays
`PartnerLIF`.

##### How it was checked

- **Dev parity.** In both schemas, `export_model` on 3, 6, 14 and 17
gives dev's file byte for byte.
- **Generated schemas against dev's.** All 16 outputs per model were
compared with `GET /datamodels/open_api_schema/{id}` from dev's
`tenant_lif_team`, row Ids aside:
- The **default schema** (what GraphQL, the Translator and semantic
search load) is the same for all four. For 17, the only difference is
enum value order (Id order, and the Ids are new).
- The other flags differ only where the portable format normalizes
legacy element columns (Portability Spec §5.4 and its migration table):
- with attribute metadata, attributes' free-text `Array`/`Required` on
3, 6 and 14;
- under `public_only`, three child entities of model 17
(`OperationalStatus`, `OrganizationCode`, `Ranges`, whose parents are
Private) come out single, because a child entity's legacy `Array` isn't
carried;
- under `full_export`, `CreationDate`, which the format doesn't carry.
- Any import of these files gives the same result, so these aren't
regeneration errors.
- **The reference transformations now fit the seed.** Checked on a
throwaway copy:
- `Ed-Fi-v5_StateU-LIF__v1.0.json` (#1517) imports, all 83 rules, into
both seed schemas. Before, `public` refused it with `MODEL_MISSING`.
- The two old-format outbound files: StateU LIF → Ed-Fi v5 resolves 70
of 70 (44 failed before), and StateU LIF → CLR v2 / OB3 resolves 30 of
32. The other two have no source and target attributes in the file
itself.
- So the outbound files can now be converted to the portable format from
the seed; that's left for a follow-up.
- **No dump noise, no schema change.** Same pg_dump 18.6 container as
#1520. The DDL, everything but data and `setval` lines, is identical to
#1520's, including the 33 `GENERATED ALWAYS` identity columns.
- **Every foreign key** in both schemas was checked for orphans after
the swap (29 FKs, none).
- **The migrations replay cleanly.** Loading the new dump and replaying
V1.2–V1.11 as `restore.sh` does changes no row.
- **Rows added** are the same in both schemas, dev's four models: 116
entities, 826 attributes, 48 value sets, 1,414 values, 138 entity
associations, 1,111 attribute associations, plus the re-imported groups
(4) and rules (5).

The procedure ran once, on a fresh load of #1520's seed, so the dump's
Ids and sequence values don't depend on any dry runs.

##### Tests

- **Schema snapshots,** regenerated. Only models 3, 6, 14, 17 (new
content) and 29 (removed) changed; every other model's 16 outputs are
unchanged from #1520.
- **`test_measure_export_blockers`:** 18 of 18 models and 6 of 6 groups
in each schema, nothing refused.
- **`test_portable_seed_round_trip`:** all 18 models, and every group
and crosswalk on them, round-trip byte for byte.
- **`test_portable_endpoints`:** no seed model is refused any more, so
the not-migrated test sets one of model 3's attributes to `DataType`
entity inside the request's session, then rolls it back.
- **`test_association_name_seed`:** model 17 joins 4 and 10 as a model
whose association `Name` and `Array` aren't derived by the V1.7 rule.
They were set on dev: role names such as `awardedByRefOrganization`
(#1434), and `Array` edited since #1472. For those models, the test
checks only that both are set.
- **`test_clone_datamodel_sql`:** runs on the converted seed's 3 (CLR v2
/ Open Badges v3) and 14 (CASE). A clone gets no
`ContributorOrganization`, so the test sets the source's; that gap is on
#1468.
- **`test_schema_generation_cycle`:** needs model 29, so it runs on the
unconverted seed (`unconverted_db_session`, from #1520), and goes with
#1463's guard when #1468 removes the `NOT_MIGRATED` pass.

`test/scripts`, `test/bases/lif/mdr_restapi` and
`test/components/lif/mdr_services`: 728 passed, 1 skipped (PG 16.15
locally). One fewer than #1520 because model 29 left the snapshot set.
After merging `main` (with #1523), the full suite: 1927 passed, 1
skipped.

**Docs:** `reference_data/transformations/README.md` now says where the
files import against this seed.

##### Related Issues

Refs #1513 (the seed is done; demo, step 6, and the migration question,
step 4, stay open there), #1511, #1514

##### Type of Change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] Documentation update

##### Project Area(s) Affected

- [x] projects/
- [x] reference_data/
- [x] test/ or e2e/

---

##### Checklist

- [x] commit message follows commit guidelines (see
commitlint.config.mjs)
- [x] tests are included (unit and/or integration tests)
- [x] code passes linting checks (`uv run ruff check`)
- [x] code passes formatting checks (`uv run ruff format`)
- [x] pre-commit hooks have been run successfully

##### Additional Notes

- **For the reviewer:** model 17's association `Array` values. Dev
stores `Array` true on 123 attribute associations and 101 entity
associations whose child's own `Array` is `No`. The generator reads the
association, so dev and now the local stack serve those as lists. That's
dev's content as decided, but it may not be what was meant; the counts
are from the seed's `public`.
- **Conflicts:** with #1518 in
`reference_data/transformations/README.md` (both edit "Where the
portable file imports"), and with #1519 in
`test/scripts/test_measure_export_blockers.py`. Whichever merges second
resolves.
- **What's left in #1513:** apply this on demo (step 6), and Chris's
answer on the migration (step 4).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
bjagg added a commit that referenced this pull request Nov 20, 2026
…ortable format (#1522)

##### Description of Change

**Stacked on #1521** (itself on #1520), so the diff shows only this
step. Merge those first; this PR's base then becomes `main`.

The two outbound reference groups, StateU LIF → CLR v2 / Open Badges v3
and StateU LIF → Ed-Fi v5, were the last old-format files in
`reference_data/transformations/` (#1511). Their groups on dev have
never had mappings, so there was nothing to export them from. Since
#1521, the seed's models 3, 6 and 17 are dev's `tenant_lif_team`
versions, which these files were written against, so they now convert
through the seed:

1. Each old file was imported into the seed
(`import_transformation_group`, as `POST
/transformation_groups/{id}/import` does) as a new 17 → 3 or 17 → 6
group, version `1.0`.
2. That group was exported with `export_mapping_group` (`GET
/portable/mapping_groups/{id}`) and replaces the old file under the same
name.

Both of the seed's schemas give the same two files, byte for byte.

All three files in the directory are now portable, so
`scripts/import-transformations.sh` loads all three instead of skipping
two.

**What changed in the content:**

- **Rules:** every converted rule has the old rule's name, expression,
expression language, target and sources, compared rule by rule (old
paths' dotted `UniqueName`s and numeric prefixes reduced to the portable
path's segments). That's 70 of 70 for Ed-Fi v5 and 30 of 32 for CLR v2 /
Open Badges v3.
- **Two rules dropped:** `AchievementSubject.activityStartDate` and
`AchievementSubject.result` have no source or target attributes in the
old file, and both read `Name.firstName`. The portable format needs a
target, and they look like placeholders.
- **Group names** follow the `<source>_<target>` pattern every other
group uses: `StateU LIF_CLR v2 / Open Badges v3` and `StateU LIF_Ed-Fi
v5`. The old files had `StateU-LIF_CLR-v2-Open-Badges-v3__v1.0` and
`StateU LIF_Ed-Fi_v5_v1.0`.
- **Not carried over:** the old files' `ActivationDate` (2026-06-18). An
imported group arrives inactive (#1350), like the inbound file's. No
rule had `Notes`, `Alignment` or a contributor to lose.

##### Where they import

Checked on throwaway copies of #1521's seed:

- **The seed, both schemas:** each file imports with every rule,
re-exports byte for byte, and a second import is refused with
`GROUP_EXISTS`.
- **Dev's `public`:** none of the three files imports, and that includes
the inbound file already on `main`. With dev's `public` export of model
17 in place of the seed's, they're refused with 53, 8 and 47
`PATH_INVALID` errors. That StateU LIF has fewer entities than
`tenant_lif_team`'s, as the README already says for the inbound file.
- **Dev's `tenant_lif_team`:** its models 3, 6 and 17 are the ones the
seed now holds, so the paths resolve there. Not imported, since that
would be a dev write. One thing to check before running the script
there: `GROUP_EXISTS` keys on the two models plus `Version`. If dev
already has an empty 17 → 3 or 17 → 6 group at `1.0`, the script reports
the file as already installed while that group still has no mappings.

##### Tests

- New `test/bases/lif/mdr_restapi/test_reference_transformations.py`
runs every portable file in the directory (not recursively, like the
script) in both seed schemas. It checks four things: the rule count, the
import, the byte-for-byte re-export, and `GROUP_EXISTS` on the second
import. 7 passed.
- **Mutations:** the old-format Ed-Fi file put back fails 2 tests, and
so does a mapping removed from it.

##### Related Issues

Refs #1511, #1513

##### Type of Change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] Documentation update

##### Project Area(s) Affected

- [x] reference_data/
- [x] test/ or e2e/

---

##### Checklist

- [x] commit message follows commit guidelines (see
commitlint.config.mjs)
- [x] tests are included (unit and/or integration tests)
- [x] code passes linting checks (`uv run ruff check`)
- [x] code passes formatting checks (`uv run ruff format`)
- [x] pre-commit hooks have been run successfully

##### Additional Notes

- **Conflicts:** with #1518 in
`reference_data/transformations/README.md`, like #1521. Whichever merges
second resolves.
- **The diff is mostly the two JSON files:** the old format carried
database Ids and nulls on every rule; the portable one names paths only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants