feat(migrate): physical index/constraint attrs + auto schema-scope + DB-adoption fixes#42
Merged
Conversation
…adoption fixes Enables non-destructive adoption of an existing Postgres database (verify --db / migrate --from-db reaching zero drift against a hand-built schema) and richer index modeling. All physical-storage concerns are contributed by the db provider (spec/metamodel/db.json `extends`), not core. db provider — new physical attrs on core identity subtypes: - identity.secondary @orders — per-key sort direction (asc|desc) → DESC index keys - identity.secondary @where — partial-index predicate → WHERE (<pred>) - identity.reference @constraintName — FK constraint-name override (adopt an existing DB's naming without a rename) Wired end-to-end: IndexDescriptor {orders?, where?}, buildSecondaryIndexes, renderCreateIndex (DESC + WHERE), readPgIndexes (indoption + pg_get_expr(indpred); expression-key indexes skipped), indexEquals (positional orders + normalized predicate). FkDescriptor honours @constraintName. diff — auto schema scope (DiffArgs.scopeSchemas): the diff manages only the schemas the expected/metadata side declares; a table in an undeclared schema belongs to another owner and is left untouched. Makes per-owner drift gates clean with no manual config; an explicit set overrides; an empty model preserves prior whole-DB behavior. introspect — gen_random_uuid() classified as an expression default: parsePgDefault now treats any bare function-call default as an expression (mirrors the metadata-side EXPR_DEFAULT_PATTERNS), so a uuid-PK column round-trips without a spurious default diff. fix(metadata) — allowedValues on an isArray attr validates each ELEMENT, not the array as a whole (previously always failed; @orders is the first isArray+allowedValues attr). Tests: index-partial-ordered, diff-schema-scope, expected-schema-fk-constraint-name, isArray-allowedValues cases; updated diff-schema-aware + identity/coverage gates; regenerated the embedded metamodel, registry manifest, metamodel docs, and Python spec copies. metadata + migrate-ts suites green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…entity attrs Registers the three db-provider identity attrs (identity.secondary @orders + @where, identity.reference @constraintName) in each non-TS port so every port's emitted registry manifest byte-matches the canonical fixtures/registry-conformance/ expected-registry.json (canonical/TS is the source of truth). - Python: db_provider.py extends TYPE_IDENTITY secondary/reference (db_constants.py constants); AttrSchema is_array + descriptions sourced byte-exact from db.json. - Java: SecondaryIdentity / ReferenceIdentity register the attrs via the fluent builder; descriptions land via applySpecDescriptions from the bundled spec/metamodel/db.json (Kotlin reuses the JVM registration — no separate change). - C#: DbProvider extends the identity subtypes with DbSchema schemas; SpecMetamodel/ db.json mirror synced. The manifest carries no allowedValues, so @orders' asc/desc set is validation-only. Verified locally: registry-conformance passes for all four ports (python 3, java 3, kotlin 1, csharp 3). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Enables non-destructive adoption of an existing Postgres database (
verify --db/migrate --from-dbreaching zero drift against a hand-built schema) and richer index modeling. All new physical-storage attributes are contributed by the db provider (spec/metamodel/db.jsonextends), not core.Changes
db provider — physical attrs on core identity subtypes
identity.secondary@orders— per-key sort direction (asc|desc) → DESC index keysidentity.secondary@where— partial-index predicate →WHERE (<pred>)identity.reference@constraintName— FK constraint-name override (adopt an existing DB's FK naming without a rename)Wired end-to-end:
IndexDescriptor {orders?, where?},buildSecondaryIndexes,renderCreateIndex(DESC + WHERE),readPgIndexes(indoption+pg_get_expr(indpred); expression-key indexes skipped),indexEquals(positional orders + normalized predicate);FkDescriptorhonours@constraintName.diff — auto schema scope (
DiffArgs.scopeSchemas)The diff manages only the schemas the expected/metadata side declares; a table in an undeclared schema belongs to another owner and is left untouched. Per-owner drift gates become clean with no manual config. Explicit set overrides; empty model preserves prior whole-DB behavior.
introspect —
gen_random_uuid()as an expression defaultparsePgDefaultnow treats any bare function-call default as an expression (mirrors the metadata-sideEXPR_DEFAULT_PATTERNS), so a uuid-PK column round-trips without a spurious default diff.fix(metadata) —
allowedValueson anisArrayattr validates each element, not the array as a whole (@ordersis the firstisArray+allowedValuesattr).Tests
New:
index-partial-ordered,diff-schema-scope,expected-schema-fk-constraint-name, isArray-allowedValues cases. Updated:diff-schema-aware, identity-completeness + coverage gates. Regenerated the embedded metamodel, registry manifest, metamodel docs, and Python spec copies.metadata+migrate-tssuites green (2521 pass).Cross-port note
This grows the canonical metamodel vocabulary (new db-provider attrs). The TS port and the Python spec copies are updated here; the Java / Kotlin / C# ports will need to reconcile their registry-conformance against the regenerated
expected-registry.json(expected RED until they implement the new attrs), per the documented multi-port reconciliation flow.🤖 Generated with Claude Code