Skip to content

Commit 1c404f0

Browse files
committed
test(sql-orm-client): migration DDL + ORM include for implicit M:N
S4·M1 synthesises a model-less junction for an implicit many-to-many (both navigable list ends bare, no junction model). This proves that junction downstream: the migration system creates it, and the ORM `include` walks it. The `mn-psl-implicit` fixture authors `Post.tags Tag[]` / `Tag.posts Post[]` with no junction model, emitted via the real pipeline for both postgres and sqlite. The interpreter synthesises `_PostToTag` (composite PK `(A, B)`, FK `A` → `posts.id`, FK `B` → `tags.id`) and lowers both ends to `cardinality: 'N:M'` + `through` over it. Migration DDL: the synthesised junction is a normal contract storage table, so the migration planner creates it with no special-casing. A migration test drives the real planner over each emitted contract against an empty schema and asserts the `_PostToTag` `CREATE TABLE` (composite primary key + the two foreign keys) is planned for postgres and sqlite. Integration: an `include('tags')` test over the implicit M:N returns the related rows (whole-row assertions, explicit + implicit select, PGlite), walking the synthesised junction through a real emitted PSL contract with no authored junction model. Wires both emissions into the sql-orm-client emit script (so `fixtures:check` regenerates them) and adds `@prisma-next/sqlite` to the integration test package to emit the sqlite contract. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent c4cf006 commit 1c404f0

12 files changed

Lines changed: 1633 additions & 1 deletion

File tree

packages/3-extensions/sql-orm-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": "ORM client for Prisma Next — fluent, type-safe model collections",
88
"scripts": {
99
"build": "tsdown",
10-
"emit": "cd ../../../test/integration && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/polymorphism/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/junction-namespaces/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/execution-defaulted-tags/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/disambiguated-1n-inverse/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/self-ref-mn-through/prisma-next.config.ts && cp test/sql-orm-client/fixtures/generated/contract.json test/sql-orm-client/fixtures/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/generated/ && cp test/sql-orm-client/fixtures/junction-namespaces/generated/contract.json test/sql-orm-client/fixtures/junction-namespaces/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/junction-namespaces/generated/ && cd ../../packages/3-extensions/sql-orm-client && node scripts/strip-pgvector-fixture.mjs test/fixtures/generated/contract.d.ts",
10+
"emit": "cd ../../../test/integration && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/polymorphism/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/junction-namespaces/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/execution-defaulted-tags/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/disambiguated-1n-inverse/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/self-ref-mn-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-implicit/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-implicit/prisma-next.config.sqlite.ts && cp test/sql-orm-client/fixtures/generated/contract.json test/sql-orm-client/fixtures/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/generated/ && cp test/sql-orm-client/fixtures/junction-namespaces/generated/contract.json test/sql-orm-client/fixtures/junction-namespaces/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/junction-namespaces/generated/ && cd ../../packages/3-extensions/sql-orm-client && node scripts/strip-pgvector-fixture.mjs test/fixtures/generated/contract.d.ts",
1111
"emit:check": "pnpm emit && git diff --exit-code test/fixtures/generated/ test/fixtures/junction-namespaces/generated/",
1212
"test": "vitest run",
1313
"test:coverage": "vitest run --coverage",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@prisma-next/sql-relational-core": "workspace:0.14.0",
4545
"@prisma-next/sql-runtime": "workspace:0.14.0",
4646
"@prisma-next/sql-schema-ir": "workspace:0.14.0",
47+
"@prisma-next/sqlite": "workspace:0.14.0",
4748
"@prisma-next/target-postgres": "workspace:0.14.0",
4849
"@prisma-next/adapter-mongo": "workspace:0.14.0",
4950
"@prisma-next/adapter-sqlite": "workspace:0.14.0",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Real emitted fixture for the sql-orm-client implicit many-to-many parity
2+
// test — the `Post ↔ Tag` relation authored as two bare navigable list ends
3+
// with NO junction model.
4+
//
5+
// `Post.tags Tag[]` / `Tag.posts Post[]` are both bare (no `@relation(through:)`)
6+
// and no model links the pair, so the interpreter synthesises a model-less
7+
// junction table — Prisma's implicit many-to-many. The synthesised junction is
8+
// named `_PostToTag` (the two terminal model names ordered alphabetically) with
9+
// foreign-key columns `A` (→ `posts.id`) and `B` (→ `tags.id`) and a composite
10+
// `(A, B)` identity. Both list ends lower to a navigable `cardinality: 'N:M'`
11+
// relation with a populated `through` descriptor over `_PostToTag` — the same
12+
// runtime-consumable shape an authored junction emits — so the M:N ORM
13+
// `include` drives through a real emitted PSL contract with no authored
14+
// junction model.
15+
//
16+
// The synthesised junction is a physical table only (filtered out of `roots`),
17+
// so the migration system creates it like any contract storage table.
18+
19+
model Post {
20+
id Int @id
21+
title String
22+
23+
tags Tag[]
24+
25+
@@map("posts")
26+
}
27+
28+
model Tag {
29+
id String @id
30+
label String @unique
31+
32+
posts Post[]
33+
34+
@@map("tags")
35+
}

test/integration/test/sql-orm-client/fixtures/mn-psl-implicit/generated-sqlite/contract.d.ts

Lines changed: 303 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)