Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions docs/developer-handbook/backend/03-data-model-and-mdr.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,41 @@ wrong-case path silently matches nothing. The full rule: [`docs/specs/data-model

## The models in the seed

The local MDR is seeded from `projects/lif_mdr_database/backup.sql`. It holds 21 live models:
The local MDR is seeded from `projects/lif_mdr_database/backup.sql`. It holds 18 live models, the same in `public` and `tenant_lif_team`:

| Id | Name | Type | What it's for |
|---|---|---|---|
| 1 | LIF | `BaseLIF` | The base LIF model |
| 17 | StateU LIF | `OrgLIF` (built on 1) | **What the services load locally**: the demo organization's LIF |
| 18 | Org2 LIF | `PartnerLIF` (built on 1) | Another organization's LIF |
| 2–16, 29 | HR Open, CLR v2, CEDS v14, Ed-Fi v5, CTDL, Open Badges v2/v3, … | `SourceSchema` | Other standards, kept so they can be mapped to LIF |
| 17 | StateU LIF | `SourceSchema` | **What the services load locally**: the demo organization's LIF |
| 18 | Org2 LIF | `PartnerLIF` | Another organization's LIF |
| 2–15 | HR Open, CLR v2, CEDS v14, Ed-Fi v5, CTDL, Open Badges v2/v3, … | `SourceSchema` | Other standards, kept so they can be mapped to LIF |
| 26 | R1 Demo Source Data Model | `SourceSchema` | The example source system's shape ([chapter 4](04-follow-the-data.md)'s translation) |
| 25 | Test2UpdatedSourceModel | `SourceSchema` | Test data |

The GraphQL API, semantic search and the Learner Data Export API pick their model by **name, version and
contributor organization**, not by Id. The Translator works by Id: its caller passes the source and target
Ids in the URL (the planner's sources config sends 26 → 17). In the compose file: `OPENAPI_DATA_MODEL_NAME=StateU LIF`, `OPENAPI_DATA_MODEL_VERSION=1.0`,
`OPENAPI_DATA_MODEL_CONTRIBUTOR_ORGANIZATION=StateU`.

### Overlays are on their way out (dev and the local seed: converted; demo: not yet, #1513)
### Overlays are gone

Models 17 and 18 are **overlays** on demo, and were on dev until #1388 and in the local seed until #1513: they build
on model 1 and add or include parts of it, rather than holding everything themselves. ADR data_model/0004
Models 17 and 18 were **overlays** until #1388 converted them, and in the local seed until #1513: they built
on model 1 and added or included parts of it, rather than holding everything themselves. ADR data_model/0004
([`docs/design/adr/data_model/0004-retire-overlays-variants-as-copies.md`](../../design/adr/data_model/0004-retire-overlays-variants-as-copies.md), Accepted) retires this:

- every model will be **self-contained**, with one kind of model instead of four types;
- a variant of a model is a **copy**, and **schema diff** shows how two models differ;
- 17 and 18 are converted once, in place, so they produce the same schema as before (#1388, done:
`scripts/convert_overlays.py`, #1489). The conversion is applied on dev, in all 10 schemas, and in the local
seed (`projects/lif_mdr_database/backup.sql`, #1513). Demo isn't converted yet (#1513).
`scripts/convert_overlays.py`, #1489). The local seed (`projects/lif_mdr_database/backup.sql`) is converted
(#1513). An MDR that still holds overlays, such as one deployed before #1388 or a fresh environment built by
Flyway from V1.1, keeps them until `scripts/convert_overlays.py` runs on it
([`deployment.md`](../../operations/guides/deployment.md)).

Older docs and ADRs (metadata_repository/0004, 0008; data_model/0002) describe the overlay model:
inclusions, extensions, Org LIF vs Partner LIF. Read them as history.

**What that means on an overlay (demo, until #1513).** Model 17 shows only what it *includes* from
model 1, plus its own *extensions*:

- Entities like `Person` and `Name` are defined in model 1 (`Entities.DataModelId = 1`). Model 17 includes
37 of model 1's entities and 169 of its attributes (`ExtInclusionsFromBaseDM`), not all of them: model 1's
`Name` has 18 attributes, and model 17's generated `Name` has 6.
- Some entities exist only in 17, as extensions: `EmploymentPreferences` is one.
- So a field added to model 1 doesn't appear in the services until model 17 also includes it. A field
added to model 17 as an extension appears directly.

**The rule: on dev and the local seed, model 17 holds everything itself and is edited directly. On
demo, add new fields to model 1, then include them in model 17** ([chapter 7](07-recipes.md) has the steps).
**The rule: model 17 holds everything itself and is edited directly.** The overlay code
(`scripts/convert_overlays.py`, the overlay converter and the inclusion screens) is still in the repo,
and is removed after #1513.

### Two schema files you'll find in the repo

Expand Down
30 changes: 17 additions & 13 deletions docs/developer-handbook/backend/07-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ stack; the others are assembled from the code, recent PRs and the existing guide

The field lives in the MDR, so this is mostly data, not code ([chapter 3](03-data-model-and-mdr.md)).

1. **Add it in the MDR.** On dev and the local seed, model 17 holds everything itself (#1388, #1513), so
you add the attribute to model 17 directly, with `DataModelId: 17` and an entity in model 17. On demo,
model 17 is still an overlay until #1513, and the rule is: **add the attribute to base model 1, then
include it in model 17.** The steps below are for that overlay case. In the MDR UI, or through the API (endpoints at `http://localhost:8012/docs`; log in with
1. **Add it in the MDR.** Model 17 holds everything itself (#1388, #1513), so you add the attribute to
model 17 directly. In the MDR UI, or through the API (endpoints at `http://localhost:8012/docs`; log in with
`POST /login` and send `Authorization: Bearer <access_token>`):
- `POST /attributes/` with `Name` (camelCase), `UniqueName` (`Person.Name.preferredPronouns`),
`DataType` (`string`), `DataModelId: 1`, and `EntityId` (the entity in model 1; passing it creates the
attribute and its link to the entity in one step);
- `POST /inclusions/` with `ExtDataModelId: 17`, `ElementType: "Attribute"`, `IncludedElementId` (the new
attribute's `Id`), `LevelOfAccess` (most of 17's inclusions are `Public`), `CreationDate`, and
`Queryable` / `Modifiable` as needed (these become `x-queryable` / `x-mutable`).

Verified 11-07 on the local stack with a test field `preferredPronouns` on `Name`: both calls returned
201; model 17's generated schema showed the field at once; GraphQL showed it only after a restart (next
step); a query returned it (`null`, since no data has it yet). A reseed ([chapter 1](01-dev-environment.md)) removed it again.
`DataType` (`string`), `DataModelId: 17`, `EntityId` (the entity in model 17; passing it creates the
attribute and its link to the entity in one step).

The new attribute gets the default element flags: `LevelOfAccess` `Public`, `Queryable` and `Modifiable`
`false`, so it has no `x-queryable` or `x-mutable`. Neither `POST /attributes/` nor `PUT /attributes/{id}`
can set them yet: `CreateAttributeDTO` and `UpdateAttributeDTO` (`components/lif/mdr_dto/attribute_dto.py`)
have no such fields, and Pydantic drops unknown fields without an error, so sending them changes nothing.
The portable format does carry them on elements (Portability Spec §5.3). Until the DTOs take them, a field
that has to be restricted, queryable or mutable needs those columns set in the database.

Checked 11-16 against the local seed with a test field `preferredPronouns` on `Name`: the call returned
201 and model 17's generated schema showed the field at once.

The overlay route this step used to describe (add to model 1, then include it in 17, where the inclusion
row carried the flags) applied only while 17 was an overlay.
2. **Restart the services that load the schema** (`docker restart lif-graphql-api-org1 …`, semantic
search): they read it once at startup. The Translator picks it up within 5 minutes (its schema cache), or
restart it to see it at once.
Expand Down
9 changes: 6 additions & 3 deletions docs/developer-handbook/frontend/02-mdr-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ workspace again brings them back in line. The proper fix, a `GET /tenants/curren
activated (backend [chapter 10](../backend/10-extending-lif.md)).
- **Overlay screens**: Data Extensions, and a model's "only / all / public / extensions / partner" views.
An overlay is a model built on top of another one, and these screens show which parts are its own. ADR
data_model/0004 retires overlays in favour of self-contained models: on dev and in the local seed, models 17
and 18 have been converted (#1388, #1513), and on demo they're still overlays of model 1 until #1513 (backend
[chapter 3](../backend/03-data-model-and-mdr.md), "Overlays are on their way out"). Expect these screens
data_model/0004 retires overlays in favour of self-contained models: in the local seed, models 17 and 18
have been converted (#1388, #1513; backend [chapter 3](../backend/03-data-model-and-mdr.md), "Overlays are
gone"). In the seed, StateU LIF (17) is now Type `SourceSchema`, since the portable format has no `Type`
and an imported model is a source schema (#1513). So the tree lists it with the source schemas, not under
Org LIF, and Data Extensions (`GET /datamodels/orglif`) shows nothing. Org2 LIF (18), converted in place,
is still `PartnerLIF`. Expect these screens
to change.

## Where to go next
Expand Down
Loading
Loading