Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

Decouple extensions - #3

Merged
wmadden merged 52 commits into
mainfrom
decouple-extensions
Nov 12, 2025
Merged

wmadden merged 52 commits into
mainfrom
decouple-extensions

Conversation

@wmadden

@wmadden wmadden commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

No description provided.

wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 10, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 12, 2026
…Missing primitive (M3 R4 item 21)

Lift the existence-check + write-if-missing pattern out of two
copies (CLI 'runContractSpaceExtensionMigrationsPass' and the
cipherstash AM11/AM12 regression test) into a single primitive on
'@prisma-next/migration-tools/io':

  materialiseExtensionMigrationPackageIfMissing(
    targetDir: string,
    pkg: MigrationPackageContents,
  ): Promise<{ readonly written: boolean }>

Returns '{ written: true }' on first run (writes manifest, ops,
contract.json) and '{ written: false }' when the package directory
already exists (skips silently — the AC-7 / AM12 by-existence
idempotency semantic from framework-mechanism.spec.md § 3).

Both call sites now consume the primitive:

  - packages/1-framework/3-tooling/cli/.../contract-space-extension-
    migrations-pass.ts: drops the inline pathExists helper + the
    'pkgPath = join(spaceDir, dirName)' boilerplate. The pass remains
    structurally identical.
  - packages/3-extensions/cipherstash/test/am11-am12-no-descriptor.
    test.ts: the rematerialiseSkippingExisting helper now wraps the
    primitive directly — same behavioural property (re-running leaves
    on-disk content byte-untouched) but exercises the *exact* code
    path the CLI uses, instead of mirroring it.

Drains R2 deviation #3 (pathExists duplicate). Test count: +4 unit
tests on the primitive in migration-tools (431 -> 435 in that
package). Cipherstash test count unchanged (37 -> 37).
wmadden added a commit that referenced this pull request May 12, 2026
Captures the design pass driven by the example-app forcing function:

- decisions.md: canonical decision log (A1-A7 TS authoring, B1-B6 PSL
  authoring, C1-C8 cross-cutting). Records the closes on holes #1, #2,
  #3, #4, #5, #15, #16, #17 and the elevation of roles/posture/extension
  structure to first-class concepts.

- design-holes.md: marks resolved holes against decisions, updates the
  blocking-holes summary table.

- rls.md: rewritten to the .rls([...]) array form (TS) and top-level
  policy <name> { key = value } blocks (PSL), with ref() helper semantics
  documented.

- overview.md: refreshed at-a-glance snippet, capability bullets, stretch
  goals to align with the array-of-descriptors RLS surface and the
  out-of-scope-for-v0.1 framing of functions-as-IR.

- example/src/prisma/contract.ts: rewritten to exercise the settled
  surface (composite uniques in .attributes(), .rls([...]) descriptor
  array, ref() helper for cross-model predicates, no capability flag).

- extension-package.md, posture.md, README.md: cross-reference updates
  pointing at decisions.md and reflecting the role IR + subpath
  entrypoint decisions.
wmadden added a commit that referenced this pull request May 13, 2026
Captures the design pass driven by the example-app forcing function:

- decisions.md: canonical decision log (A1-A7 TS authoring, B1-B6 PSL
  authoring, C1-C8 cross-cutting). Records the closes on holes #1, #2,
  #3, #4, #5, #15, #16, #17 and the elevation of roles/posture/extension
  structure to first-class concepts.

- design-holes.md: marks resolved holes against decisions, updates the
  blocking-holes summary table.

- rls.md: rewritten to the .rls([...]) array form (TS) and top-level
  policy <name> { key = value } blocks (PSL), with ref() helper semantics
  documented.

- overview.md: refreshed at-a-glance snippet, capability bullets, stretch
  goals to align with the array-of-descriptors RLS surface and the
  out-of-scope-for-v0.1 framing of functions-as-IR.

- example/src/prisma/contract.ts: rewritten to exercise the settled
  surface (composite uniques in .attributes(), .rls([...]) descriptor
  array, ref() helper for cross-model predicates, no capability flag).

- extension-package.md, posture.md, README.md: cross-reference updates
  pointing at decisions.md and reflecting the role IR + subpath
  entrypoint decisions.
wmadden added a commit that referenced this pull request May 13, 2026
Captures the design pass driven by the example-app forcing function:

