@prisma/orm-mongo 8.0.1-dev.42 → 8.0.1-dev.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{mongo-static-DXv-zWOu-FTCkjjZe.mjs → mongo-static-Dudm8H_X-DUUqqcta.mjs} +3 -3
- package/dist/{mongo-static-DXv-zWOu-FTCkjjZe.mjs.map → mongo-static-Dudm8H_X-DUUqqcta.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +12 -12
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/contract.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +129 -36
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +86 -9
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +110 -18
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +28 -6
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +70 -13
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +98 -13
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +100 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +29 -15
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +86 -9
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +110 -18
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +28 -6
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +70 -13
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +98 -13
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +56 -0
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Usage: node stored-files-format-version.ts [project-root]
|
|
6
6
|
*
|
|
7
|
-
* The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build
|
|
7
|
+
* The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot and, in a git repository, the files and folders git ignores, unless git ignores the project root itself. It walks a migrations folder (one holding the contract snapshot store, a migration package or a ref file, directly or in a space folder) and what is in it even when git ignores them, since nothing else writes those files again. It recognises a contract by its content (`targetFamily`, `storage` and `schemaVersion` at the top level) in any `*.json` file, a `migration.json` by its fields and by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content. Every `*.json` file in `<migrations>/<space>/refs/` (in an application) or `<migrations>/refs/` (in an extension's own repository) is a ref, where a migrations directory is one holding the contract snapshot store (`snapshots/<hash>/contract.json`) or a migration package, whatever it is named. A `*.json` file in any other `refs` directory is a ref when its content is one: a `hash` that is `empty` or a storage hash, and an `invariants` list of strings. This finds the refs of a space with no migrations after `snapshots/` was deleted. Any other JSON file in a `refs` directory is not Prisma's and is left alone. It edits each file's text in place, so the rest of the file keeps its bytes: the version goes first, except in a contract whose top-level keys are sorted (a snapshot), where it goes in sorted position, as Prisma writes them. No hash covers the version, so no hash changes.
|
|
8
8
|
*
|
|
9
9
|
* A ref file may have fields the format does not have; earlier releases ignored them when they read a ref and dropped them when they wrote one again. The script drops them too, and lists each one it dropped.
|
|
10
10
|
*
|
|
11
|
-
* It
|
|
11
|
+
* It checks every file before it writes any. If it finds any of these, it changes no file, lists them and exits 1: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file or `migration.json` whose content is not one that a release of Prisma read (a missing or extra field, or a value of the wrong type); a contract with both `formatVersion` and `schemaVersion`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`; a stored file whose `formatVersion` is not `1`; a directory it cannot list; and a symbolic link, to a file or folder outside the project root or inside it where the walk skips, that holds a stored file it would change or report, or a link inside the root to a place the walk reads as another kind of file than at the link, since it does not follow links. Otherwise it prints each file it changed, and a second run changes nothing.
|
|
12
12
|
*/
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
13
14
|
import {
|
|
14
15
|
chmodSync,
|
|
15
16
|
type Dirent,
|
|
@@ -458,6 +459,79 @@ function isWalked(name: string): boolean {
|
|
|
458
459
|
return !SKIPPED_DIRECTORIES.has(name) && !name.startsWith('.');
|
|
459
460
|
}
|
|
460
461
|
|
|
462
|
+
let ignoredByGit: (path: string) => boolean = () => false;
|
|
463
|
+
|
|
464
|
+
/** A test of whether git ignores a file or folder under `root`. Outside a git repository it ignores nothing, and so it does when git ignores `root` itself, which the user then named on purpose. */
|
|
465
|
+
function gitIgnores(root: string): (path: string) => boolean {
|
|
466
|
+
const listed = spawnSync(
|
|
467
|
+
'git',
|
|
468
|
+
['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'],
|
|
469
|
+
{ cwd: root, encoding: 'utf8', maxBuffer: 2 ** 30 },
|
|
470
|
+
);
|
|
471
|
+
if (listed.status !== 0) return () => false;
|
|
472
|
+
const ignored = new Set(
|
|
473
|
+
listed.stdout
|
|
474
|
+
.split('\0')
|
|
475
|
+
.filter((path) => path !== '')
|
|
476
|
+
.map((path) => path.replace(/\/$/, '')),
|
|
477
|
+
);
|
|
478
|
+
if (ignored.has('.')) return () => false;
|
|
479
|
+
const bases = [root, realpathSync(root)];
|
|
480
|
+
return (path) =>
|
|
481
|
+
bases.some((base) => ignored.has(relative(base, path).split(sep).join('/'))) &&
|
|
482
|
+
!isInMigrationsFolder(bases, path);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function readsAsRef(path: string): boolean {
|
|
486
|
+
try {
|
|
487
|
+
const value: unknown = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/, ''));
|
|
488
|
+
return isRecord(value) && hasRefContent(value);
|
|
489
|
+
} catch {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** Whether `dir` holds what Prisma writes to a migrations directory or to one of its spaces: the contract snapshot store, a migration package or a ref file. */
|
|
495
|
+
function holdsMigrationFiles(dir: string): boolean {
|
|
496
|
+
return isMigrationsDirectory(dir) || holdsRef(dir);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function holdsRef(dir: string): boolean {
|
|
500
|
+
const refs = join(dir, 'refs');
|
|
501
|
+
const entries = listDirectory(refs);
|
|
502
|
+
return (
|
|
503
|
+
typeof entries !== 'string' &&
|
|
504
|
+
entries.some((entry) => entry.isFile() && readsAsRef(join(refs, entry.name)))
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Whether `dir` holds what Prisma writes to a space of a migrations directory: a migration package or a ref file. The snapshot store sits beside the spaces, never in one. */
|
|
509
|
+
function holdsSpaceFiles(dir: string): boolean {
|
|
510
|
+
return hasSubdirectory(dir, isMigrationPackage) || holdsRef(dir);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function isMigrationsFolder(dir: string): boolean {
|
|
514
|
+
return (
|
|
515
|
+
holdsMigrationFiles(dir) ||
|
|
516
|
+
hasSubdirectory(dir, (path, name) => SPACE_ID.test(name) && holdsSpaceFiles(path))
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** Whether `path`, or a folder it is in below the project root, is a migrations folder, whose files the script upgrades even when git ignores them: nothing else writes them again. */
|
|
521
|
+
function isInMigrationsFolder(bases: readonly string[], path: string): boolean {
|
|
522
|
+
for (let dir = path; !bases.includes(dir) && dir !== dirname(dir); dir = dirname(dir))
|
|
523
|
+
if (isDirectory(dir) && isMigrationsFolder(dir)) return true;
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** Whether the walk from `realRoot` reaches `target`. */
|
|
528
|
+
function isReached(realRoot: string, target: string): boolean {
|
|
529
|
+
const names = relative(realRoot, target).split(sep);
|
|
530
|
+
return names.every(
|
|
531
|
+
(name, index) => isWalked(name) && !ignoredByGit(join(realRoot, ...names.slice(0, index + 1))),
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
|
|
461
535
|
function isInside(dir: string, path: string): boolean {
|
|
462
536
|
return path === dir || path.startsWith(`${dir}${sep}`);
|
|
463
537
|
}
|
|
@@ -476,8 +550,7 @@ function handleLink(root: string, path: string, name: string, outcome: Outcome):
|
|
|
476
550
|
if (isInside(target, realRoot)) return;
|
|
477
551
|
const inside = isInside(realRoot, target);
|
|
478
552
|
const reached =
|
|
479
|
-
|
|
480
|
-
(statSync(target).isDirectory() || target.endsWith('.json'));
|
|
553
|
+
isReached(realRoot, target) && (statSync(target).isDirectory() || target.endsWith('.json'));
|
|
481
554
|
const shown = relative(root, path);
|
|
482
555
|
const targetShown = relative(realRoot, target);
|
|
483
556
|
if (inside && reached) {
|
|
@@ -491,7 +564,7 @@ function handleLink(root: string, path: string, name: string, outcome: Outcome):
|
|
|
491
564
|
const isDirectory = statSync(target).isDirectory();
|
|
492
565
|
if (isDirectory) {
|
|
493
566
|
if (!isWalked(name)) return;
|
|
494
|
-
visit(root, path, probe,
|
|
567
|
+
visit(root, path, probe, 'probe');
|
|
495
568
|
} else if (name.endsWith('.json')) {
|
|
496
569
|
handleFile(root, path, probe, false);
|
|
497
570
|
}
|
|
@@ -517,8 +590,8 @@ function readsAlike(
|
|
|
517
590
|
const atTarget = emptyOutcome();
|
|
518
591
|
if (statSync(target).isDirectory()) {
|
|
519
592
|
if (!isWalked(name)) return true;
|
|
520
|
-
visit(root, path, atLink,
|
|
521
|
-
visit(realRoot, target, atTarget,
|
|
593
|
+
visit(root, path, atLink, 'probe');
|
|
594
|
+
visit(realRoot, target, atTarget, 'probe');
|
|
522
595
|
} else if (name.endsWith('.json')) {
|
|
523
596
|
handleFile(root, path, atLink, false);
|
|
524
597
|
handleFile(realRoot, target, atTarget, false);
|
|
@@ -530,8 +603,10 @@ function readsAlike(
|
|
|
530
603
|
return JSON.stringify(seen(atLink, linkShown)) === JSON.stringify(seen(atTarget, targetShown));
|
|
531
604
|
}
|
|
532
605
|
|
|
533
|
-
/**
|
|
534
|
-
|
|
606
|
+
/** How a walk handles what it finds: `write` rewrites stored files and reports links; `check` only records what `write` would do; `probe` records it too, but does not look at links, which a walk started from a link would otherwise follow in a loop. */
|
|
607
|
+
type Walk = 'write' | 'check' | 'probe';
|
|
608
|
+
|
|
609
|
+
function visit(root: string, dir: string, outcome: Outcome, walk: Walk): void {
|
|
535
610
|
const entries = listDirectory(dir);
|
|
536
611
|
if (typeof entries === 'string') {
|
|
537
612
|
outcome.problems.push(`${relative(root, dir) || '.'}: directory cannot be read (${entries})`);
|
|
@@ -539,11 +614,12 @@ function visit(root: string, dir: string, outcome: Outcome, write = true): void
|
|
|
539
614
|
}
|
|
540
615
|
for (const entry of entries) {
|
|
541
616
|
const path = join(dir, entry.name);
|
|
617
|
+
if (ignoredByGit(path)) continue;
|
|
542
618
|
if (entry.isDirectory()) {
|
|
543
|
-
if (isWalked(entry.name)) visit(root, path, outcome,
|
|
619
|
+
if (isWalked(entry.name)) visit(root, path, outcome, walk);
|
|
544
620
|
} else if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
545
|
-
handleFile(root, path, outcome, write);
|
|
546
|
-
} else if (entry.isSymbolicLink() &&
|
|
621
|
+
handleFile(root, path, outcome, walk === 'write');
|
|
622
|
+
} else if (entry.isSymbolicLink() && walk !== 'probe') {
|
|
547
623
|
handleLink(root, path, entry.name, outcome);
|
|
548
624
|
}
|
|
549
625
|
}
|
|
@@ -559,8 +635,17 @@ function main(args: readonly string[]): number {
|
|
|
559
635
|
process.stderr.write(`${root}: not a directory\n`);
|
|
560
636
|
return 1;
|
|
561
637
|
}
|
|
638
|
+
ignoredByGit = gitIgnores(root);
|
|
639
|
+
const check = emptyOutcome();
|
|
640
|
+
visit(root, root, check, 'check');
|
|
641
|
+
if (check.problems.length > 0) {
|
|
642
|
+
process.stderr.write(
|
|
643
|
+
`Changed no file, because:\n${check.problems.map((problem) => ` ${problem}\n`).join('')}`,
|
|
644
|
+
);
|
|
645
|
+
return 1;
|
|
646
|
+
}
|
|
562
647
|
const outcome = emptyOutcome();
|
|
563
|
-
visit(root, root, outcome);
|
|
648
|
+
visit(root, root, outcome, 'write');
|
|
564
649
|
if (outcome.changed.length > 0) {
|
|
565
650
|
const files = outcome.changed.length === 1 ? 'file' : 'files';
|
|
566
651
|
process.stdout.write(
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
from: "8.0.0-rc.26"
|
|
3
|
+
to: "8.0.0-rc.27"
|
|
4
|
+
changes:
|
|
5
|
+
- id: app-snapshot-gets-emitted-profile
|
|
6
|
+
summary: |
|
|
7
|
+
`prisma contract emit` now gives the snapshot of the emitted contract (`migrations/snapshots/<hash>/`, under the emitted storage hash) the emitted contract's required capabilities and profile hash when it holds others, and reports the snapshot it rewrote. In 8.0.0-rc.26 that snapshot kept the capabilities it was planned with, so a database that `prisma db migrate --to <ref>` created from it, as every Composer deploy does, failed `prisma db verify` with `CONTRACT.SIGNATURE_MISMATCH` ("signed for other capabilities"). Run `prisma contract emit` once and commit the snapshot it rewrites; sign each database created since the upgrade to 8.0.0-rc.26 with `prisma db sign --no-advance-ref`.
|
|
8
|
+
- id: boolean-codec-type-takes-codec-types
|
|
9
|
+
summary: |
|
|
10
|
+
`BooleanCodecType` takes the contract's codec types, as `BooleanCodecType<CodecTypes>`; a use without type arguments no longer compiles.
|
|
11
|
+
detection:
|
|
12
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
13
|
+
matches:
|
|
14
|
+
- '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bBooleanCodecType\b(?!\s*<)'
|
|
15
|
+
- id: function-condition-takes-codec-types
|
|
16
|
+
summary: |
|
|
17
|
+
`FunctionCondition` from the ORM client takes the contract's codec types; a use without type arguments no longer compiles.
|
|
18
|
+
detection:
|
|
19
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
20
|
+
matches:
|
|
21
|
+
- '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bFunctionCondition\b(?!\s*<)'
|
|
22
|
+
- id: condition-codec-on-mysql-and-sqlite
|
|
23
|
+
summary: |
|
|
24
|
+
On MySQL, MariaDB and SQLite a condition from `fns` is an expression of the target's boolean codec, `mysql/boolean@1` or `sqlite/boolean@1`, not `pg/bool@1`.
|
|
25
|
+
detection:
|
|
26
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
27
|
+
matches:
|
|
28
|
+
- 'pg\/bool@1'
|
|
29
|
+
- id: projected-condition-reads-as-boolean
|
|
30
|
+
summary: |
|
|
31
|
+
On MySQL, MariaDB and SQLite a condition selected as a column reads as a boolean, or `null` when its value is NULL, where it read as the text `'1'` or `'0'` on MySQL and MariaDB and as the number `1` or `0` on SQLite; on every target its row type is `boolean` without `null` when no operand is nullable.
|
|
32
|
+
- id: functions-builders-no-longer-published
|
|
33
|
+
summary: |
|
|
34
|
+
`createFunctions` and `createAggregateFunctions` are no longer published; a callback of the query builder receives the functions they built as its `fns` argument, and a callback of the ORM receives the ORM's functions, built from `createFunctions`.
|
|
35
|
+
detection:
|
|
36
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
37
|
+
matches:
|
|
38
|
+
- '\bcreate(?:Aggregate)?Functions\b'
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
# The snapshot of the emitted contract gets its capabilities
|
|
42
|
+
|
|
43
|
+
## `app-snapshot-gets-emitted-profile`
|
|
44
|
+
|
|
45
|
+
`db migrate --to <ref>` signs the database with the profile hash of the ref's contract snapshot, in `migrations/snapshots/<hash>/`. The profile hash covers the capabilities the contract requires. 8.0.0-rc.26 added `conn.interactiveTransactions` to the capabilities a PostgreSQL contract requires, which changed the emitted profile hash but not the storage hash, so the snapshot of the current contract kept the old list and the old profile hash. A database that `db migrate --to <ref>` created from that snapshot was signed with the old profile hash, and `db verify` failed with `CONTRACT.SIGNATURE_MISMATCH`: "The database is signed for other capabilities". `db migrate` without `--to`, or with `--to @contract`, was not affected.
|
|
46
|
+
|
|
47
|
+
`contract emit` now updates the `requiredCapabilities` and `profileHash` in that snapshot's `contract.json` when they differ from the emitted contract's, changes nothing else in it, and writes the snapshot's `contract.d.ts` again from it. Its output names the snapshot, and its `--json` output has it under `rewrittenSnapshot`. The Vite plugin's emit does not update the snapshot; run `prisma contract emit`.
|
|
48
|
+
|
|
49
|
+
1. Run `prisma contract emit` in each Prisma project folder. If the output reports an updated snapshot, commit the files under `migrations/snapshots/` that it changed. If it reports none, it changed no snapshot file, and there is nothing to commit for this step.
|
|
50
|
+
2. This step is only for an application that was on 8.0.0-rc.26 and created databases on it. List each database that `prisma db migrate --to <ref>` or a Composer deploy created after the upgrade to 8.0.0-rc.26: new environments, preview and pull request databases, and demo databases. Run `prisma db verify --db <url>` against each. A database that fails with `CONTRACT.SIGNATURE_MISMATCH` and "The database is signed for other capabilities" was signed with the old profile hash. Sign it again with the emitted contract:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
prisma db sign --db <url> --no-advance-ref
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`db sign` checks the database's schema against the emitted contract before it signs, so run it only once the database is at the contract you emitted. If it refuses because the database's change policy allows only migrations, add `--force`; the schema is still checked and the policies are kept.
|
|
57
|
+
|
|
58
|
+
# Conditions from `fns` carry the contract's boolean codec
|
|
59
|
+
|
|
60
|
+
## `boolean-codec-type-takes-codec-types`
|
|
61
|
+
|
|
62
|
+
`BooleanCodecType`, exported by `@prisma/orm-family-sql/builder/types`, now takes the contract's codec types and, optionally, a nullability. Pass the `CodecTypes` of the contract's `contract.d.ts`:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import type { CodecTypes } from './prisma/contract';
|
|
66
|
+
|
|
67
|
+
expectTypeOf(condition).toExtend<Expression<BooleanCodecType<CodecTypes>>>();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## `function-condition-takes-codec-types`
|
|
71
|
+
|
|
72
|
+
`FunctionCondition`, exported by `@prisma/orm-family-sql/orm-client`, takes the contract's codec types the same way: `FunctionCondition<CodecTypes>`. It also takes a nullability as a second argument.
|
|
73
|
+
|
|
74
|
+
## `condition-codec-on-mysql-and-sqlite`
|
|
75
|
+
|
|
76
|
+
On MySQL, MariaDB and SQLite, a condition such as `fns.eq(...)` or `fns.and(...)` is typed with the target's boolean codec: `mysql/boolean@1` on MySQL and MariaDB, `sqlite/boolean@1` on SQLite. Where code on these targets names `'pg/bool@1'` for a condition, replace it with the target's id. This covers a type annotation such as `Expression<{ codecId: 'pg/bool@1'; nullable: boolean }>`, and `fns.raw` with `.returns('pg/bool@1')` used as the result of `where` or as an operand of `fns.and` or `fns.or`. A boolean column is now accepted wherever a condition is, so a `fns.raw` that only wrapped a boolean column can be replaced by the column. Leave `pg/bool@1` on Postgres as it is.
|
|
77
|
+
|
|
78
|
+
## `projected-condition-reads-as-boolean`
|
|
79
|
+
|
|
80
|
+
On MySQL, MariaDB and SQLite, a condition selected as a column, such as `select('isAdmin', (f, fns) => fns.eq(f.role, 'ADMIN'))`, now reads as `true` or `false`, or as `null` when one of its operands is nullable and its value is NULL. Before, it read as the text `'1'` or `'0'` on MySQL and MariaDB, and as the number `1` or `0` on SQLite. Find the code that reads such a value and use it as a boolean:
|
|
81
|
+
|
|
82
|
+
- On MySQL and MariaDB, look for comparisons with `'1'` or `'0'`, such as `row.isAdmin === '1'`, and conversions such as `Number(row.isAdmin)`. `Boolean(row.isAdmin)` was `true` for `'0'` as well, so code that used it was wrong before and is right now.
|
|
83
|
+
- On SQLite, look for comparisons with `1` or `0`, such as `row.isAdmin === 1`, and conversions such as `Boolean(row.isAdmin)` or `Number(row.isAdmin)`.
|
|
84
|
+
|
|
85
|
+
On Postgres the value does not change.
|
|
86
|
+
|
|
87
|
+
On every target, the row type of a selected condition is `boolean` without `null` when none of its operands is nullable. A type annotation that spells `boolean | null` for such a column still compiles; narrow it to `boolean` where the code no longer needs to handle `null`.
|
|
88
|
+
|
|
89
|
+
## `functions-builders-no-longer-published`
|
|
90
|
+
|
|
91
|
+
`@prisma/orm-family-sql/builder/runtime` no longer exports `createFunctions` and `createAggregateFunctions`, and no other published path exports them. They built the functions that a callback of the query builder receives as its `fns` argument, and the ORM builds the `fns` of its callbacks from `createFunctions`, so code that called them takes `fns` from such a callback instead:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// The query builder: the second argument of an expression callback, such as where, select, a join's on, orderBy, groupBy, having or the set of an update.
|
|
95
|
+
db.sql.public.user.select('id').where((f, fns) => fns.eq(f.id, 1));
|
|
96
|
+
// The ORM: the fns member of the second argument of a where or orderBy callback.
|
|
97
|
+
db.orm.public.User.where((user, { fns }) => fns.eq(user.id, 1));
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Code that called them to build a condition outside a query, such as in a test, builds a query with the query builder instead and reads the condition from the plan's syntax tree, such as the `where` of `db.sql.public.user.select('id').where((f, fns) => fns.eq(f.id, 1)).build().ast` after checking that its `kind` is `'select'`. That is a syntax-tree node, not the expression `createFunctions` returned.
|
package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md
CHANGED
|
@@ -52,7 +52,7 @@ changes:
|
|
|
52
52
|
- '@prisma/orm-(?:postgres|sqlite|mysql|mariadb|mongo)/contract-types[''"]'
|
|
53
53
|
- id: contract-signature-flag
|
|
54
54
|
summary: |
|
|
55
|
-
`prisma db verify --marker-only` is now `prisma db verify --signature-only`; the old flag is refused. Run this guide's colocated script: it changes the flag wherever it is written as a whole word, in `package.json` scripts, CI workflow files, shell scripts
|
|
55
|
+
`prisma db verify --marker-only` is now `prisma db verify --signature-only`; the old flag is refused. Run this guide's colocated script: it changes the flag wherever it is written as a whole word, in `package.json` scripts, CI workflow files, shell scripts and code, including an argument array that spreads the command over several lines.
|
|
56
56
|
detection:
|
|
57
57
|
glob: "**/*"
|
|
58
58
|
matches:
|
|
@@ -60,7 +60,7 @@ changes:
|
|
|
60
60
|
script: ./scripts/contract-signature-names/contract-signature-names.ts
|
|
61
61
|
- id: contract-signature-error-codes
|
|
62
62
|
summary: |
|
|
63
|
-
Nine error codes are renamed. Six say SIGNATURE where they said MARKER, such as `CONTRACT.MARKER_MISSING`, now `CONTRACT.SIGNATURE_MISSING`; `MIGRATION.MARKER_MISMATCH` and `MIGRATION.MARKER_NOT_IN_HISTORY`, which reported one condition from two commands, are one code, `MIGRATION.SIGNATURE_NOT_IN_GRAPH`; `MIGRATION.MARKER_CAS_FAILURE` is `MIGRATION.CONCURRENT_CHANGE`. `CONTRACT.MARKER_REQUIRED` and `CONFIG.FAMILY_READ_MARKER_REQUIRED`, which no command raised, are gone. The script renames the nine wherever they are written; remove code that matches the two removed ones.
|
|
63
|
+
Nine error codes are renamed. Six say SIGNATURE where they said MARKER, such as `CONTRACT.MARKER_MISSING`, now `CONTRACT.SIGNATURE_MISSING`; `MIGRATION.MARKER_MISMATCH` and `MIGRATION.MARKER_NOT_IN_HISTORY`, which reported one condition from two commands, are one code, `MIGRATION.SIGNATURE_NOT_IN_GRAPH`; `MIGRATION.MARKER_CAS_FAILURE` is `MIGRATION.CONCURRENT_CHANGE`. `CONTRACT.MARKER_REQUIRED` and `CONFIG.FAMILY_READ_MARKER_REQUIRED`, which no command raised, are gone. The script renames the nine wherever they are written outside Markdown, and lists the lines of Markdown that name them; remove code that matches the two removed ones.
|
|
64
64
|
detection:
|
|
65
65
|
glob: "**/*"
|
|
66
66
|
matches:
|
|
@@ -444,8 +444,8 @@ This release changes every hash Prisma stores, so an extension built for an earl
|
|
|
444
444
|
|
|
445
445
|
Make the changes below in this order, and skip a step that does not apply to the extension:
|
|
446
446
|
|
|
447
|
-
1. Fix `package.json` before you run the install: move every `@prisma/orm-*` package the extension's shipped code uses to `peerDependencies`, and list it under `devDependencies` too, at `8.0.0-rc.26` (`prisma-packages-are-peer-dependencies`). Move the `prisma` package the extension builds with to `
|
|
448
|
-
2. Run the three scripts that rewrite import paths and names, in this order, and make the changes by hand that each one lists: `facade-paths-an-application-uses`, then `platform-paths-an-extension-uses`, then `contract-signature-names` (`contract-signature-flag` and the entries after it). Each later script reads what the earlier one wrote. Then change the imports of the PostgreSQL client's parts to their Early Access names (`postgres-client-parts-early-access-names`, `sql-prepared-query-early-access-names`), and any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). Until step 5 emits the contract, its `contract.d.ts` still has the old shape, so a type check before then also reports errors that name the contract's `capabilities` or `requiredCapabilities`; do not fix those by hand.
|
|
447
|
+
1. Fix `package.json` before you run the install: move every `@prisma/orm-*` package the extension's shipped code uses to `peerDependencies`, and list it under `devDependencies` too, at `8.0.0-rc.26` (`prisma-packages-are-peer-dependencies`). Move the `prisma` package the extension builds with to the version whose `@prisma/orm-toolchain` dependency is exactly the ORM version the extension's `devDependencies` install, as [Choosing the `prisma` version](../../../../references/upgrade-app.md#choosing-the-prisma-version) describes. Read its dependencies, not its own number: `prisma` `8.0.0-rc.37` depends on `@prisma/orm-toolchain` `8.0.0-rc.26`. `prisma` `8.0.0-rc.36` runs the toolchain of `8.0.0-rc.25` beside this release's packages. Once the bundled files are upgraded, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version": that is this release's `CONTRACT.FORMAT_VERSION_MISSING` error, which the old toolchain reports under its own code. Then install.
|
|
448
|
+
2. Run the three scripts that rewrite import paths and names, in this order, and make the changes by hand that each one lists: `facade-paths-an-application-uses`, then `platform-paths-an-extension-uses`, then `contract-signature-names` (`contract-signature-flag` and the entries after it). Each later script reads what the earlier one wrote. Then change the imports of the PostgreSQL client's parts to their Early Access names (`postgres-client-parts-early-access-names`, `sql-prepared-query-early-access-names`), and any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). Until step 5 emits the contract, its `contract.d.ts` still has the old shape, so a type check before then also reports errors in code that uses a client of that contract, such as tests. Some name the contract's `capabilities` or `requiredCapabilities`; others do not, such as `TS2349` "This expression is not callable" on a method that a capability enables, such as `.returning()`, `TS2339` on a field of the row such a query returns, and `TS2345` on a `transaction` callback. Do not fix those by hand: type-check again after step 5's `prisma contract emit`, and fix only what is left then.
|
|
449
449
|
3. Make the code changes, in any order: capabilities (`extension-code-reads-required-capabilities`, `required-capabilities-as-list`, `extension-descriptor-declares-no-capabilities`, `extension-capability-flags-removed`, `extension-client-goes-by-the-contract`, `extension-capability-exports-moved`), data types and index types (`data-type-param-keys` and the entries after it, `index-type-options-standard-schema`, `extension-index-types-checked-for-prisma-schemas`), the control API's contract resolvers (`control-api-ref-resolution-takes-migration-dir`), the database's config and Prisma's tables (`read-the-database-config`, `policy-helpers-renamed`, `name-the-prisma-schema`, `prisma-tables-api-breaks`, `sqlite-prisma-tables-renamed`, `sqlite-prisma-tables-api-breaks`), MongoDB and migration calls (`kept-enum-member-route-removed`, `mongo-runner-checked-policies-renamed`, `extension-migration-calls-use-framework-interface`), the ORM client (`fragment-on-the-client`, `aggregate-operation-names-after-8-0`, `orm-fns-comparison-takes-field-input-type`, `update-all-explicit-type-argument`, `prepared-declaration-param-spec-can-be-a-list`), sets of values that may grow (`extension-middleware-handles-later-activities`, `extension-switches-over-later-values`, `extension-more-open-sets-of-values`), and the stored-file APIs (`descriptor-self-consistency-takes-contract-json`, `contract-space-from-json-reads-stored-files`, `canonicalize-contract-takes-version-from-serializer`, `contract-serializer-prints-version-1`).
|
|
450
450
|
4. On PostgreSQL, write the list of capabilities the extension's contract requires (`extension-contract-lists-required-capabilities`, its step 1). Do not run `prisma contract emit` yet.
|
|
451
451
|
5. Bring the bundled files up to date: run the `stored-files-format-version` script, then the `contract-hash-inputs` script, then `prisma contract emit` once. That one emit also covers `extension-stored-contract-needs-the-upgrade-script`. If the emitted contract's storage hash differs from the one the script printed, follow `contract-hash-inputs` under "When the emitted contract gets a different storage hash". Then build, run the tests, sign each test database again (`extension-contract-lists-required-capabilities`, its step 4), and publish a new version with no new migration.
|
|
@@ -520,7 +520,7 @@ This guide is part of the `prisma-8` skill. The skill ships inside the database
|
|
|
520
520
|
|
|
521
521
|
Run it from that copy, not from the one under `node_modules/@prisma/orm-<database>/skills/`: Node does not strip types from a file under `node_modules`, so it refuses to run the script there. You need Node.js 24 or later, which Prisma 8 already requires; it runs the TypeScript file directly. It may print an `ExperimentalWarning` about type stripping, which is harmless.
|
|
522
522
|
|
|
523
|
-
The script works on the folder you give it, or on the working directory, and every folder below it except `node_modules`, `dist`, `build
|
|
523
|
+
The script works on the folder you give it, or on the working directory, and every folder below it except `node_modules`, `dist`, `build`, folders whose name starts with a dot, and, in a git repository, the files and folders git ignores (through `.gitignore`, `.git/info/exclude` or the user's global ignore file). A file git tracks inside an ignored folder is still read, and so is the folder you give it, even if git ignores it. The two scripts that rewrite stored files, `stored-files-format-version` and `contract-hash-inputs`, also read a migrations folder that git ignores, and every file in it: nothing else writes those files again, and this release refuses a snapshot they have not upgraded. They recognise a migrations folder by what it holds, a contract snapshot store, a migration package or a ref file, directly or in a space folder. A copy of one inside a folder git ignores, such as `wip/`, is still skipped. The ignore rules of a nested repository or a submodule are not applied, so the scripts walk the folders it ignores. In a monorepo, a run at the repository root covers every package in it, and so does a run in each package that imports Prisma. The two scripts that read code with TypeScript, `platform-paths-an-extension-uses` and `contract-signature-names`, load the `typescript` package that code in the folder you give them would import, so where packages use different TypeScript versions, run those two once in each package. The two scripts that rewrite stored files, `stored-files-format-version` and `contract-hash-inputs`, are different: run each of them once per extension package, giving it the package's folder, as their sections say.
|
|
524
524
|
|
|
525
525
|
#### Run the script
|
|
526
526
|
|
|
@@ -823,7 +823,14 @@ Commit your work first, so the script's changes can be reviewed and undone with
|
|
|
823
823
|
node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts .
|
|
824
824
|
```
|
|
825
825
|
|
|
826
|
-
As with the other script, run it from the skills copy, not from `node_modules`, with Node.js 24 or later. It reads each file with the project's own TypeScript compiler, so run it in a project whose `typescript` package is installed; if it finds none, it says so and stops without changing any file. It
|
|
826
|
+
As with the other script, run it from the skills copy, not from `node_modules`, with Node.js 24 or later. It reads each file with the project's own TypeScript compiler, so run it in a project whose `typescript` package is installed; if it finds none, it says so and stops without changing any file. It needs TypeScript 5 or 6: the `typescript` package of TypeScript 7 has no compiler API that a script can call. The script tries the project's `typescript` first, then one installed beside the script, and uses the first that has a compiler API. If neither has one, it changes no file, says that it needs TypeScript 5 or 6, and exits with code 1. Then do one of the two things its message offers:
|
|
827
|
+
|
|
828
|
+
- Install TypeScript 5 in the project for the run, for example with `pnpm add -D typescript@5` (add `-w` at the root of a pnpm workspace), run the script, and put the project's own TypeScript version back afterwards.
|
|
829
|
+
- Install `typescript@5` in an empty folder, copy the script's `.ts` file into that folder, and run the copy with the project folder as its argument: `node <folder>/<script>.ts <project folder>`.
|
|
830
|
+
|
|
831
|
+
If the script fails on an error it did not expect, it says "The script failed on an unexpected error, before it changed any file. This is a fault in the script; report it to Prisma with this output", prints the stack trace, and exits with code 1.
|
|
832
|
+
|
|
833
|
+
It skips `node_modules`, `dist`, `build`, folders whose name starts with a dot, and, in a git repository, the files and folders git ignores.
|
|
827
834
|
|
|
828
835
|
The script:
|
|
829
836
|
|
|
@@ -849,7 +856,7 @@ The script reads only source files. Rename the old names in your Markdown and ot
|
|
|
849
856
|
- An import of a name no published path exports any more, such as `planIssues` from `@prisma/orm-target-postgres/target` or `target/issue-planner`, `MigrationToolsError` from `@prisma/orm-toolchain/migration-tools`, `validateSqlContractFully` from `@prisma/orm-family-sql/contract`, `Tokenizer` from `@prisma/orm-framework/psl-parser/tokenizer` or `BuiltinFunctions` from `@prisma/orm-family-sql/relational-core/functions`.
|
|
850
857
|
- A namespace import, an `export *`, a dynamic `import()` or a `require` of a path whose names are no longer published together, and one it moved, so you check the names it uses.
|
|
851
858
|
- A `vi.mock` or `jest.mock` of a path this change moves. Point the mock at the module the code under test now imports, and rename what its factory returns.
|
|
852
|
-
- A file that re-exports a renamed name under its old name. Rename the name where the project imports it, then drop the alias.
|
|
859
|
+
- A file that re-exports a renamed name under its old name. Rename the name where the project imports it, then drop the alias, unless the alias is part of the extension's published API: dropping it there breaks the extension's users, so keep it until a release that may break them. When the project re-exports Prisma's error from a module of its own, every file that imports it from there uses the old name, which can mean a rename across most of the repository. The alias keeps those files compiling, so you can make that rename in a change of its own. Until then, make sure none of them tests the error's `name` against `'InternalError'`, which no error of this release has.
|
|
853
860
|
- A check of `name` against `'InternalError'` in a file with no Prisma import of `InternalError`, or of `isPrismaInternalError` in a file that imports nothing from Prisma. If it means Prisma's error, use `isInvariantError`.
|
|
854
861
|
- A `vi.mock` or `jest.mock` with a factory of a kept path that exports a renamed name, such as `@prisma/orm-family-sql/runtime`. Rename what its factory returns.
|
|
855
862
|
|
|
@@ -911,7 +918,7 @@ Every other name that is no longer published was a part of how Prisma builds its
|
|
|
911
918
|
|
|
912
919
|
#### Check the result
|
|
913
920
|
|
|
914
|
-
Type-check and test the extension. A local binding of the same name as a renamed import, such as a parameter destructured as `{ InternalError }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as `errors.InternalError` on a parameter `errors`. Then run the script again: once you have rewritten everything it listed, it changes nothing and lists
|
|
921
|
+
Type-check and test the extension. The script renames a check of `name` against `'InternalError'` only in a comparison or a `case`. A test that matches the name another way, such as `expect.objectContaining({ name: 'InternalError' })`, keeps it and fails; search the project for `'InternalError'` and change each match that means Prisma's error to `'InvariantError'`. A local binding of the same name as a renamed import, such as a parameter destructured as `{ InternalError }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as `errors.InternalError` on a parameter `errors`. Then run the script again: once you have rewritten everything it listed, it changes nothing and lists only what you chose to keep, such as a re-export alias that is part of the extension's published API.
|
|
915
922
|
|
|
916
923
|
## `contract-types` exports types only
|
|
917
924
|
|
|
@@ -1037,7 +1044,7 @@ Commit your work first. Then run the script that sits beside this guide in the `
|
|
|
1037
1044
|
node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts .
|
|
1038
1045
|
```
|
|
1039
1046
|
|
|
1040
|
-
It is the same script as the application guide's. In a code file that imports a renamed name from an `@prisma/orm-*` package, it renames that import and the file's uses of it; a name the file re-exports keeps the name the file exports (`export { ContractSignatureRow as ContractMarkerRow }`), so your own users are not broken. An object that holds the import in shorthand keeps its key: `{ errorMarkerMissing }` becomes `{ errorMarkerMissing: errorSignatureMissing }`. In a file that imports from such a package, it renames each renamed member where the file reads it (`.readMarker`), writes it as a key (`markerLocation: …`), or declares it in a class, interface or object (`async readMarker(…) {`, `markerLocation = …`, `readMarker = async (…) => …`), and in a type that names it as a string (`Pick<SqlControlAdapter<'postgres'>, 'readMarker'>`, `SqlControlAdapter<'postgres'>['readMarker']`). A variable, parameter, function or export your code declares keeps its name. In a file that uses a renamed name through an import, it reads the code with the project's own TypeScript compiler, so that a local binding of that name, such as a parameter destructured as `{ errorMarkerMissing }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as a parameter `errors` in a file that imports `@prisma/orm-framework/errors` as the namespace `errors`; if it finds no `typescript` package, it says so and stops without changing any file. It also renames the path, the flag, the codes, the values and the `--json` fields, as the application guide says, prints each file it changed, and a second run changes nothing.
|
|
1047
|
+
It is the same script as the application guide's. In a code file that imports a renamed name from an `@prisma/orm-*` package, it renames that import and the file's uses of it; a name the file re-exports keeps the name the file exports (`export { ContractSignatureRow as ContractMarkerRow }`), so your own users are not broken. An object that holds the import in shorthand keeps its key: `{ errorMarkerMissing }` becomes `{ errorMarkerMissing: errorSignatureMissing }`. In a file that imports from such a package, it renames each renamed member where the file reads it (`.readMarker`), writes it as a key (`markerLocation: …`), or declares it in a class, interface or object (`async readMarker(…) {`, `markerLocation = …`, `readMarker = async (…) => …`), and in a type that names it as a string (`Pick<SqlControlAdapter<'postgres'>, 'readMarker'>`, `SqlControlAdapter<'postgres'>['readMarker']`). A variable, parameter, function or export your code declares keeps its name. In a file that uses a renamed name through an import, it reads the code with the project's own TypeScript compiler, so that a local binding of that name, such as a parameter destructured as `{ errorMarkerMissing }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as a parameter `errors` in a file that imports `@prisma/orm-framework/errors` as the namespace `errors`; if it finds no `typescript` package, it says so and stops without changing any file, and when it needs TypeScript and finds only TypeScript 7, it changes no file and exits with code 1, as `platform-paths-an-extension-uses` does. It also renames the path, the flag, the codes, the values and the `--json` fields, as the application guide says, prints each file it changed, and a second run changes nothing. It skips the files and folders git ignores. In Markdown files it changes nothing: it lists each place in them that names the old flag or an old code, or an old `--json` field on a line that runs `db verify`, `db init`, `db update` or `db migrate` with `--json`, because the sentence around it usually needs rewriting too, and a dated record, such as a changelog, should keep the old names. It prints them last, under `Not changed:`, one line each, as `file:line: old -> new`, and still exits with code 0. Change by hand the places that describe how the extension works now.
|
|
1041
1048
|
|
|
1042
1049
|
```ts
|
|
1043
1050
|
// before
|
|
@@ -1075,6 +1082,7 @@ The script finds names by searching the text of your code. It uses TypeScript on
|
|
|
1075
1082
|
grep -rnE --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir=upgrading '\.marker(Hash)?\b|\[.marker(Hash)?.\]|\{[^}]*\bmarker(Hash)?\b[^}]*\}[[:space:]]*[=:)]' .
|
|
1076
1083
|
```
|
|
1077
1084
|
|
|
1085
|
+
- **Messages.** The script renames codes and `--json` fields, not the text of messages. `db verify` now reports "The database's contract signature and schema match the contract" where it reported "Database marker and schema match contract", and, with `--signature-only`, "The database's contract signature matches the contract" where it reported "Database marker matches contract". Change a test or script that matches the old text.
|
|
1078
1086
|
- **Your target's own table and messages.** A target that stores signatures in a table of its own keeps its table name; rename only what the code calls it, if you want the code to match. Messages your target writes that say "marker" are yours to reword.
|
|
1079
1087
|
|
|
1080
1088
|
The searches leave out the `upgrading` folder of the skill copy, whose guides name the old names.
|
|
@@ -1879,15 +1887,17 @@ Each file Prisma stores now says which version of its format it is in, so a late
|
|
|
1879
1887
|
{ "formatVersion": 1, "from": null, "to": "...", ... }
|
|
1880
1888
|
```
|
|
1881
1889
|
|
|
1882
|
-
Commit your work first. Then run the script from the
|
|
1890
|
+
Commit your work first. Then run the script once for each extension package, from the folder that holds the skills copy, and give it the package's folder as its one argument, relative to where you run it; without one, it works on the working directory. For a package at the repository root, the argument is `.`; for one in `packages/extension-foo`:
|
|
1883
1891
|
|
|
1884
1892
|
```sh
|
|
1885
|
-
node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts
|
|
1893
|
+
node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts packages/extension-foo
|
|
1886
1894
|
```
|
|
1887
1895
|
|
|
1896
|
+
Do not give it a folder that holds more than the package, such as the root of a monorepo: it would also reach files that look like Prisma's but are not, such as test fixtures. If one of them cannot be read as Prisma's, the script changes no file at all and exits with code 1. The script takes one argument at most, the folder, and no option.
|
|
1897
|
+
|
|
1888
1898
|
The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
|
|
1889
1899
|
|
|
1890
|
-
Node 24 or later runs the TypeScript script directly. It reads and writes files only. It walks the
|
|
1900
|
+
Node 24 or later runs the TypeScript script directly. It reads and writes files only. It walks the folder you gave it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot, and, in a git repository, the files and folders git ignores other than a migrations folder and what is in it. In every contract (any `*.json` file with `targetFamily`, `storage` and `schemaVersion` at the top level) it replaces `"schemaVersion": "1"` with `"formatVersion": 1`. In every `migration.json` that has an `ops.json` next to it, and every ref file under the package's `migrations/refs/` (or the migrations folder the package configures under another name; the script recognises a migrations folder by the contract snapshot store or the migrations in it, not by its name, and a ref in any other `refs` folder by its `hash` and `invariants`), it adds `"formatVersion": 1` as the first field. It keeps the rest of each file's bytes, prints each file it changed, and says so when nothing needed changing. A field a ref file does not have, which earlier releases ignored and dropped when they wrote the ref again, it drops and lists. It checks every file before it writes any. It changes no file, prints `Changed no file, because:` with what is wrong with each file and what to do, and exits 1 when it cannot tell the file is one a release of Prisma wrote: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file in a migrations folder it recognises without a `hash` or an `invariants` list; a `migration.json` next to an `ops.json` with a field the format does not have or without one it has; a contract with both `formatVersion` and `schemaVersion`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`. Outside a migrations folder it recognises, it leaves alone, without a report, any file in a `refs` folder without a ref's content (a `hash` that is `empty` or a 64-character storage hash, and an `invariants` list of strings). If a command still refuses a ref file after the script ran, that ref was already invalid, and earlier releases refused it too: restore it from version control, or correct it by hand, since no Prisma command writes the head ref in an extension's own package: its `hash` is the `storage.storageHash` of the contract the extension emits. It also reports a stored file whose `formatVersion` is not `1` and a snapshot's `contract.json` that is not a JSON object. It does not follow symbolic links. It ignores a link to the package folder or a folder above it, and a link to a folder inside the package that the walk enters or to a `.json` file in one, unless the walk would read the target as another kind of file than at the link, such as a ref in `migrations/refs/` that links to a file elsewhere; it reports such a link and exits 1. It reports a link to any other file or folder, outside the package or skipped by the walk, that holds a stored file it would change or report.
|
|
1891
1901
|
|
|
1892
1902
|
No hash covers the format version: the storage hash, the head ref's hash, snapshot directory names and each `migrationHash` stay as they are. Then run the `contract-hash-inputs` script below, and only then `prisma contract emit`, which writes the new form of `contract.json`. Rebuild the package and publish it as those instructions say.
|
|
1893
1903
|
|
|
@@ -1982,17 +1992,21 @@ A contract has three hashes: the storage hash (`storage.storageHash`), the profi
|
|
|
1982
1992
|
|
|
1983
1993
|
An extension's package carries these hashes: its emitted `src/contract.json` and `contract.d.ts`, `migrations/refs/head.json`, the `from`, `to` and `migrationHash` of each `migration.json` and any storage hash in its `ops.json`, the snapshots under `migrations/snapshots/<hash>/` and the `migration.ts` that import them. When an application loads the extension, this release recomputes the hash of the bundled contract and compares it with the head ref. An extension published for an earlier release therefore fails to load with `MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH`, which names the extension.
|
|
1984
1994
|
|
|
1985
|
-
The script works on files with or without `formatVersion`, and leaves their format as it is, so it does not matter whether you have run the upgrade step for the stored-file format version (`stored-files-format-version`). Commit your work, then run the script from the
|
|
1995
|
+
The script works on files with or without `formatVersion`, and leaves their format as it is, so it does not matter whether you have run the upgrade step for the stored-file format version (`stored-files-format-version`). Commit your work, then run the script from the folder that holds the skills copy:
|
|
1986
1996
|
|
|
1987
1997
|
```sh
|
|
1988
|
-
node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts
|
|
1998
|
+
node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts packages/extension-foo
|
|
1989
1999
|
```
|
|
1990
2000
|
|
|
2001
|
+
As with the format version script, run it once for each extension package and give it the package's folder, here `packages/extension-foo`, or `.` for a package at the repository root. The script checks every stored file below that folder before it changes anything. A hand-written `migration.json` whose `migrationHash` does not match its migration, or a snapshot with hashes no release wrote, makes it change no file and exit with code 1; a lone contract file, such as a test fixture, is left alone, as the next paragraph says. It skips the files and folders git ignores, other than a migrations folder and what is in it.
|
|
2002
|
+
|
|
1991
2003
|
The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
|
|
1992
2004
|
|
|
1993
2005
|
Node 24 or later runs the TypeScript script directly. It reads and writes files only. It first checks that each stored storage hash, and each snapshot directory's name, is the hash the old rules or the new rules give the contract's content, and that each `migrationHash` matches its migration. If one does not, the file was edited by hand or comes from another release: the script changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the package, and exits 1. Otherwise it rewrites every hash listed above, renames each snapshot directory to its new hash, and recomputes each `migrationHash`, keeping every other byte of each file. It also renames each contract's and snapshot's `capabilities` to `requiredCapabilities`, and the type of that list in each `contract.d.ts`: `sql.interactiveTransactions` becomes `conn.interactiveTransactions`, every other `sql.` and `postgres.` key becomes `db.`, and a PostgreSQL contract loses the nine keys the release candidates wrote that nothing reads, such as `postgres.jsonAgg`. A contract a development build wrote, with `requiredCapabilities` grouped by provider (`{ "db": { "returning": true } }`), gets the sorted list too, of the keys it sets to `true`; a contract already in the list form keeps it. This release refuses a contract that still has `capabilities`, and a snapshot cannot be emitted again, so the script is the only way to bring one to this release. It changes no file, names the contract and exits 1 when a contract's capabilities cannot be renamed: two old keys become one key with different values (such as `sql.distinctOn: false` beside `postgres.distinctOn: true`, which both become `db.distinctOn`), the file has both `capabilities` and `requiredCapabilities`, `requiredCapabilities` is neither a list of strings nor an object, or a `sql` or `postgres` namespace of `capabilities`, or a provider of a grouped `requiredCapabilities`, is not an object. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand, and run the script again. It does not follow symbolic links. It also changes no file at all, names the cause and exits 1 when a link leads to a file or folder that holds stored files and that the walk does not reach, inside the package where the walk skips or outside the package, or that the walk reaches but reads as another kind of file, such as a ref in `migrations/refs/` that links to a file elsewhere, or when a snapshot directory, or the `contract.json` in one, is itself a link, wherever it points, or a folder above it is a link to a place where the snapshot is not under a `snapshots` folder by the same hash, such as a `snapshots` folder linked to a folder with another name, since the script renames each snapshot directory to its new storage hash and through the link it would keep the old name, or when a link outside a snapshot directory points into one, such as a `contract.json` linked to a snapshot's, since after the rename the link would point at nothing, or when a snapshot whose storage hash changes cannot be rewritten without changing other content: migrations and refs would then name a snapshot directory that keeps its old name. Fix the file as the report says and run the script again. It prints what it changed; a second run changes nothing. If you ran `prisma contract emit` with this release before the script, and the contract source holds a value the earlier release left out, the emitted contract's storage hash differs from the new hash of the contract the earlier release wrote, which is the one your databases are at. The script gives every snapshot, migration and ref that named the old hash that new hash, whether or not a snapshot of the contract is left. It leaves the emitted contract as it is and lists it with both hashes, on every run; "When the emitted contract gets a different storage hash" below says what to do. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
|
|
1994
2006
|
|
|
1995
|
-
Then build the package and run its tests, and publish a new version. An application must upgrade the extension together with Prisma: an older version of the extension does not load in this release, and this version does not load in an earlier one.
|
|
2007
|
+
Then run `prisma contract emit`, build the package and run its tests, and publish a new version. An application must upgrade the extension together with Prisma: an older version of the extension does not load in this release, and this version does not load in an earlier one.
|
|
2008
|
+
|
|
2009
|
+
Do not run again the `migration.ts` of a migration the extension already shipped. This release can write other checks into `ops.json` than the release that planned the migration, such as new prechecks and postchecks, so running one changes its `ops.json` and its `migrationHash`, and the migration is no longer the one applications have applied. The script changes those `migration.ts` files without running them, and the migration hash does not cover `migration.ts`. A CI check that runs each changed `migration.ts` and compares what it writes with the committed files fails on the upgrade's pull request for that reason; make an exception for that one pull request.
|
|
1996
2010
|
|
|
1997
2011
|
Add no migration in this version: publish any new migration in a version for the release before, and leave this one with the migrations it already had. An application deploys every pending migration, its own and its extensions', before it upgrades, then upgrades Prisma and the extension in a release of its own, whose deploy runs `prisma db sign --no-advance-ref` (with `--force` where the database's change policy permits only migrations) and then `prisma db migrate` against each database that existed before it. The release assumes every database is at the newest contract of the application and of every extension: `db sign` signs the extension's space at the extension's head, whatever contract the application names, so a database must already be there. A migration first shipped in this version would not be in the database yet: signing would then fail, because the schema does not match, or, for a migration that only drops something or moves data, mark the space as up to date so the migration never runs. The application's guide gives these steps.
|
|
1998
2012
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage: node contract-hash-inputs.ts [project-root]
|
|
8
8
|
*
|
|
9
|
-
* The project root defaults to the working directory. The script reads and writes files only; it needs no database. It walks the root, skipping `node_modules`, `dist`, `build
|
|
9
|
+
* The project root defaults to the working directory. The script reads and writes files only; it needs no database. It walks the root, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot and, in a git repository, the files and folders git ignores, unless git ignores the root itself, except a migrations folder (one holding the contract snapshot store, a migration package or a ref file, directly or in a space folder) and what is in it, since nothing else writes those files again, and finds stored files the way the `stored-files-format-version` script does: a contract by its content (`targetFamily` and `storage`) in any `*.json` file, a `migration.json` by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content.
|
|
10
10
|
*
|
|
11
11
|
* First it checks every contract: each stored `storageHash`, `profileHash` and `executionHash`, and each snapshot directory's name, must be the hash the old rules or the new rules give the contract's content. Two exceptions: a snapshot's profile and execution hash may come from an earlier release's rules, and a MongoDB snapshot may keep the storage hash it had before an earlier upgrade step rewrote its content; both get the hashes their content gives. Then it checks each `migration.json` against its `migrationHash`, and that each `from`, `to` and ref `hash` names a contract of the project. If any check fails, it changes no file, prints one line per problem and exits 1. A hash that does not match the content means the file was edited by hand or comes from another release; fix that first.
|
|
12
12
|
*
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* The hash rules, old and new, the families' normal forms of storage and the migration hash rule are copied from Prisma's packages, because a project's strict `node_modules` does not expose them.
|
|
20
20
|
*/
|
|
21
|
+
import { spawnSync } from 'node:child_process';
|
|
21
22
|
import { createHash } from 'node:crypto';
|
|
22
23
|
import {
|
|
23
24
|
chmodSync,
|
|
@@ -1145,6 +1146,79 @@ function isWalked(name: string): boolean {
|
|
|
1145
1146
|
return !SKIPPED_DIRECTORIES.has(name) && !name.startsWith('.');
|
|
1146
1147
|
}
|
|
1147
1148
|
|
|
1149
|
+
let ignoredByGit: (path: string) => boolean = () => false;
|
|
1150
|
+
|
|
1151
|
+
/** A test of whether git ignores a file or folder under `root`. Outside a git repository it ignores nothing, and so it does when git ignores `root` itself, which the user then named on purpose. */
|
|
1152
|
+
function gitIgnores(root: string): (path: string) => boolean {
|
|
1153
|
+
const listed = spawnSync(
|
|
1154
|
+
'git',
|
|
1155
|
+
['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'],
|
|
1156
|
+
{ cwd: root, encoding: 'utf8', maxBuffer: 2 ** 30 },
|
|
1157
|
+
);
|
|
1158
|
+
if (listed.status !== 0) return () => false;
|
|
1159
|
+
const ignored = new Set(
|
|
1160
|
+
listed.stdout
|
|
1161
|
+
.split('\0')
|
|
1162
|
+
.filter((path) => path !== '')
|
|
1163
|
+
.map((path) => path.replace(/\/$/, '')),
|
|
1164
|
+
);
|
|
1165
|
+
if (ignored.has('.')) return () => false;
|
|
1166
|
+
const bases = [root, realpathSync(root)];
|
|
1167
|
+
return (path) =>
|
|
1168
|
+
bases.some((base) => ignored.has(relative(base, path).split(sep).join('/'))) &&
|
|
1169
|
+
!isInMigrationsFolder(bases, path);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function readsAsRef(path: string): boolean {
|
|
1173
|
+
try {
|
|
1174
|
+
const value: unknown = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/, ''));
|
|
1175
|
+
return isRecord(value) && hasRefContent(value);
|
|
1176
|
+
} catch {
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/** Whether `dir` holds what Prisma writes to a migrations directory or to one of its spaces: the contract snapshot store, a migration package or a ref file. */
|
|
1182
|
+
function holdsMigrationFiles(dir: string): boolean {
|
|
1183
|
+
return isMigrationsDirectory(dir) || holdsRef(dir);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
function holdsRef(dir: string): boolean {
|
|
1187
|
+
const refs = join(dir, 'refs');
|
|
1188
|
+
const entries = listDirectory(refs);
|
|
1189
|
+
return (
|
|
1190
|
+
typeof entries !== 'string' &&
|
|
1191
|
+
entries.some((entry) => entry.isFile() && readsAsRef(join(refs, entry.name)))
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/** Whether `dir` holds what Prisma writes to a space of a migrations directory: a migration package or a ref file. The snapshot store sits beside the spaces, never in one. */
|
|
1196
|
+
function holdsSpaceFiles(dir: string): boolean {
|
|
1197
|
+
return hasSubdirectory(dir, isMigrationPackage) || holdsRef(dir);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
function isMigrationsFolder(dir: string): boolean {
|
|
1201
|
+
return (
|
|
1202
|
+
holdsMigrationFiles(dir) ||
|
|
1203
|
+
hasSubdirectory(dir, (path, name) => SPACE_ID.test(name) && holdsSpaceFiles(path))
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/** Whether `path`, or a folder it is in below the project root, is a migrations folder, whose files the script upgrades even when git ignores them: nothing else writes them again. */
|
|
1208
|
+
function isInMigrationsFolder(bases: readonly string[], path: string): boolean {
|
|
1209
|
+
for (let dir = path; !bases.includes(dir) && dir !== dirname(dir); dir = dirname(dir))
|
|
1210
|
+
if (isDirectory(dir) && isMigrationsFolder(dir)) return true;
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/** Whether the walk from `realRoot` reaches `target`. */
|
|
1215
|
+
function isReached(realRoot: string, target: string): boolean {
|
|
1216
|
+
const names = relative(realRoot, target).split(sep);
|
|
1217
|
+
return names.every(
|
|
1218
|
+
(name, index) => isWalked(name) && !ignoredByGit(join(realRoot, ...names.slice(0, index + 1))),
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1148
1222
|
function isInside(dir: string, path: string): boolean {
|
|
1149
1223
|
return path === dir || path.startsWith(`${dir}${sep}`);
|
|
1150
1224
|
}
|
|
@@ -1164,12 +1238,16 @@ function visit(
|
|
|
1164
1238
|
for (const entry of entries) {
|
|
1165
1239
|
const path = join(dir, entry.name);
|
|
1166
1240
|
const shown = relative(root, path);
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
} else if (entry.isFile() && entry.name.endsWith(TEMPORARY_SUFFIX)) {
|
|
1241
|
+
const isLeftover = entry.isDirectory()
|
|
1242
|
+
? entry.name.startsWith('.') && entry.name.endsWith(REMOVED_SUFFIX)
|
|
1243
|
+
: entry.isFile() && entry.name.endsWith(TEMPORARY_SUFFIX);
|
|
1244
|
+
if (isLeftover) {
|
|
1172
1245
|
files.leftovers.push(path);
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
if (ignoredByGit(path)) continue;
|
|
1249
|
+
if (entry.isDirectory()) {
|
|
1250
|
+
if (isWalked(entry.name)) visit(root, path, files, stops, checkLinks);
|
|
1173
1251
|
} else if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
1174
1252
|
classify(root, path, files, stops, shown);
|
|
1175
1253
|
} else if (entry.isFile() && entry.name === 'migration.ts' && isMigrationPackage(dir)) {
|
|
@@ -1196,9 +1274,7 @@ function checkLink(root: string, path: string, name: string, stops: string[]): v
|
|
|
1196
1274
|
}
|
|
1197
1275
|
if (isInside(target, realRoot)) return;
|
|
1198
1276
|
const inside = isInside(realRoot, target);
|
|
1199
|
-
const reached =
|
|
1200
|
-
relative(realRoot, target).split(sep).every(isWalked) &&
|
|
1201
|
-
(isDirectory(target) || target.endsWith('.json'));
|
|
1277
|
+
const reached = isReached(realRoot, target) && (isDirectory(target) || target.endsWith('.json'));
|
|
1202
1278
|
const intoSnapshot = inside && isInSnapshotDirectory(realRoot, target);
|
|
1203
1279
|
const reading = inside && reached ? linkReading(root, path, realRoot, target, name) : undefined;
|
|
1204
1280
|
if (reading === 'snapshot') {
|
|
@@ -1666,6 +1742,7 @@ function main(args: readonly string[]): number {
|
|
|
1666
1742
|
process.stderr.write(`${root}: not a directory\n`);
|
|
1667
1743
|
return 1;
|
|
1668
1744
|
}
|
|
1745
|
+
ignoredByGit = gitIgnores(root);
|
|
1669
1746
|
const shown = (path: string) => relative(root, path).split(sep).join('/');
|
|
1670
1747
|
const files = emptyFiles();
|
|
1671
1748
|
const stops: string[] = [];
|