Skip to content

Commit 3a71c13

Browse files
committed
feat(mongo-family)!: from/to relation syntax; reject legacy fields/references
S1a/S1b taught the SQL PSL resolver to accept only @relation(from:, to:). The Mongo family has its own PSL relation parser (contract-psl/psl-helpers.ts, parseRelationAttribute) that read only fields:/references: and ignored from:/to:, so Mongo schemas were left on the legacy vocabulary. Mirror the SQL change in the Mongo interpreter: - parseRelationAttribute now reads from:/to:, rejects fields:/references: with the PSL_LEGACY_FIELDS_REFERENCES diagnostic (the same open-string code SQL uses), and supports bare or bracketed values. Omitting to: infers the referenced column(s) from the target model's @id (resolveTargetIdFieldNames); a to: without a from: is rejected. The interpreter caller resolves the inferred references against the target model and routes legacy/invalid relations away from backrelation handling. - Migrate every Mongo-family authored schema, migration snapshot, inline-PSL test, and the Mongo CLI init template from fields:/references: to from:/to:. from/to lowers byte-identically to fields/references, so only .prisma source spelling changes — no contract.json, migration metadata, or hash drift (verified: migrations:regen:examples re-parses the migrated Mongo snapshots and re-emits the start/end contracts with zero artifact diff). @relation(name:) is untouched. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 0e0b163 commit 3a71c13

15 files changed

Lines changed: 395 additions & 71 deletions

File tree

