Repository navigation
feat(cli): add meta verify --uuid-values pre-upgrade scan - #693
Merged
Merged
Conversation
… check refuses A read-only pre-upgrade check. With --db <url> or --dialect d1, it reads every field.uuid column (keys, foreign keys, each isArray element) in the governed tables and lists those holding values that are not canonical 8-4-4-4-12 uuids, with a count and samples, exiting 1 when any are found. A native Postgres uuid column is reported as guaranteed and not read. Columns come from the same schema builder meta migrate uses. Node CLI only, like the other live-database checks.
…its own rows; scheme-less --db is a run error A subtype that redeclares a field its base stores put its own node in the base's column, and the scan only walked the base's node: a uuid redeclaration was never read (a false all-clear), and a string redeclaration of a base uuid got that subtype's strings reported. storedTablesOf now records the redeclaration (the base's entry builds the column, so migrate's DDL is unchanged), and the scan reads each node in the rows that hold it. A --db with no URL scheme now fails the uuid-values gate with exit 1 and an errors[] entry instead of an uncaught throw.
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 Changed
meta verify --uuid-values(newcli/src/lib/uuid-values-check.ts, wired incommands/verify.ts,index.ts,lib/args.ts). It is read-only and runs against SQLite, libSQL, Postgres, or D1 (--dialect d1). It walks everyfield.uuidplace in every stored table, including JSON-stored value objects, lists, and maps. Each place gets a status (scanned,native,missing,unreadable). For each place it reports the count of non-canonical 8-4-4-4-12 values and up to five samples, and it exits 1 when it finds any or when a place could not be read.migrate-tsstoredTablesOf(expected-schema.ts, exported fromindex.ts), so the scan andmeta migrateagree on which column holds which field.introspect/d1.tsandmetadata/src/loader/validation-passes.tschange to support that enumeration.docs/features/migrations-and-drift.mdanddocs/features/cli.md, and adds a CHANGELOG entry plus a pointer from the 1.3.0 uuid write-check note. Adds unit and integration tests (verify-uuid-values.test.ts,uuid-values-scan.test.ts) and CLI snapshot and args updates.Gate: this took two no-mistakes runs. The first ran three review fix rounds and hit the review round cap. The second fixed the two findings that cap had left as notes: a TPH subtype that redeclares a base field, and a
--dbwith no URL scheme.Validation
Risk Assessment
✅ Low: The increment closes the two prior findings: base-versus-subtype TPH redeclaration and the uncaught scheme-less --db error. Traced row-set algebra, SQL filters and migrate DDL invariance all hold, and the new test pins migrate's column list.
Testing
Built a disposable SQLite project under scratch, ran the real CLI against it. Non-canonical 'mbr1' row: exit 1, finding names members.id with sample 'mbr1' and the 1.3 write-refusal explanation. Clean DB: exit 0 with 'every stored value is canonical'. Mistyped --db path: exit 1 with 'incomplete ... cannot say every stored value is canonical' instead of a green verdict, which fixes the nothing-scanned false green. Side effect: the mistyped path still created an empty stray DB file, an inherent property of the SQLite open. D1-specific behavior (short GLOB pattern, --dialect d1 on a long constraint name) was not driven live. Broad regression is the baseline ci-local run, which passed.
Evidence: uuid-values non-canonical SQLite run transcript
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - resolved: every finding below is fixed on this branch
♻️ Reviewed only the branch's changes since run 01M8WPGR9TJZ54DQHGP5B106RE approved; the rest of the branch carries that approval.
Findings carried from run 01M8WPGR9TJZ54DQHGP5B106RE. Each is fixed on this branch: the sibling-subtype case in 5e5c0d8, and the base-field redeclaration and the scheme-less
--dbin cd80b61. Each fix has a test that fails without it. The last item is a comment-only fix the review applied inline.server/typescript/packages/migrate-ts/src/expected-schema.ts:423- False all-clear when sibling TPH subtypes share a column but declare different field nodes.storedFieldsOfkeeps only the first field per column (if (existing.has(column)) continue), anduuidPlacesOfwalks only that field. Example: baseParty; subtypeAutohasfield.object detail @objectRef AutoDetail(strings only); subtypeHomehasfield.object detail @objectRef HomeDetail(ownerIdisfield.uuid). OnlyAuto.detailsurvives, soparties.detail $.ownerIdis never a place. A stored{"ownerId":"mbr1"}on a Home row then yields "every stored field.uuid value is canonical", although Home's write schema refuses it. The same happens withAuto.externalIdasfield.stringandHome.externalIdasfield.uuid. migrate already supports sibling nodes that differ on one column (see the CHECK grouping near line 1128). Round 2 introduced this: the gate head 14b5857 walked each subtype object's own effective fields, so it read both. Sites: expected-schema.ts:423 (dedupe drops the sibling node); uuid-values-check.ts:123 (consumes one field per column); the "every place the model types field.uuid" claims in CHANGELOG.md and docs/features/migrations-and-drift.md. Fix: keep migrate's column list unchanged, but haveStoredFieldalso expose the other distinct sibling field nodes with their subtypes. Walk all of them and merge identical places. Where sibling types differ (string and uuid on one column), restrict the uuid read to rows carrying the declaring subtypes' discriminator values, so the string sibling's rows are not reported. Add this sibling case to the tests.server/typescript/packages/migrate-ts/src/expected-schema.ts:435- False all-clear: a TPH subtype that redeclares a base field is never scanned.storedFieldsOfskips every subtype field whose name is inbaseFieldNames, even when the subtype's effective field is a different node with a different type. Reproduced on this head: basePartyhasfield.object detail @objectRef: A(no uuid) andfield.string ref; subtypeHomeoverrides them withdetail @objectRef: B(B hasfield.uuid ownerId) andfield.uuid ref. The model loads with no errors. The generatedHomeInsertSchemaandHomeUpdateSchemaenforce the uuid regex onrefand useBInsertSchemafordetail.uuidPlacesOfreturns [], so--uuid-valuesprints 'declares no stored field.uuid; nothing to scan' and exits 0 while Home rows may hold "mbr1". The round 3 fix covered sibling-versus-sibling differences and left base-versus-subtype. Fix: instoredTablesOf's layout, also emit an entry (withsubtypes) when a subtype's node for a base field or base column differs from the base's node, and keep migrate's columns and DDL unchanged (buildTablealready skips a subtype entry whose column exists). Sibling sites of the same rule: expected-schema.ts:439 (baseColumns.has(column)drops a subtype field that shares a base column); uuid-values-check.ts:145-150 (carrierscounts only subtype entries, so a uuid place held only by an overriding subtype would get norowsrestriction and would report base and other-subtype strings; it must be restricted whenever a base entry occupies the column without a uuid at that path); the reverse case, a base uuid place overridden by a non-uuid subtype field (uuid-values-check.ts:119), currently reads that subtype's rows and reports its strings as findings.ℹ️
server/typescript/packages/cli/src/commands/verify.ts:1711-inferDialect(flags.db)runs outside any try inrunUuidValuesVerify.meta verify --uuid-values --db ./app.db(no URL scheme) therefore throws out ofverifyCommand, and bin/meta.ts does not catch it: the user gets an uncaught error, and--format jsonemits no payload orerrors[]entry. Move the dialect inference into a try that setsuuidValuesRunError, logs it and returns 1, as the connection failure below does.ℹ️
server/typescript/packages/migrate-ts/src/expected-schema.ts:388- Inline fix. The storedFieldsOf docstring and the TPH-block comment still said a column the base already stores is 'not re-emitted'. The change now appends overridesBase entries for subtype redeclarations, and buildTable skips them. Both comments were reworded to describe those entries. Comment-only, no behaviour change.✅ **Test** - passed
✅ No issues found.
scripts/ci-local.sh --affected --strict-toolchainsbun server/typescript/packages/cli/bin/meta.ts verify --uuid-values --db file:app.db (table members with id='mbr1' and one canonical uuid)bun server/typescript/packages/cli/bin/meta.ts verify --uuid-values --db file:clean.db (all canonical)bun server/typescript/packages/cli/bin/meta.ts verify --uuid-values --db file:app.dbb (mistyped path, no matching table)Baseline: scripts/ci-local.sh --affected --strict-toolchains (already passed; not re-run)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.