Skip to content

Commit 890d102

Browse files
wmadden-electricwmaddenclaude
authored
feat: add pragma to inferred PSL contracts (#801)
## Summary - Add `// use prisma-next` pragma to the top of inferred contract.prisma files - Makes it explicit that inferred PSL contracts should be used with the prisma-next toolchain - Updated tests to verify the pragma is present ## Test plan - [x] PSL printer tests pass (55 tests) - [x] Contract infer journey test passes with new pragma verification - [x] All integration tests pass (123 tests across 41 test files) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Generated schema/contract files now include a top-line `// use prisma-next` pragma. * **Tests** * Updated snapshots and end-to-end assertions to expect the new pragma in printed outputs. * Test harness configs simplified by removing a legacy test-workaround setting. * **Chores** * Workspace package pin bumped and release-exclusion rules added. * **Documentation** * Note added clarifying the removal of the temporary test-workaround. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Will Madden <madden@prisma.io> Co-authored-by: Will Madden <madden@prisma.io> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 50f628b commit 890d102

10 files changed

Lines changed: 74 additions & 37 deletions

File tree

packages/1-framework/2-authoring/psl-printer/src/ast-to-print-document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type { PrinterEnum, PrinterField, PrinterModel, PrinterNamedType } from '
2323
// `contract emit` to produce the canonical artifacts. The header invites that
2424
// workflow rather than warning against it.
2525
const DEFAULT_AST_PRINT_HEADER =
26-
'// Contract inferred from the live database schema. Edit as needed, then run `prisma-next contract emit`.';
26+
'// use prisma-next\n// Contract inferred from the live database schema. Edit as needed, then run `prisma-next contract emit`.';
2727

2828
export function astDocumentToPrintDocument(ast: PslDocumentAst): PrintDocument {
2929
// FK dependencies are resolved across the whole document — a model in one

packages/1-framework/2-authoring/psl-printer/test/print-psl-from-ast.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ describe('printPslFromAst', () => {
736736
});
737737

738738
it('parser → printer → parser round-trip for a small schema', () => {
739-
const source = `// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
739+
const source = `// use prisma-next
740+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
740741
741742
model User {
742743
id Int @id
@@ -973,7 +974,8 @@ namespace auth {
973974
it('parser → printer → parser round-trip for a cross-space colon-prefix field', () => {
974975
// AC2: a field authored as `supabase:auth.User` must survive a full
975976
// text→parse→print→text round-trip with the colon-prefix intact.
976-
const source = `// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
977+
const source = `// use prisma-next
978+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
977979
978980
model Profile {
979981
id Int @id

packages/2-sql/9-family/test/psl-contract-infer/print-psl/print-psl.core.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ describe('printPsl', () => {
1414
};
1515
const result = printPslFromSql(schemaIR);
1616
expect(result).toMatchInlineSnapshot(`
17-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
17+
"// use prisma-next
18+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
1819
"
1920
`);
2021
});
@@ -38,7 +39,8 @@ describe('printPsl', () => {
3839
};
3940
const result = printPslFromSql(schemaIR);
4041
expect(result).toMatchInlineSnapshot(`
41-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
42+
"// use prisma-next
43+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
4244
4345
model User {
4446
id Int @id
@@ -72,7 +74,8 @@ describe('printPsl', () => {
7274
};
7375
const result = printPslFromSql(schemaIR);
7476
expect(result).toMatchInlineSnapshot(`
75-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
77+
"// use prisma-next
78+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
7679
7780
// WARNING: This table has no primary key in the database
7881
model AuditLog {
@@ -108,7 +111,8 @@ describe('printPsl', () => {
108111
};
109112
const result = printPslFromSql(schemaIR);
110113
expect(result).toMatchInlineSnapshot(`
111-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
114+
"// use prisma-next
115+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
112116
113117
model OrderItem {
114118
orderId Int @map("order_id")

packages/2-sql/9-family/test/psl-contract-infer/print-psl/print-psl.defaults-and-types.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ describe('printPsl', () => {
5454
};
5555
const result = printPslFromSql(schemaIR);
5656
expect(result).toMatchInlineSnapshot(`
57-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
57+
"// use prisma-next
58+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
5859
5960
model Post {
6061
id Int @id @default(autoincrement())
@@ -96,7 +97,8 @@ describe('printPsl', () => {
9697
};
9798
const result = printPslFromSql(schemaIR);
9899
expect(result).toMatchInlineSnapshot(`
99-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
100+
"// use prisma-next
101+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
100102
101103
types {
102104
Email = String @db.VarChar(255)
@@ -151,7 +153,8 @@ describe('printPsl', () => {
151153
};
152154
const result = printPslFromSql(schemaIR);
153155
expect(result).toMatchInlineSnapshot(`
154-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
156+
"// use prisma-next
157+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
155158
156159
types {
157160
Value = Decimal @db.Numeric(10, 2)
@@ -213,7 +216,8 @@ describe('printPsl', () => {
213216

214217
const result = printPslFromSql(schemaIR);
215218
expect(result).toMatchInlineSnapshot(`
216-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
219+
"// use prisma-next
220+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
217221
218222
types {
219223
Email = String @db.VarChar(255)
@@ -287,7 +291,8 @@ describe('printPsl', () => {
287291

288292
const result = printPslFromSql(schemaIR);
289293
expect(result).toMatchInlineSnapshot(`
290-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
294+
"// use prisma-next
295+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
291296
292297
types {
293298
Role2 = String @db.VarChar(32)
@@ -342,7 +347,8 @@ describe('printPsl', () => {
342347
};
343348
const result = printPslFromSql(schemaIR);
344349
expect(result).toMatchInlineSnapshot(`
345-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
350+
"// use prisma-next
351+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
346352
347353
model GeoData {
348354
id Int @id
@@ -377,7 +383,8 @@ describe('printPsl', () => {
377383
};
378384
const result = printPslFromSql(schemaIR);
379385
expect(result).toMatchInlineSnapshot(`
380-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
386+
"// use prisma-next
387+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
381388
382389
types {
383390
Id = String @db.Uuid
@@ -430,7 +437,8 @@ describe('printPsl', () => {
430437

431438
const result = printPslFromSql(schemaIR);
432439
expect(result).toMatchInlineSnapshot(`
433-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
440+
"// use prisma-next
441+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
434442
435443
types {
436444
BookedOn = DateTime @db.Date
@@ -488,7 +496,8 @@ describe('printPsl', () => {
488496
};
489497
const result = printPslFromSql(schemaIR);
490498
expect(result).toMatchInlineSnapshot(`
491-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
499+
"// use prisma-next
500+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
492501
493502
model Data {
494503
id Int @id
@@ -524,7 +533,8 @@ describe('printPsl', () => {
524533
};
525534
const result = printPslFromSql(schemaIR);
526535
expect(result).toMatchInlineSnapshot(`
527-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
536+
"// use prisma-next
537+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
528538
529539
model Counter {
530540
id BigInt @id @default(9223372036854776000)

packages/2-sql/9-family/test/psl-contract-infer/print-psl/print-psl.enums.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('printPsl', () => {
3939
};
4040
const result = printPslFromSql(schemaIR);
4141
expect(result).toMatchInlineSnapshot(`
42-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
42+
"// use prisma-next
43+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
4344
4445
enum UserRole {
4546
USER
@@ -103,7 +104,8 @@ describe('printPsl', () => {
103104
// `'in-progress'`). `READY` is already a valid PSL identifier and
104105
// matches its storage label, so no `@map` is needed there.
105106
expect(result).toMatchInlineSnapshot(`
106-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
107+
"// use prisma-next
108+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
107109
108110
enum DeploymentStatus {
109111
READY
@@ -161,7 +163,8 @@ describe('printPsl', () => {
161163
// `value` and so carries a per-member `@map("!!!")` to preserve the
162164
// original storage label across the parse-print round-trip.
163165
expect(result).toMatchInlineSnapshot(`
164-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
166+
"// use prisma-next
167+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
165168
166169
enum Role {
167170
value @map("!!!")

packages/2-sql/9-family/test/psl-contract-infer/print-psl/print-psl.naming-and-constraints.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ describe('printPsl', () => {
4646
};
4747
const result = printPslFromSql(schemaIR);
4848
expect(result).toMatchInlineSnapshot(`
49-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
49+
"// use prisma-next
50+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
5051
5152
model Account {
5253
id Int @id
@@ -113,7 +114,8 @@ describe('printPsl', () => {
113114
};
114115
const result = printPslFromSql(schemaIR);
115116
expect(result).toMatchInlineSnapshot(`
116-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
117+
"// use prisma-next
118+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
117119
118120
model Account {
119121
userId2 Int @id @map("user_id")
@@ -166,7 +168,8 @@ describe('printPsl', () => {
166168
};
167169
const result = printPslFromSql(schemaIR);
168170
expect(result).toMatchInlineSnapshot(`
169-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
171+
"// use prisma-next
172+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
170173
171174
model Account {
172175
id Int @id
@@ -200,7 +203,8 @@ describe('printPsl', () => {
200203
};
201204
const result = printPslFromSql(schemaIR);
202205
expect(result).toMatchInlineSnapshot(`
203-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
206+
"// use prisma-next
207+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
204208
205209
model Record {
206210
id Int @id
@@ -237,7 +241,8 @@ describe('printPsl', () => {
237241
};
238242
const result = printPslFromSql(schemaIR);
239243
expect(result).toMatchInlineSnapshot(`
240-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
244+
"// use prisma-next
245+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
241246
242247
model Record {
243248
id Int @id
@@ -274,7 +279,8 @@ describe('printPsl', () => {
274279
};
275280
const result = printPslFromSql(schemaIR);
276281
expect(result).toMatchInlineSnapshot(`
277-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
282+
"// use prisma-next
283+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
278284
279285
model Record {
280286
id Int @id(map: "record_pkey")
@@ -307,7 +313,8 @@ describe('printPsl', () => {
307313
};
308314
const result = printPslFromSql(schemaIR);
309315
expect(result).toMatchInlineSnapshot(`
310-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
316+
"// use prisma-next
317+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
311318
312319
model _Type {
313320
id Int @id

packages/2-sql/9-family/test/psl-contract-infer/print-psl/print-psl.relations.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ describe('printPsl', () => {
4444
};
4545
const result = printPslFromSql(schemaIR);
4646
expect(result).toMatchInlineSnapshot(`
47-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
47+
"// use prisma-next
48+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
4849
4950
model User {
5051
id Int @id
@@ -102,7 +103,8 @@ describe('printPsl', () => {
102103
};
103104
const result = printPslFromSql(schemaIR);
104105
expect(result).toMatchInlineSnapshot(`
105-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
106+
"// use prisma-next
107+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
106108
107109
model User {
108110
id Int @id
@@ -171,7 +173,8 @@ describe('printPsl', () => {
171173
};
172174
const result = printPslFromSql(schemaIR);
173175
expect(result).toMatchInlineSnapshot(`
174-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
176+
"// use prisma-next
177+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
175178
176179
model Account {
177180
tenantId Int @map("tenant_id")
@@ -224,7 +227,8 @@ describe('printPsl', () => {
224227
};
225228
const result = printPslFromSql(schemaIR);
226229
expect(result).toMatchInlineSnapshot(`
227-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
230+
"// use prisma-next
231+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
228232
229233
model Employee {
230234
id Int @id
@@ -289,7 +293,8 @@ describe('printPsl', () => {
289293
};
290294
const result = printPslFromSql(schemaIR);
291295
expect(result).toMatchInlineSnapshot(`
292-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
296+
"// use prisma-next
297+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
293298
294299
model User {
295300
id Int @id
@@ -364,7 +369,8 @@ describe('printPsl', () => {
364369
};
365370
const result = printPslFromSql(schemaIR);
366371
expect(result).toMatchInlineSnapshot(`
367-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
372+
"// use prisma-next
373+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
368374
369375
model Product {
370376
categoryId Int @map("category_id")
@@ -427,7 +433,8 @@ describe('printPsl', () => {
427433
};
428434
const result = printPslFromSql(schemaIR);
429435
expect(result).toMatchInlineSnapshot(`
430-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
436+
"// use prisma-next
437+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
431438
432439
model Parent {
433440
id Int @id
@@ -483,7 +490,8 @@ describe('printPsl', () => {
483490

484491
const result = printPslFromSql(schemaIR);
485492
expect(result).toMatchInlineSnapshot(`
486-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
493+
"// use prisma-next
494+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
487495
488496
model Team {
489497
id Int @id

packages/2-sql/9-family/test/psl-contract-infer/sql-schema-ir-to-psl-ast.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ describe('sqlSchemaIrToPslAst', () => {
267267

268268
const out = printPsl(sqlSchemaIrToPslAst(schemaIR));
269269
expect(out).toMatchInlineSnapshot(`
270-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
270+
"// use prisma-next
271+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
271272
272273
model User {
273274
id Int @id

test/integration/test/__snapshots__/cli.db-introspect.e2e.test.ts.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`live schema CLI commands (e2e) > contract infer > writes a full PSL snapshot to output/contract.prisma 1`] = `
4-
"// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
4+
"// use prisma-next
5+
// Contract inferred from the live database schema. Edit as needed, then run \`prisma-next contract emit\`.
56
67
model User {
78
id Int @id(map: "user_pkey") @default(autoincrement())

test/integration/test/cli-journeys/contract-infer-workflow.e2e.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ withTempDir(({ createTempDir }) => {
5555
'Contract written to contract.prisma',
5656
);
5757
const inferredPsl = readFileSync(join(ctx.testDir, 'contract.prisma'), 'utf-8');
58+
expect(inferredPsl, 'AB.01: inferred psl includes pragma').toContain('// use prisma-next');
5859
expect(inferredPsl, 'AB.01: infer removes stale field').not.toContain('name');
5960
expect(inferredPsl, 'AB.01: infer keeps live field').toContain('email String');
6061

0 commit comments

Comments
 (0)