examples/mongo-blog-leaderboard/src/contract.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ model Post {
2222
kind String
2323
authorId ObjectId
2424
createdAt DateTime
25-
author User @relation(fields: [authorId], references: [id])
25+
author User @relation(from: [authorId], to: [id])
2626
2727
@@discriminator(kind)
2828
@@index([authorId])

examples/mongo-demo/migrations/app/20260409T1030_migration/contract.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ model Post {
2424
kind String
2525
authorId ObjectId
2626
createdAt DateTime
27-
author User @relation(fields: [authorId], references: [id])
27+
author User @relation(from: [authorId], to: [id])
2828
@@discriminator(kind)
2929
@@map("posts")
3030
}

examples/mongo-demo/migrations/app/20260626T1605_add_user_role_enum/contract.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ model Post {
3232
kind String
3333
authorId ObjectId
3434
createdAt DateTime
35-
author User @relation(fields: [authorId], references: [id])
35+
author User @relation(from: [authorId], to: [id])
3636
@@discriminator(kind)
3737
@@map("posts")
3838
}

examples/mongo-demo/src/contract.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ model Post {
3232
kind String
3333
authorId ObjectId
3434
createdAt DateTime
35-
author User @relation(fields: [authorId], references: [id])
35+
author User @relation(from: [authorId], to: [id])
3636
@@discriminator(kind)
3737
@@index([authorId])
3838
@@index([createdAt(sort: Desc), authorId])

examples/retail-store/migrations/app/20260513T0505_initial/contract.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ model Cart {
7777
id ObjectId @id @map("_id")
7878
userId ObjectId
7979
items CartItem[]
80-
user User @relation(fields: [userId], references: [id])
80+
user User @relation(from: [userId], to: [id])
8181
@@map("carts")
8282
@@unique([userId])
8383
}
@@ -89,7 +89,7 @@ model Order {
8989
shippingAddress String
9090
type String
9191
statusHistory StatusEntry[]
92-
user User @relation(fields: [userId], references: [id])
92+
user User @relation(from: [userId], to: [id])
9393
invoices Invoice[]
9494
@@map("orders")
9595
@@index([userId])
@@ -114,7 +114,7 @@ model Invoice {
114114
tax Float
115115
total Float
116116
issuedAt DateTime
117-
order Order @relation(fields: [orderId], references: [id])
117+
order Order @relation(from: [orderId], to: [id])
118118
@@map("invoices")
119119
@@index([orderId])
120120
@@index([issuedAt(sort: Desc)], sparse: true)

examples/retail-store/migrations/app/20260513T0507_add_product_category_index/contract.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ model Cart {
7878
id ObjectId @id @map("_id")
7979
userId ObjectId
8080
items CartItem[]
81-
user User @relation(fields: [userId], references: [id])
81+
user User @relation(from: [userId], to: [id])
8282
@@map("carts")
8383
@@unique([userId])
8484
}
@@ -90,7 +90,7 @@ model Order {
9090
shippingAddress String
9191
type String
9292
statusHistory StatusEntry[]
93-
user User @relation(fields: [userId], references: [id])
93+
user User @relation(from: [userId], to: [id])
9494
invoices Invoice[]
9595
@@map("orders")
9696
@@index([userId])
@@ -115,7 +115,7 @@ model Invoice {
115115
tax Float
116116
total Float
117117
issuedAt DateTime
118-
order Order @relation(fields: [orderId], references: [id])
118+
order Order @relation(from: [orderId], to: [id])
119119
@@map("invoices")
120120
@@index([orderId])
121121
@@index([issuedAt(sort: Desc)], sparse: true)

examples/retail-store/migrations/app/20260513T0508_backfill_product_status/contract.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ model Cart {
8080
id ObjectId @id @map("_id")
8181
userId ObjectId
8282
items CartItem[]
83-
user User @relation(fields: [userId], references: [id])
83+
user User @relation(from: [userId], to: [id])
8484
@@map("carts")
8585
@@unique([userId])
8686
}
@@ -92,7 +92,7 @@ model Order {
9292
shippingAddress String
9393
type String
9494
statusHistory StatusEntry[]
95-
user User @relation(fields: [userId], references: [id])
95+
user User @relation(from: [userId], to: [id])
9696
invoices Invoice[]
9797
@@map("orders")
9898
@@index([userId])
@@ -117,7 +117,7 @@ model Invoice {
117117
tax Float
118118
total Float
119119
issuedAt DateTime
120-
order Order @relation(fields: [orderId], references: [id])
120+
order Order @relation(from: [orderId], to: [id])
121121
@@map("invoices")
122122
@@index([orderId])
123123
@@index([issuedAt(sort: Desc)], sparse: true)

examples/retail-store/src/contract.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ model Cart {
9393
id ObjectId @id @map("_id")
9494
userId ObjectId
9595
items CartItem[]
96-
user User @relation(fields: [userId], references: [id])
96+
user User @relation(from: [userId], to: [id])
9797
@@map("carts")
9898
@@unique([userId])
9999
}
@@ -105,7 +105,7 @@ model Order {
105105
shippingAddress String
106106
type OrderType
107107
statusHistory StatusEntry[]
108-
user User @relation(fields: [userId], references: [id])
108+
user User @relation(from: [userId], to: [id])
109109
invoices Invoice[]
110110
@@map("orders")
111111
@@index([userId])
@@ -130,7 +130,7 @@ model Invoice {
130130
tax Float
131131
total Float
132132
issuedAt DateTime
133-
order Order @relation(fields: [orderId], references: [id])
133+
order Order @relation(from: [orderId], to: [id])
134134
@@map("invoices")
135135
@@index([orderId])
136136
@@index([issuedAt(sort: Desc)], sparse: true)

packages/1-framework/3-tooling/cli/src/commands/init/templates/code-templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ model Post {
150150
id ObjectId @id @map("_id")
151151
title String
152152
content String?
153-
author User @relation(fields: [authorId], references: [id])
153+
author User @relation(from: [authorId], to: [id])
154154
authorId ObjectId
155155
@@map("posts")
156156
}

packages/1-framework/3-tooling/cli/test/commands/init/__snapshots__/templates.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ model Post {
247247
id ObjectId @id @map("_id")
248248
title String
249249
content String?
250-
author User @relation(fields: [authorId], references: [id])
250+
author User @relation(from: [authorId], to: [id])
251251
authorId ObjectId
252252
@@map("posts")
253253
}

0 commit comments

Comments
 (0)