Repository navigation
TML-2991: diff uniques and indexes structurally — delete the reconciliation pass - #947
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR removes semantic-satisfaction normalization and the standalone unique schema IR, makes index equality symmetric, changes unbound foreign-key namespace projection, and updates Postgres, SQLite, verification, and migration tests for structural comparisons. ChangesStructural schema diffing
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/config-loader
@prisma-next/emitter
@prisma-next/language-server
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/3-targets/3-targets/sqlite/src/core/migrations/issue-planner.ts (1)
272-291: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winPreserve
uniqueon SQLite indexes
CreateIndexCalldrops the index’suniqueflag, even thoughbuildCreateIndexSql()already supportsCREATE UNIQUE INDEX. BothbuildCreateTableCalls()andmapIndexIssue()should threadindex.uniquethrough; otherwise a bareunique: trueindex is recreated as a plain non-unique index and loses its guarantee.packages/3-targets/3-targets/sqlite/src/core/migrations/issue-planner.ts:272-291, 392-393🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/3-targets/3-targets/sqlite/src/core/migrations/issue-planner.ts` around lines 272 - 291, Preserve SQLite index uniqueness by passing each index’s unique flag into CreateIndexCall in buildCreateTableCalls, and update mapIndexIssue to thread index.unique through its CreateIndexCall construction as well. Verify both paths retain unique: true so buildCreateIndexSql emits CREATE UNIQUE INDEX.packages/2-sql/1-core/schema-ir/README.md (1)
81-81: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winUpdate stale
uniquesfield in the Basic Usage example.The example still uses
uniques: [{ columns: ['email'] }], butSqlTableIRInputno longer has auniquesfield — it was removed as part of this PR. This example would cause a TypeScript error for anyone following it. Replace it with a constraint-marked index entry.As per coding guidelines for
**/*.{md,mdc}: Keep docs current.📝 Proposed fix for the stale README example
primaryKey: { columns: ['id'] }, foreignKeys: [], - uniques: [{ columns: ['email'] }], - indexes: [], + indexes: [{ columns: ['email'], unique: true, constraint: true }], },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/2-sql/1-core/schema-ir/README.md` at line 81, Update the Basic Usage example by replacing the removed `uniques` property with an index entry marked as a unique constraint, using the current `SqlTableIRInput` schema and index/constraint field names. Verify the example remains valid TypeScript and accurately represents a unique email constraint.Source: Coding guidelines
🧹 Nitpick comments (1)
packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts (1)
233-237: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate the pass 3 comment to mention
isSuperfluousConstraintOnlyNotEqualfiltering.The comment at lines 209–213 describes pass 3 as dropping only
not-expectedissues outside strict mode, but the changed filter now also dropsisSuperfluousConstraintOnlyNotEqualissues. The comment should reflect this addition to avoid confusing future readers about what the non-strict filter does.♻️ Suggested comment update
* 3. Strict-mode extras gating — `not-expected` (extra table/column/ * constraint) issues and `isSuperfluousConstraintOnlyNotEqual` * (undeclared-constraint-marker) `not-equal` index issues are dropped * entirely outside strict mode, mirroring the retired coordinate walk's * `if (strict) { ...extra_* } }` guards: an additive-only plan must never * even consider dropping an unclaimed object, not just refuse to emit * the drop.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts` around lines 233 - 237, Update the pass 3 comment near the issues filter to state that non-strict mode drops both “not-expected” issues and issues identified by isSuperfluousConstraintOnlyNotEqual, matching the filtering logic in the issues computation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/2-sql/1-core/schema-ir/README.md`:
- Line 81: Update the Basic Usage example by replacing the removed `uniques`
property with an index entry marked as a unique constraint, using the current
`SqlTableIRInput` schema and index/constraint field names. Verify the example
remains valid TypeScript and accurately represents a unique email constraint.
In `@packages/3-targets/3-targets/sqlite/src/core/migrations/issue-planner.ts`:
- Around line 272-291: Preserve SQLite index uniqueness by passing each index’s
unique flag into CreateIndexCall in buildCreateTableCalls, and update
mapIndexIssue to thread index.unique through its CreateIndexCall construction as
well. Verify both paths retain unique: true so buildCreateIndexSql emits CREATE
UNIQUE INDEX.
---
Nitpick comments:
In `@packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts`:
- Around line 233-237: Update the pass 3 comment near the issues filter to state
that non-strict mode drops both “not-expected” issues and issues identified by
isSuperfluousConstraintOnlyNotEqual, matching the filtering logic in the issues
computation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 7e55f40a-900f-48cb-98b4-96bf8ce369f3
📒 Files selected for processing (80)
packages/2-sql/1-core/schema-ir/README.mdpackages/2-sql/1-core/schema-ir/src/exports/types.tspackages/2-sql/1-core/schema-ir/src/ir/schema-node-kinds.tspackages/2-sql/1-core/schema-ir/src/ir/sql-index-ir.tspackages/2-sql/1-core/schema-ir/src/ir/sql-table-ir.tspackages/2-sql/1-core/schema-ir/src/ir/sql-unique-ir.tspackages/2-sql/1-core/schema-ir/src/types.tspackages/2-sql/1-core/schema-ir/test/sql-flat-tree-diffable.test.tspackages/2-sql/1-core/schema-ir/test/sql-index-ir.test.tspackages/2-sql/1-core/schema-ir/test/sql-schema-ir-node.test.tspackages/2-sql/1-core/schema-ir/test/sql-unique-ir.test.tspackages/2-sql/9-family/src/core/control-instance.tspackages/2-sql/9-family/src/core/diff/diff-tree-normalization.tspackages/2-sql/9-family/src/core/diff/fk-schema-normalization.tspackages/2-sql/9-family/src/core/diff/schema-verify.tspackages/2-sql/9-family/src/core/diff/sql-schema-diff.tspackages/2-sql/9-family/src/core/migrations/contract-to-schema-ir.tspackages/2-sql/9-family/src/core/psl-contract-infer/relation-inference.tspackages/2-sql/9-family/src/exports/diff.tspackages/2-sql/9-family/test/contract-to-schema-ir.test.tspackages/2-sql/9-family/test/psl-contract-infer/relation-inference.test.tspackages/2-sql/9-family/test/schema-verify.classify.test.tspackages/2-sql/9-family/test/schema-verify.helpers.tspackages/2-sql/9-family/test/schema-verify.verdict.test.tspackages/2-sql/9-family/test/schema-view.test.tspackages/3-extensions/pgvector/test/migrations/planner.behavior.test.tspackages/3-extensions/pgvector/test/migrations/planner.contract-to-schema-ir.test.tspackages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.tspackages/3-targets/3-targets/postgres/src/core/migrations/diff-database-schema.tspackages/3-targets/3-targets/postgres/src/core/migrations/issue-planner.tspackages/3-targets/3-targets/postgres/src/core/migrations/planner-schema-lookup.tspackages/3-targets/3-targets/postgres/src/core/migrations/planner.tspackages/3-targets/3-targets/postgres/src/core/psl-infer/infer-psl-contract.tspackages/3-targets/3-targets/postgres/src/core/schema-ir/postgres-table-schema-node.tspackages/3-targets/3-targets/postgres/test/migrations/node-issue-planner.test.tspackages/3-targets/3-targets/postgres/test/migrations/planner-schema-lookup.test.tspackages/3-targets/3-targets/postgres/test/migrations/planner.check-constraints.test.tspackages/3-targets/3-targets/postgres/test/migrations/planner.sibling-scoping.test.tspackages/3-targets/3-targets/postgres/test/migrations/rls-planner.test.tspackages/3-targets/3-targets/postgres/test/migrations/verdict-table-less-namespace.test.tspackages/3-targets/3-targets/postgres/test/postgres-database-schema-node.test.tspackages/3-targets/3-targets/postgres/test/postgres-namespace-schema-node.test.tspackages/3-targets/3-targets/postgres/test/postgres-table-schema-node.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract-described-contracts.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/print-psl/print-psl.core.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/print-psl/print-psl.defaults-and-types.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/print-psl/print-psl.enums.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/print-psl/print-psl.naming-and-constraints.test.tspackages/3-targets/3-targets/postgres/test/psl-infer/print-psl/print-psl.relations.test.tspackages/3-targets/3-targets/postgres/test/schema-node-subject-granularity.test.tspackages/3-targets/3-targets/sqlite/src/core/migrations/column-ddl-rendering.tspackages/3-targets/3-targets/sqlite/src/core/migrations/diff-database-schema.tspackages/3-targets/3-targets/sqlite/src/core/migrations/issue-planner.tspackages/3-targets/3-targets/sqlite/src/core/migrations/operations/tables.tspackages/3-targets/3-targets/sqlite/src/core/migrations/planner-strategies.tspackages/3-targets/3-targets/sqlite/src/core/migrations/planner.tspackages/3-targets/3-targets/sqlite/test/migrations/node-issue-helpers.tspackages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.tspackages/3-targets/3-targets/sqlite/test/migrations/planner.sibling-scoping.test.tspackages/3-targets/6-adapters/postgres/src/core/control-adapter.tspackages/3-targets/6-adapters/postgres/test/control-adapter.test.tspackages/3-targets/6-adapters/postgres/test/migrations/fixtures/runner-fixtures.tspackages/3-targets/6-adapters/postgres/test/migrations/planner-schema-lookup.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.tspackages/3-targets/6-adapters/postgres/test/migrations/rls-collect-extension-issues.test.tspackages/3-targets/6-adapters/sqlite/src/core/control-adapter.tspackages/3-targets/6-adapters/sqlite/test/control-adapter.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/db-init-update.cli.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/fixtures/runner-fixtures.tsskills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.mdtest/e2e/framework/test/sqlite/migrations/additive.test.tstest/e2e/framework/test/sqlite/migrations/fk-preservation.test.tstest/integration/test/cross-package/postgres-control-policy-planner.test.tstest/integration/test/cross-package/postgres-issue-planner.test.tstest/integration/test/family.introspect.integration.test.tstest/integration/test/family.introspect.test.tstest/integration/test/family.schema-verify.constraints.test.ts
💤 Files with no reviewable changes (24)
- packages/2-sql/1-core/schema-ir/src/ir/sql-unique-ir.ts
- packages/3-targets/3-targets/postgres/test/postgres-database-schema-node.test.ts
- packages/3-targets/3-targets/postgres/test/migrations/planner-schema-lookup.test.ts
- packages/2-sql/1-core/schema-ir/test/sql-unique-ir.test.ts
- packages/2-sql/9-family/src/core/diff/diff-tree-normalization.ts
- packages/3-targets/3-targets/postgres/test/schema-node-subject-granularity.test.ts
- packages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.ts
- packages/2-sql/1-core/schema-ir/src/exports/types.ts
- packages/2-sql/1-core/schema-ir/src/types.ts
- packages/3-targets/3-targets/postgres/test/psl-infer/print-psl/print-psl.enums.test.ts
- packages/3-targets/6-adapters/postgres/test/migrations/rls-collect-extension-issues.test.ts
- packages/3-targets/3-targets/postgres/test/migrations/rls-planner.test.ts
- packages/2-sql/9-family/test/schema-view.test.ts
- packages/3-targets/3-targets/postgres/test/postgres-namespace-schema-node.test.ts
- packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
- packages/3-targets/3-targets/postgres/test/migrations/planner.check-constraints.test.ts
- packages/3-targets/3-targets/sqlite/test/migrations/planner.sibling-scoping.test.ts
- test/integration/test/cross-package/postgres-control-policy-planner.test.ts
- packages/3-targets/3-targets/postgres/test/migrations/verdict-table-less-namespace.test.ts
- packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
- packages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract-described-contracts.test.ts
- packages/3-extensions/pgvector/test/migrations/planner.contract-to-schema-ir.test.ts
- test/integration/test/cross-package/postgres-issue-planner.test.ts
- packages/3-targets/3-targets/postgres/test/migrations/planner.sibling-scoping.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts (1)
89-89: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFilename no longer matches content. The suite is now "structural reconcile (no satisfaction)" yet the file is still
planner.semantic-satisfaction.test.ts. Consider renaming (e.g.planner.structural-reconcile.test.ts) so the file name reflects the reframed behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts` at line 89, Rename the test file containing the “PostgresMigrationPlanner - structural reconcile (no satisfaction)” suite from its semantic-satisfaction name to a structural-reconcile name, such as planner.structural-reconcile.test.ts, so the filename matches the suite’s behavior.packages/3-targets/3-targets/postgres/src/core/migrations/issue-planner.ts (1)
749-778: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the default unique-constraint name to a shared helper. The fallback
${tableName}_${index.columns.join('_')}_keyis duplicated indropIndexOrConstraintCallandcreateIndexOrConstraintCall. Since a drop must target the same name a priorAddUniqueCallcreated, centralizing keeps the two sides from silently diverging (mirroring howdefaultIndexNameis already shared).♻️ Proposed helper
+function defaultUniqueConstraintName(tableName: string, columns: readonly string[]): string { + return `${tableName}_${columns.join('_')}_key`; +} + function dropIndexOrConstraintCall( schemaName: string, tableName: string, index: SqlIndexIR, ): PostgresOpFactoryCall { if (index.constraint === true) { - const name = index.name ?? `${tableName}_${index.columns.join('_')}_key`; + const name = index.name ?? defaultUniqueConstraintName(tableName, index.columns); return new DropConstraintCall(schemaName, tableName, name, 'unique'); } const indexName = index.name ?? defaultIndexName(tableName, index.columns); return new DropIndexCall(schemaName, tableName, indexName); } function createIndexOrConstraintCall( schemaName: string, tableName: string, index: SqlIndexIR, ): PostgresOpFactoryCall { if (index.constraint === true) { - const name = index.name ?? `${tableName}_${index.columns.join('_')}_key`; + const name = index.name ?? defaultUniqueConstraintName(tableName, index.columns); return new AddUniqueCall(schemaName, tableName, name, [...index.columns]); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/3-targets/3-targets/postgres/src/core/migrations/issue-planner.ts` around lines 749 - 778, Extract the duplicated default unique-constraint naming expression from dropIndexOrConstraintCall and createIndexOrConstraintCall into a shared helper, analogous to defaultIndexName. Use that helper in both constraint branches so DropConstraintCall and AddUniqueCall always target the same generated name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/3-targets/3-targets/postgres/src/core/migrations/issue-planner.ts`:
- Around line 749-778: Extract the duplicated default unique-constraint naming
expression from dropIndexOrConstraintCall and createIndexOrConstraintCall into a
shared helper, analogous to defaultIndexName. Use that helper in both constraint
branches so DropConstraintCall and AddUniqueCall always target the same
generated name.
In
`@packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts`:
- Line 89: Rename the test file containing the “PostgresMigrationPlanner -
structural reconcile (no satisfaction)” suite from its semantic-satisfaction
name to a structural-reconcile name, such as
planner.structural-reconcile.test.ts, so the filename matches the suite’s
behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: a3984b36-bb60-4bb6-8682-b84b3e2d0c19
📒 Files selected for processing (11)
packages/2-sql/1-core/schema-ir/src/ir/sql-index-ir.tspackages/2-sql/1-core/schema-ir/test/sql-index-ir.test.tspackages/2-sql/9-family/src/core/migrations/schema-differ.tspackages/2-sql/9-family/src/exports/diff.tspackages/2-sql/9-family/test/schema-verify.classify.test.tspackages/2-sql/9-family/test/schema-verify.verdict.test.tspackages/3-targets/3-targets/postgres/src/core/migrations/diff-database-schema.tspackages/3-targets/3-targets/postgres/src/core/migrations/issue-planner.tspackages/3-targets/3-targets/postgres/test/migrations/node-issue-planner.test.tspackages/3-targets/3-targets/sqlite/src/core/migrations/diff-database-schema.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
💤 Files with no reviewable changes (1)
- packages/2-sql/9-family/src/exports/diff.ts
✅ Files skipped from review due to trivial changes (1)
- packages/2-sql/9-family/src/core/migrations/schema-differ.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/3-targets/3-targets/postgres/test/migrations/node-issue-planner.test.ts
4eb5e7d to
c57c0c1
Compare
…uctural nodes Discard the merge-into-one-node approach: a unique constraint (pg_constraint) and an index (pg_index) are distinct schema elements. The slice deletes the semantic-satisfaction reconciliation pass and keeps SqlUniqueIR/SqlIndexIR as two structural nodes, so the generic differ compares the trees with no massaging. Deliberate behaviour change: a unique-vs-index mismatch is drift. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Drop the (!this.unique || node.unique) stronger-satisfies-weaker rule; a unique index and a non-unique index on the same columns are different objects and are not equal. Keep indexOptionsLooselyEqual and the introspection-side btree->undefined type normalization (real value normalization at construction). Unit matrix rewritten to a symmetric row. Per projects/postgres-rls/slices/unify-unique-and-index-nodes/design.md. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…esolution into derivation The differ now runs diffSchemas(expected, actual) on the trees exactly as derived — no pre-diff transformation. Deleted: - resolveSemanticSatisfaction / normalizeFlatActualForDiff / the SemanticSatisfaction* types (diff-tree-normalization.ts removed entirely) and their call sites: normalizePostgresActualForDiff (postgres) and the two SQLite normalize calls. - the caller-less isUniqueConstraintSatisfied / isIndexSatisfied predicates (grep-confirmed zero callers) and their exports/diff.ts entries. FK schema-segment normalization folds into derivation: a target-agnostic flattenReferencedNamespace option on contractToSchemaIR stamps the flat empty resolvedReferencedNamespace at derivation. SQLite passes it (its diff path); Postgres omits it and re-resolves FK namespaces downstream in contract-to-postgres-database-schema-node, so the family default is never observed there — byte-neutral (FK verdict tests unchanged). Behaviour flips (intended, structural equality): contract @@unique vs live unique index → fails (constraint missing + index extra); contract @@index vs live unique constraint → fails; stray live unique index → ordinary extra (strict-fails / lenient-passes); @@unique round-trip → clean. Verdict suite rewritten to these. Fence: schema-verify.ts is byte-unchanged vs origin/main (general strict/lenient extra grading untouched). Per projects/postgres-rls/slices/unify-unique-and-index-nodes/design.md. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…tale unique-ir debt note The unique-vs-index planner cases no longer assert semantic satisfaction: a contract @@unique against a live unique index adds the constraint (the destructive index drop is suppressed under an additive policy), a contract @@index against a live unique index is an incompatible index change, and a contract @@index against a live unique constraint creates the index. Add a derivation test for the flattenReferencedNamespace FK-fold and remove the accepted-under-protest note on SqlUniqueIR (its premise — delete the node — was rejected; the two-node model is the accepted design). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ot a flag Replace the rejected flattenReferencedNamespace option with node behavior: NamespaceBase gains an isUnbound getter (the single encapsulated place the UNBOUND_NAMESPACE_ID comparison lives — required on the base rather than a singleton override because non-singleton SqliteDatabase instances with tables also occupy the unbound slot). convertForeignKey resolves the FK target namespace node from storage and stamps no referencedSchema when it is unbound; flat introspection stamps nothing, so both diff sides FK ids meet by construction. Bound and cross-space targets stamp verbatim as before. The Postgres rebuild restores its own coordinate for the unbound slot (referencedSchema ?? UNBOUND_NAMESPACE_ID, the fallback already used for resolution in the same function) so REFERENCES qualification and the expected tree stay byte-identical. Deletes the option, its threading, and the SQLite/harness call sites; the schema-IR layer never sees the sentinel. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Rebasing onto the slice-3/native-enums base surfaces the extension substrate touch (pgvector test double) to check:upgrade-coverage in the 0.14-to-0.15 window. Record the one genuine extension-facing consequence of the FK node-identity work: contractToSchemaIR no longer stamps referencedSchema for an unbound-namespace FK target (absent, not the __unbound__ sentinel), and namespace identity is answered by NamespaceBase.isUnbound. Extensions that rebuild a target schema-IR tree default the absent value with `?? UNBOUND_NAMESPACE_ID`. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
c57c0c1 to
afab1b9
Compare
…ntity Slice-0 reality check: postgres-rls 2.6 merged as #947 keeping SqlUniqueIR and SqlIndexIR as two structural nodes, rejecting the merged-node-with-flag shape this spec assumed. Operator confirmed the two-node substrate is the principled one (discrete-entities: an index must not claim to also be a constraint; ADR 161 superseding note, Data Contract design principle 4). Amendments: name identity covers index nodes and policies only; unique constraints keep tuple identity (fully structured, content comparison is already exact). @@unique/constraints.unique surfaces unchanged; the @@unique default wire-prefix is dropped. TS policy exact-naming is out of scope (rls-ts-authoring was never built; postgres-rls closed in #979). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ntity Slice-0 reality check: postgres-rls 2.6 merged as #947 keeping SqlUniqueIR and SqlIndexIR as two structural nodes, rejecting the merged-node-with-flag shape this spec assumed. Operator confirmed the two-node substrate is the principled one (discrete-entities: an index must not claim to also be a constraint; ADR 161 superseding note, Data Contract design principle 4). Amendments: name identity covers index nodes and policies only; unique constraints keep tuple identity (fully structured, content comparison is already exact). @@unique/constraints.unique surfaces unchanged; the @@unique default wire-prefix is dropped. TS policy exact-naming is out of scope (rls-ts-authoring was never built; postgres-rls closed in #979). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Linked issue
Refs TML-2991 (slice 2.6 of postgres-rls). Between slice 2.5 (
one-differ-two-ir-planner, #921) and slice 3 (explicit-rls-control, #945).At a glance
The schema differ compares two derived schema-IR trees and does nothing else — no pre-diff pass that transforms a tree to make the verdict come out "satisfied". This PR deletes the one place that violated that:
export function diffSqliteSchema(input: { … }) { - const expected = neutralizeFlatExpectedFkSchemas( - normalizeActualForSatisfaction(contractToSchemaIR(input.contract, { … })), - ); - const actual = normalizeFlatActualForDiff(expected, introspect(input.db)); - return diffSchemas(expected, actual); + const expected = contractToSchemaIR(input.contract); + return diffSchemas(expected, introspect(input.db)); }diff-tree-normalization.ts— the 211-lineresolveSemanticSatisfactionreconciliation pass — is gone.Decision
A unique constraint (
pg_constraint) and an index (pg_index) are different schema elements — different catalog, different DDL, independent lifecycle. They stay two structural nodes (SqlUniqueIR,SqlIndexIR), exactly as primary keys, foreign keys, and check constraints are already separate nodes. The debt slice 2.5 left behind was not the two node kinds — it was the pre-diff pass that massaged the actual tree to fake "semantic satisfaction" (a live unique index silently counting as a declared unique constraint, and vice-versa).resolveSemanticSatisfaction/normalizeFlatActualForDiffand the caller-lessisUniqueConstraintSatisfied/isIndexSatisfiedare removed; both diff paths rundiffSchemas(expected, actual)on the trees as derived.SqlIndexIR.isEqualTobecomes purely symmetric structural equality —unique === unique && type === type && options— dropping the "stronger-satisfies-weaker" rule. Noconstraintmarker, no merging, no dedupe, no fail-loud rule: none is needed once the two elements are honestly two nodes.NamespaceBase.isUnbound), never by comparing an__unbound__string. An FK targeting the unbound namespace stamps no referenced-namespace (matching what flat introspection produces, so the two sides' FK ids meet by construction); a bound one stamps it as before. No pre-diff normalization pass survives, and the sentinel string never enters the schema-IR layer. (The broader sweep — routing the ~15 remainingid === UNBOUND_NAMESPACE_IDconsumers throughisUnboundand banning the literal — is tracked as TML-2997; this PR lands the seam.)Behavior change
Deleting satisfaction makes a unique-vs-index mismatch plain structural drift (verdicts and planner ops flip only for the mismatch cases; the general strict/lenient extra-tolerance and cross-space ownership are untouched —
schema-verify.tsis byte-identical tomain):@@uniquevs a live unique index → fails (constraintmissing+ indexextra).@@indexvs a live unique constraint → fails.@@indexvs a live unique index (both indexes, differ onunique) → recreate (indexIncompatible) — a plain and a unique index are genuinely different objects.@@uniquevs the live unique constraint it created (the normal round-trip) → clean.The planner needs no new code: a mismatch is a
missingnode plus anextranode, which its existing independentSqlUniqueIR/SqlIndexIRarms map to drop-the-extra + create-the-missing, with the existing control-policy disposition suppressing the drop under an additive policy.Reviewer notes
constraintboolean. That merge — two schema elements in one node keyed by column tuple — forced new tree-massaging back in (an introspection dedupe and a fail-loud derivation rule) to avoid id collisions, which is the exact anti-pattern the slice exists to remove. It was discarded; this is the corrected, deletion-dominated design. If you saw the prior force-pushed history, ignore it.git diff main -- packages/2-sql/9-family/src/core/diff/schema-verify.tsis empty. The verdict grading, control-policy disposition, and cross-space ownership are byte-unchanged; the behavior flips fall out purely of the node model, not the grading.sqlite/.../runner.across-spaces.test.tsdeclared both@@uniqueand@@indexonemailbut its hand-written DDL created onlyemail TEXT UNIQUE. It passed before only because satisfaction masked the missing index. AddedCREATE INDEXso the live schema honestly carries both declared elements.NamespaceBase.isUnboundis added as the single encapsulated place the__unbound__sentinel is compared; derivation reads it instead of the string. The Postgres target re-stampsreferencedSchema ?? UNBOUND_NAMESPACE_IDfor its own REFERENCES-clause DDL (keeping Postgres byte-identical — proven byfixtures:checkclean); that lone sentinel-as-value in the target layer is the kind of thing TML-2997 sweeps up.mainmid-flight and touched these files. This branch rebased onto them: our reconciliation deletion and slice-3'srlsEnabled/nativeEnumscoexist (deleting the actual-tree-rebuild function is safer than merging — the introspected tree flows to the differ unmodified, RLS/enum data intact). The full RLS suite is green on the new base.SqlUniqueIRandSqlIndexIRare otherwise unchanged frommain; both planners are untouched.Verification
Run on final HEAD (rebased onto current
main):pnpm build,pnpm typecheck— clean.pnpm lint:deps,pnpm lint,pnpm lint:casts,pnpm lint:framework-vocabulary,pnpm check:upgrade-coverage --mode pr— pass.pnpm fixtures:check— no drift.pnpm test:packages— pass (only the known macOS/var→/private/varconfig-loader symlink flake).pnpm test:integration,pnpm test:e2e(109/109) — green (documented environmental flakes only; each passes in isolation).runner.unbound-namespace, which drives theisUnboundpath end-to-end on live PGlite). Our deletions do not disturb RLS.Alternatives considered
SqlIndexIRwith aconstraintflag). Rejected — it conflates two distinct catalog elements into one node keyed by column tuple, which cannot represent a unique constraint and a same-column index at once, forcing an introspection dedupe and a fail-loud contract rule to paper over the collision. That re-introduces the tree-massaging this slice removes.Skill update
One extension-author upgrade entry recorded (
schema-ir-fk-unbound-referenced-schema-absent, 0.14→0.15):contractToSchemaIRno longer stampsreferencedSchemafor an FK targeting the unbound namespace (identity is read viaNamespaceBase.isUnbound); target tree re-builders default with?? UNBOUND_NAMESPACE_ID. No public API/CLI/config surface change and the emitted contract is unchanged; the behavior change is todb verify/migration plandrift semantics for unique-vs-index mismatches, documented above.Checklist
git commit -s) per the DCO.TML-NNNN: <title>form.Summary by CodeRabbit
New Features
Bug Fixes
Documentation