- decisions.md: canonical decision log (A1-A7 TS authoring, B1-B6 PSL
  authoring, C1-C8 cross-cutting). Records the closes on holes #1, #2,
  #3, #4, #5, #15, #16, #17 and the elevation of roles/posture/extension
  structure to first-class concepts.

- design-holes.md: marks resolved holes against decisions, updates the
  blocking-holes summary table.

- rls.md: rewritten to the .rls([...]) array form (TS) and top-level
  policy <name> { key = value } blocks (PSL), with ref() helper semantics
  documented.

- overview.md: refreshed at-a-glance snippet, capability bullets, stretch
  goals to align with the array-of-descriptors RLS surface and the
  out-of-scope-for-v0.1 framing of functions-as-IR.

- example/src/prisma/contract.ts: rewritten to exercise the settled
  surface (composite uniques in .attributes(), .rls([...]) descriptor
  array, ref() helper for cross-model predicates, no capability flag).

- extension-package.md, posture.md, README.md: cross-reference updates
  pointing at decisions.md and reflecting the role IR + subpath
  entrypoint decisions.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 13, 2026
Captures the design pass driven by the example-app forcing function:

- decisions.md: canonical decision log (A1-A7 TS authoring, B1-B6 PSL
  authoring, C1-C8 cross-cutting). Records the closes on holes #1, #2,
  #3, #4, #5, #15, #16, #17 and the elevation of roles/posture/extension
  structure to first-class concepts.

- design-holes.md: marks resolved holes against decisions, updates the
  blocking-holes summary table.

- rls.md: rewritten to the .rls([...]) array form (TS) and top-level
  policy <name> { key = value } blocks (PSL), with ref() helper semantics
  documented.

- overview.md: refreshed at-a-glance snippet, capability bullets, stretch
  goals to align with the array-of-descriptors RLS surface and the
  out-of-scope-for-v0.1 framing of functions-as-IR.

- example/src/prisma/contract.ts: rewritten to exercise the settled
  surface (composite uniques in .attributes(), .rls([...]) descriptor
  array, ref() helper for cross-model predicates, no capability flag).

- extension-package.md, posture.md, README.md: cross-reference updates
  pointing at decisions.md and reflecting the role IR + subpath
  entrypoint decisions.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 13, 2026
Captures the design pass driven by the example-app forcing function:

- decisions.md: canonical decision log (A1-A7 TS authoring, B1-B6 PSL
  authoring, C1-C8 cross-cutting). Records the closes on holes #1, #2,
  #3, #4, #5, #15, #16, #17 and the elevation of roles/posture/extension
  structure to first-class concepts.

- design-holes.md: marks resolved holes against decisions, updates the
  blocking-holes summary table.

- rls.md: rewritten to the .rls([...]) array form (TS) and top-level
  policy <name> { key = value } blocks (PSL), with ref() helper semantics
  documented.

- overview.md: refreshed at-a-glance snippet, capability bullets, stretch
  goals to align with the array-of-descriptors RLS surface and the
  out-of-scope-for-v0.1 framing of functions-as-IR.

- example/src/prisma/contract.ts: rewritten to exercise the settled
  surface (composite uniques in .attributes(), .rls([...]) descriptor
  array, ref() helper for cross-model predicates, no capability flag).

- extension-package.md, posture.md, README.md: cross-reference updates
  pointing at decisions.md and reflecting the role IR + subpath
  entrypoint decisions.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 16, 2026
…el helpers shape (post-R2b)

M9 R2b flattened pack-contributed entity helpers from
helpers.entities.<name> onto top-level helpers.<name> (alongside
built-in helpers.model / helpers.rel). Per Decision 21 + reviewer
item #3, sweep the spec to match the new on-disk shape:

- FR8b — reframe principle from "asymmetric naming is intentional"
  to "top-level placement is the principle: built-in and
  contributed top-level entities are grammatically indistinguishable
  from the user vantage point". Asymmetry is structural
  (contribution-side namespace vs user-side flat surface), not a
  deliberate naming opposition.
- Authoring surface § "Asymmetric naming, deliberate" prose at
  line 122 — same reframing; explicit before/after wording so
  future readers see the shape evolution.
- Vocabulary § (line 130) — packs ship entityTypes.namespace /
  entityTypes.enum / entityTypes.policy (was entities.*).
