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
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@ here.**

## [Unreleased]

- **`meta verify --uuid-values` lists the stored uuids that 1.3.0's write check refuses.** It is
a read-only check to run before upgrading. With `--db <url>` (SQLite, libSQL or Postgres), or with
`--dialect d1 [--d1 <binding>] [--remote]`, it reads every place the model types `field.uuid`, in
every table the model stores rows in, `@unmanaged` tables and tables outside `migrate.scope`
included: keys, foreign keys, each element of an `isArray` list (a JSON `null` element counts as
not canonical), and inside a value object stored as JSON each `field.uuid` member, through nested
value objects, lists of value objects and the values of a `field.map` of value objects. A
flattened value object's members are read in their own columns, and a member that is itself an
object or a map is read inside its JSON column. Which column holds which field comes from the same
code `meta migrate` lays out its columns with, so a TPH subtype's flattened value object is read in
the one JSON column migrate gives it. TPH sibling subtypes that declare different fields on one
column are each read, in the rows whose discriminator names a subtype declaring that field, so a
`field.string` sibling's values are not reported; a subtype that redeclares a base field is read
the same way, its field in its own rows and the base's field in every other row. Each place is named by its column and JSON path
(`claims.meta $.memberId`); for each one holding values that are not canonical 8-4-4-4-12 uuids,
such as `"mbr1"` on SQLite or D1, it gives the count and up to five samples, and it exits 1 when it
finds any. A native Postgres `uuid` or `uuid[]` column is reported as native: the database
already stores only canonical uuids, so there is nothing to scan.
Every place ends as scanned, native, missing (the table or column is not in this database) or
unreadable (the read failed, the column type cannot hold the value, the stored text is not JSON,
or a value object that holds a `field.uuid` contains itself), and the check passes only when
every place was read: any missing or unreadable place makes the run incomplete, names the place
and its reason, and exits 1.
It does not read a `field.map @valueType: uuid` or an object with no `@objectRef` (the write check
does not check either as a uuid), or views. The SQLite and D1 queries stay inside D1's limits
(a GLOB pattern of 50 bytes, one JSON path per run of member keys). The check never writes. A
`--db` file inside wrangler's local D1 state gets the same warning as the schema gate. With
`--uuid-values`, `--db` is used for this check only, not for the schema gate, and `--format json`
carries one row per place in `uuidValues[]`. It is in the Node CLI only, like the other checks that
read a live database. See `docs/features/migrations-and-drift.md`, "`meta verify --uuid-values`".
- **C# and Rust render dotted names, a list's `length` and `0` as TypeScript does.** C# resolves a
dotted name whole against each context, innermost outward, so a context holding only the first
segment no longer hides an outer match (`render-shadowed-dotted-prefix`). The Rust
Expand Down Expand Up @@ -371,7 +401,9 @@ there is described in full here. This list is where to start.
201 or 200. Check seed scripts, fixtures, imported rows and hand-inserted ids before you
upgrade: a row already stored with such an id still reads, and `GET /<plural>/<id>` on SQLite
still answers it, but no client can write that value again. Rewrite the ids to canonical
uuids, or declare the field `field.string` if it was never a uuid.
uuids, or declare the field `field.string` if it was never a uuid. Since 1.3.1,
`meta verify --uuid-values --db <url>` (or `--dialect d1`) lists those stored values for you,
with a count and samples per column, without writing anything.
- **By hand for owned generators, every port: the code writer refuses text that starts with
whitespace.** `line`, `open` and `close` (and TypeScript's and Kotlin's `reopen`) throw
`ERR_WRITER_LEADING_WHITESPACE` when handed indented text, because the writer indents from the
Expand Down
1 change: 1 addition & 0 deletions docs/features/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ vocabulary everywhere, each port implementing the modes it supports.
| Subverb | What it checks | Touches a DB? |
|---|---|---|
| `verify --db` | **Schema drift** — does the live database (or snapshot) match the metadata? (migrate engine, ADR-0015) | yes |
| `verify --uuid-values` | **Stored uuid values** (since 1.3.1). This is a read-only check to run before upgrading. With `--db <url>` or `--dialect d1`, it reads every place the model types `field.uuid` (columns, list elements, value-object members stored as JSON, map values and flattened members) in every table the model stores rows in, `@unmanaged` and out-of-scope tables included, and lists the values that are not canonical 8-4-4-4-12 uuids, which the 1.3 write check refuses. It exits 1 when it finds any, and also when any place could not be read (a missing table or column, a failed read): it passes only when every place was read. With this flag, `--db` is used for this check only. **Node `meta` only.** See [`migrations-and-drift.md`](migrations-and-drift.md#meta-verify---uuid-values--stored-values-the-uuid-write-check-refuses). | yes (read-only) |
| `verify --codegen` | **Codegen drift** — regenerate from metadata in memory and fail if it differs from the committed generated output. Catches "metadata changed but `meta gen` wasn't re-run". **A hand-edited generated file** (Node `meta`): `meta gen` three-way-merges hand edits, so the gate compares the *generated contribution* against the committed `.gen-state/.hashes/` and reports each edited file separately, by path, with how to see the edit and how to drop it. What that report does to the exit code is the `verify.handEdits` key in `.metaobjects/config.json`: `"fail"` exits 1, `"notice"` (and a project without the key, as before 1.3) prints it and exits 0. `meta init` writes `"fail"` for a new project. `--allow-hand-edits` relaxes `fail` to a notice for one run; `--forbid-hand-edits` makes a hand edit fail for one run whatever the key says. The other ports compare the generated files byte for byte, so any edit is drift and fails: `dotnet meta verify --codegen`, `mvn metaobjects:verify` (Java and Kotlin) and `metaobjects verify --codegen` each exit non-zero and name the file. | no |
| `verify --templates` | **Template/prompt drift** — `Renderer.verify` checks each `template.*` node's `{{field}}` references against its payload VO (FR-004). A Jinja body (Python and TypeScript, ADR-0061) is checked the same way. | no |
| `verify --docs` | **Removed in 1.1.0** (ADR-0034 Amendment 9). It prints where the check went and exits 2: documentation is written by entries in `generators`, so `verify --codegen` checks it with the rest of the declared output. | — |
Expand Down
64 changes: 64 additions & 0 deletions docs/features/migrations-and-drift.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,70 @@ ports reject `--db` (C#, Python, Rust and the Maven goal exit 2 or fail with a p
TypeScript CLI); the live-DB-schema `metaobjects:verify` goal was removed along with the
runtime auto-create validator.

### `meta verify --uuid-values` — stored values the uuid write check refuses

```bash
meta verify --uuid-values --db <url> # SQLite, libSQL or Postgres
meta verify --uuid-values --dialect d1 [--d1 DB] [--remote]
```

Since 1.3.0 the generated create and update models refuse a `field.uuid` value that is not the
8-4-4-4-12 hex shape, on every dialect. SQLite and D1 store a uuid as text and accepted any
string, so a database may already hold ids such as `"mbr1"`: those rows still read, but no
client can write the value again. Run this check before upgrading. It never writes.

It reads every place the model types `field.uuid`, in every table the model stores rows in.
That includes `@unmanaged` tables, tables outside `migrate.scope` and tables from an imported
package, because the write check applies to them and reading changes nothing. Which column holds
which field comes from the same code `meta migrate` lays out its columns with. Inside a column the
check follows the nesting the write check validates:

- a `field.uuid` column (keys, foreign keys and every other uuid field);
- each element of an `isArray` list of uuids. A JSON `null` element counts as not canonical, and so
does a stored value that is not a list, because the write check refuses both;
- each `field.uuid` member of a value object stored as JSON (any `field.object` that is not
`@storage: flattened`), through nested value objects and lists of value objects;
- each value of a `field.map` of value objects;
- a flattened value object's members: a uuid member is its own column, and a member that is itself
an object or a map is read inside its JSON column. A flattened value object declared on a TPH
subtype is one JSON column, as migrate stores it;
- a column that TPH sibling subtypes each declare with a different field: every field is followed,
and where only some siblings put a uuid at a place, only the rows whose discriminator names one of
those subtypes are read, so a sibling's `field.string` values are not reported. A subtype that
redeclares a field its base stores is handled the same way: the subtype's field is read in that
subtype's rows and the base's field in every other row, in either direction (a uuid replacing a
string, or a string replacing a uuid).

Each place is reported with its column and JSON path, for example `claims.meta $.memberId`,
`claims.history $[*].tagIds[*]` or `claims.by_region $.*.regionId`, with the count of values that
are not canonical and up to five of them. An absent or `null` member is not counted. A container of
the wrong type on the way down (a string where an object should be) holds no uuid and is not
counted. Not read: a `field.string`, even one declared `@dbColumnType: uuid`, a
`field.map @valueType: uuid` and a `field.object` with no `@objectRef` (the write check does not
check any of them as a uuid), and views (their rows live in a table already read).

Every place ends in one status:

| Status | Meaning | Counts as read |
|---|---|---|
| scanned | every stored value was read | yes |
| native | a Postgres `uuid` or `uuid[]` column: the database stores nothing else | yes |
| missing | the table or the column is not in this database | no |
| unreadable | the read failed, the column type cannot hold what the model says (a value object in a Postgres column that is not `json`/`jsonb`), the stored SQLite text is not JSON, or a value object that holds a `field.uuid` contains itself (one with no `field.uuid` inside is no place at all) | no |

The check exits 1 when it finds a value that is not canonical. It passes only when every place was
read: a missing or unreadable place makes the run incomplete, exits 1 and is listed with its reason
(under `--format json`, in `errors[]`). A model whose tables live in more than one database is
therefore incomplete against each one, and says which tables it did not find. A `--db` file inside
wrangler's local D1 state (`.wrangler/state/**/d1/**`) is the local database, so the check warns and
points to `--uuid-values --dialect d1 --remote` for the deployed one.

Fix what it lists in one of two ways. Either rewrite each value to a canonical uuid, along with
every foreign key that points at it, or declare the field `field.string` if it never held uuids.
With `--uuid-values`, the `--db` connection is used for this check only. Run `meta verify --db <url>`
separately for schema drift. Under `--format json` the findings are in `uuidValues[]`, one row per
place, with its status and the reason for each place not read. Only the Node CLI has this check, as it has the other checks that read a live database.

## Generated-vs-runtime: Kotlin startup validator

`KotlinSpringConfigGenerator` emits a `@Configuration` class that re-loads
Expand Down
Loading
Loading