- Illustrative example block — pack contribution surface uses
  entityTypes (was stale entities since M7); user authoring
  surface uses helpers.enum(...) (was helpers.entities.enum).
- Pack-bag-driven type narrowing prose — top-level entity helpers
  rather than helpers.entities namespace.
- AC12a (mechanism subclause) — refined-in-M9-R2b annotation;
  helpers.<entityName> placement.
- AC12a (named-exemplar subclause) — helpers.enum / helpers.namespace
  shape for M4 and M5a exemplars.
- FR12 — TS authoring surface evolves to canonical enum({ name,
  values }) shape (was entities.enum); top-level helpers.<name>
  shape post-M9 R2b.

Two helpers.entities references remain — both deliberate
contrastive references explaining the shape change ("rather than
helpers.entities.enum(...)"; "no entities. namespace").

ADR drafts under projects/target-extensible-ir/specs/ deferred to
PR2 close-out per the same Decision 21 — they refresh + promote to
docs/architecture docs/adrs/ as a single step when the M5a
namespace exemplar provides the second consumer.

No code touched.
wmadden added a commit that referenced this pull request May 27, 2026
…arnings

Post-flight orchestrator amendments after slice m1 R1 returned COMPLETE
with one surfaced spec-deviation.

- FR2 / PDoD8: refine "absent entirely" to "absent from runtime declarations
  (dependencies + peerDependencies)"; permit devDependencies on non-consumer
  packages whose own test code imports from 'mongodb'. The recon-specialist's
  src/-only scan missed three test files in @prisma-next/target-mongo that
  import MongoClient / Db / MongoServerError; the implementer correctly
  halted-and-surfaced rather than silently rewriting the spec.
- Slice plan structural-coherence check #3: rewrite from line-oriented rg
  to JSON-aware jq so the verification actually inspects peerDependencies
  vs devDependencies rather than matching either co-occurrence in flat lines.
- Capture three learnings: recon must scan test/ as well as src/; structural-
  coherence checks on JSON must use jq; specs about runtime declarations
  should name the dep-shape buckets explicitly.
- Subagent registry: log implementer m1 R1 dispatch + outcome.

No source-code or example changes. Project-internal docs only.
wmadden added a commit that referenced this pull request May 27, 2026
…arnings

Post-flight orchestrator amendments after slice m1 R1 returned COMPLETE
with one surfaced spec-deviation.

- FR2 / PDoD8: refine "absent entirely" to "absent from runtime declarations
  (dependencies + peerDependencies)"; permit devDependencies on non-consumer
  packages whose own test code imports from 'mongodb'. The recon-specialist's
  src/-only scan missed three test files in @prisma-next/target-mongo that
  import MongoClient / Db / MongoServerError; the implementer correctly
  halted-and-surfaced rather than silently rewriting the spec.
- Slice plan structural-coherence check #3: rewrite from line-oriented rg
  to JSON-aware jq so the verification actually inspects peerDependencies
  vs devDependencies rather than matching either co-occurrence in flat lines.
- Capture three learnings: recon must scan test/ as well as src/; structural-
  coherence checks on JSON must use jq; specs about runtime declarations
  should name the dep-shape buckets explicitly.
- Subagent registry: log implementer m1 R1 dispatch + outcome.

No source-code or example changes. Project-internal docs only.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 27, 2026
…arnings

Post-flight orchestrator amendments after slice m1 R1 returned COMPLETE
with one surfaced spec-deviation.

- FR2 / PDoD8: refine "absent entirely" to "absent from runtime declarations
  (dependencies + peerDependencies)"; permit devDependencies on non-consumer
  packages whose own test code imports from 'mongodb'. The recon-specialist's
  src/-only scan missed three test files in @prisma-next/target-mongo that
  import MongoClient / Db / MongoServerError; the implementer correctly
  halted-and-surfaced rather than silently rewriting the spec.
- Slice plan structural-coherence check #3: rewrite from line-oriented rg
  to JSON-aware jq so the verification actually inspects peerDependencies
  vs devDependencies rather than matching either co-occurrence in flat lines.
- Capture three learnings: recon must scan test/ as well as src/; structural-
  coherence checks on JSON must use jq; specs about runtime declarations
  should name the dep-shape buckets explicitly.
- Subagent registry: log implementer m1 R1 dispatch + outcome.

No source-code or example changes. Project-internal docs only.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 30, 2026
…typeName)

D3a (planner-side compound key). collectPostgresEnumTypes now returns a map
keyed by the serialised compound key ${namespaceId}\u0000${typeName} instead of
bare typeName, so two namespaces declaring an enum with the same NAME produce two
distinct entries — no last-write-wins collapse. NUL is the separator (invalid in
both Postgres identifiers and TS symbol names, so unambiguous).

nativeEnumPlanCallStrategy iterates compound entries; handledKeys / introducedKeys
/ rebuiltKeys are compound-key sets. The issue-matching filter resolves the issue
to its compound key via enumCompoundKey(resolveNamespaceIdForIssue(issue),
issue.typeName), relying on the D1 substrate guarantee that enum-related issues
carry namespaceId. The introduce-and-rebuild guard error displays keys with a
readable "ns.type" rendering.

This closes the same-NAME collision (the primary CodeRabbit finding) and satisfies
SDoD6/SDoD7. The same-nativeType collision (readExistingEnumValues schema axis,
spec edge case #3) is deferred to D3b: threading (schemaName, nativeType) through
readExistingEnumValues cascades into the schema-IR provider (the introspection
merge in 6-adapters/.../control-adapter.ts explicitly discards all-but-first
namespace enum storage types), which the D3 refusal trigger routes to a separate
dispatch rather than expanding scope here.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 30, 2026
…typeName)

D3a (planner-side compound key). collectPostgresEnumTypes now returns a map
keyed by the serialised compound key ${namespaceId}\u0000${typeName} instead of
bare typeName, so two namespaces declaring an enum with the same NAME produce two
distinct entries — no last-write-wins collapse. NUL is the separator (invalid in
both Postgres identifiers and TS symbol names, so unambiguous).

nativeEnumPlanCallStrategy iterates compound entries; handledKeys / introducedKeys
/ rebuiltKeys are compound-key sets. The issue-matching filter resolves the issue
to its compound key via enumCompoundKey(resolveNamespaceIdForIssue(issue),
issue.typeName), relying on the D1 substrate guarantee that enum-related issues
carry namespaceId. The introduce-and-rebuild guard error displays keys with a
readable "ns.type" rendering.

This closes the same-NAME collision (the primary CodeRabbit finding) and satisfies
SDoD6/SDoD7. The same-nativeType collision (readExistingEnumValues schema axis,
spec edge case #3) is deferred to D3b: threading (schemaName, nativeType) through
readExistingEnumValues cascades into the schema-IR provider (the introspection
merge in 6-adapters/.../control-adapter.ts explicitly discards all-but-first
namespace enum storage types), which the D3 refusal trigger routes to a separate
dispatch rather than expanding scope here.

Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request May 30, 2026
…typeName)

D3a (planner-side compound key). collectPostgresEnumTypes now returns a map
keyed by the serialised compound key ${namespaceId}\u0000${typeName} instead of
bare typeName, so two namespaces declaring an enum with the same NAME produce two
distinct entries — no last-write-wins collapse. NUL is the separator (invalid in
both Postgres identifiers and TS symbol names, so unambiguous).

nativeEnumPlanCallStrategy iterates compound entries; handledKeys / introducedKeys
/ rebuiltKeys are compound-key sets. The issue-matching filter resolves the issue
to its compound key via enumCompoundKey(resolveNamespaceIdForIssue(issue),
issue.typeName), relying on the D1 substrate guarantee that enum-related issues
carry namespaceId. The introduce-and-rebuild guard error displays keys with a
readable "ns.type" rendering.

This closes the same-NAME collision (the primary CodeRabbit finding) and satisfies
SDoD6/SDoD7. The same-nativeType collision (readExistingEnumValues schema axis,
spec edge case #3) is deferred to D3b: threading (schemaName, nativeType) through
readExistingEnumValues cascades into the schema-IR provider (the introspection
merge in 6-adapters/.../control-adapter.ts explicitly discards all-but-first
namespace enum storage types), which the D3 refusal trigger routes to a separate
dispatch rather than expanding scope here.

Signed-off-by: Will Madden <[email protected]>
wmadden-electric added a commit that referenced this pull request Jun 16, 2026
Slice spec Done condition #3 required deleting any
`planner-ddl-builders.ts` / `operations/*.ts` PG builder left with no
callers. `buildCreateTableSql` had been callerless since the
`CreateTableCall.toOp` conversion routed CREATE TABLE through the
typed `PostgresCreateTable` DDL node — only its own definition, its
barrel re-export, and its self-test survived. Delete all three:

- the function in `core/migrations/planner-ddl-builders.ts`
- its re-export from `exports/planner-ddl-builders.ts`
- its describe block (and the now-unused `StorageTable` + `buildCreateTableSql`
  imports) in `adapter-postgres/test/migrations/planner-ddl-builders.test.ts`
  — file kept (still tests `buildColumnTypeSql` / `buildColumnDefaultSql`
  / `renderDefaultLiteral`).

`git grep buildCreateTableSql` is now empty. `buildColumnTypeSql` /
`buildColumnDefaultSql` / `renderDefaultLiteral` stay (still consumed
by `issue-planner`, `planner-strategies`, the recipe, and the SQLite
target / Postgres control target).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric added a commit that referenced this pull request Jun 18, 2026
Slice spec Done condition #3 required deleting any
`planner-ddl-builders.ts` / `operations/*.ts` PG builder left with no
callers. `buildCreateTableSql` had been callerless since the
`CreateTableCall.toOp` conversion routed CREATE TABLE through the
typed `PostgresCreateTable` DDL node — only its own definition, its
barrel re-export, and its self-test survived. Delete all three:

- the function in `core/migrations/planner-ddl-builders.ts`
- its re-export from `exports/planner-ddl-builders.ts`
- its describe block (and the now-unused `StorageTable` + `buildCreateTableSql`
  imports) in `adapter-postgres/test/migrations/planner-ddl-builders.test.ts`
  — file kept (still tests `buildColumnTypeSql` / `buildColumnDefaultSql`
  / `renderDefaultLiteral`).

`git grep buildCreateTableSql` is now empty. `buildColumnTypeSql` /
`buildColumnDefaultSql` / `renderDefaultLiteral` stay (still consumed
by `issue-planner`, `planner-strategies`, the recipe, and the SQLite
target / Postgres control target).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jun 21, 2026
Slice 3 (final) of the **SQL ORM: Many-to-Many End to End** project
([Linear
project](https://linear.app/prisma-company/project/sql-orm-many-to-many-end-to-end-c178df40ca3a)).
Nested `connect`/`disconnect`/`create` through the junction + the
required-payload safety rail.

> **Stacked PR.** Base `tml-2786` (prisma#680) → `tml-2785` (prisma#679) →
`tml-2784` (prisma#678) → `tml-2597` (prisma#673) → `tml-2729` (prisma#667) → `main`.
Review/merge bottom-up.

## Overview

`db.orm.User.update/create({ tags: (t) =>
t.connect/disconnect/create(...) })` now routes to the `UserTag`
junction (INSERT / DELETE / target-insert+link), under both `create()`
and `update()`. The `N:M not supported yet` guard is gone. Junctions
with a **required non-FK payload column** cant be written through the
sugar, so `create` **and** `connect` on them are disabled at both the
type level and runtime with a clear error (disconnect stays).

## Changes

- **Runtime junction write path:** `partitionByOwnership` gains a
`junctionOwned` bucket (keyed on `through` presence); connect→INSERT,
disconnect→DELETE, create→target-insert+link, both flows, composite-key
AND-ed; the rejection unit test flipped positive.
(`getRelationDefinitions` now carries `through`.)
- **Required-payload fixture:** `User ↔ Role` via `UserRole(user_id,
role_id, level NOT NULL)` (canonical CLI emit).
- **Runtime guard:** nested `create` **and** `connect` on a
required-payload junction throw (connect also INSERTs a junction row it
cant complete → DB NOT-NULL violation). Disconnect stays allowed.
- **Type-level gate:** `HasRequiredJunctionPayload` +
`HasJunctionThrough` compose `LinkWritesDisabled` and
`BareDisconnectDisabled` on `RelationMutator`, disabling
`create`/`connect` and bare `disconnect()` at the type level for
required-payload junctions. The `.d.ts` emitter now carries `through`
(namespace-scoped), so the gate derives required-payload columns from
the junction model's field types without `any`. Covered by type tests
(`junction-link-write-disable.test-d.ts`).
- **Error handling:** `isUniqueConstraintViolation` uses
driver-normalized `SqlQueryError.sqlState`; duplicate-connect wraps with
a domain error naming the junction; shared-column conflicts detected on
both INSERT and DELETE sides; metadata-length assertions fail fast;
preflight detects duplicate resolved targets.
- **Namespace scoping:** `MutationDefaultsOptions` carries `namespace`;
`ModelNameForTable` and `JunctionPayloadFieldNames` are namespace-aware;
execution-default and storage-default columns are excluded from
`requiredPayloadColumns`.
- **Transaction safety:** ORM mutations run inside a transaction via
`withMutationScope`.

## Integration tests (per the project standard)

`mn-nested-write.test.ts` — connect/create/disconnect on the pure
`User.tags` junction and the required-payload `User.roles` junction,
both `create()` and `update()` flows; duplicate-connect rejection;
missing-target rejection; parent-insert-failure-after-connect-preflight
(no partial writes); execution-defaulted junction payload column; bare
`disconnect()` type error on junctions; whole-row `toEqual`, explicit
`.select` in most, ≥1 implicit/default selection.

## AC status

- ✅ **AC-1** — connect/disconnect/create route to junction DML, both
flows, guard removed, rejection test flipped (unit + integration).
- ✅ **AC-2** — Runtime disable of `create`+`connect` on required-payload
junctions + type-level disable (`create`/`connect` → `never`, bare
`disconnect()` → type error on junctions). Both implemented and tested.
- ✅ **AC-3** — write integration tests per the standard.

## Notes

`connect`-disabled-on-required-payload was a mid-flight spec correction
(the original spec wrongly assumed connect was FK-pair-only safe).
Duplicate `connect` errors deliberately rather than silently succeeding
(intentional divergence from Prisma-classic implicit-M:N `connect`,
which is idempotent via `ON CONFLICT DO NOTHING`). The reverse
`Tag.users`/`Role.users` directions are deferred (one-directional
fixture, decision prisma#3). Refs: TML-2787.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Enabled many-to-many nested mutations via junction tables when
junction metadata is available, including `create`, `connect`, and
`disconnect`.
* Added compile-time and runtime protections to prevent
creating/connecting junction links when the junction has required
payload fields.
* **Bug Fixes**
* Improved unique-constraint error detection for more consistent
handling (based on SQLSTATE).
* **Tests**
* Expanded unit and integration coverage for junction-based M:N nested
writes, junction payload validation, and correct junction DML behavior.
* **Chores**
* Updated generated contract and example artifacts to use
namespace-qualified execution-default references.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
wmadden-electric added a commit that referenced this pull request Jun 26, 2026
The value is the node’s own identity among its siblings; the differ
concatenating identities into a path is the differ’s concern, not the
node’s. localKey/pathSegment encoded that consumer use; id() names the
intrinsic property on the DiffableNode interface (review comment #3).

Pure rename: same signature, same behavior, all impls and tests in
lockstep. Node key composition unchanged (separate task).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric added a commit that referenced this pull request Jun 26, 2026
… caller-side whitelist

Policies now nest under a PostgresTableNode (database root → table → policy),
so a policy’s id() is just its wire name — unique among its table’s policies —
instead of folding namespace/table into the key. Same-wire-name policies on
different tables stay distinct via their table nodes.

The framework differ becomes total: an unmatched non-leaf node emits its own
issue and descends, emitting one per node in the missing/extra subtree. So an
initial migration (every table missing) still surfaces the policies beneath
the missing tables. Coalescing a parent change over its children is the
planner’s job.

Ownership and node-type selection leave the differ. diffPostgresSchema(expected,
actual) takes two built IRs, runs the total diff, whitelists policy-subject
issues (isPostgresRlsPolicy), and drops extra policies in namespaces expected
does not own. filterSchemaIssuesByOwnership is removed from framework
schema-diff.ts — the differ is pure.

namespaceId is resolved to its DDL schema name once, at derivation
(collectContractRlsPolicies), via the existing resolveDdlSchemaForNamespaceStorage,
so expected and actual table nodes pair by id(). The degraded resolveNamespaceId
duplicate is deleted.

Also completes the coordinate→path migration missed in 6bd0f25: the family-sql
filterSchemaDiffIssues test and the supabase skeleton test referenced the removed
.coordinate field (CI Test + Type Check were red on that tip).

Addresses review comments #2, #5, #6; #3 (id()) landed separately; #4 (rename the
root off "IR") deferred as its own leveling change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant