@prisma/orm-sqlite 8.0.0-rc.23-dev.14 → 8.0.0-rc.24-dev.2
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/runtime.d.mts +3 -2
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +30 -4
- package/dist/runtime.mjs.map +1 -1
- package/dist/{sqlite-DrpYKUC0-wkBQ7gVM.d.mts → sqlite-DtcJe6kq-Qi6-p5Cy.d.mts} +14 -5
- package/dist/sqlite-DtcJe6kq-Qi6-p5Cy.d.mts.map +1 -0
- package/dist/{sqlite-static-CUbtFUTw-CIXVd8ew.mjs → sqlite-static-hboT7-Nq-D5068C14.mjs} +4 -4
- package/dist/sqlite-static-hboT7-Nq-D5068C14.mjs.map +1 -0
- package/dist/static.d.mts +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +9 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/contract.md +3 -1
- package/skills/prisma-8/references/migrations.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +319 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +304 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/dist/sqlite-DrpYKUC0-wkBQ7gVM.d.mts.map +0 -1
- package/dist/sqlite-static-CUbtFUTw-CIXVd8ew.mjs.map +0 -1
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
---
|
|
2
|
+
from: "8.0.0-rc.23"
|
|
3
|
+
to: "8.0.0-rc.24"
|
|
4
|
+
changes:
|
|
5
|
+
- id: engine-pin-moves-to-0-10-0
|
|
6
|
+
summary: |
|
|
7
|
+
The toolchain now requires `@prisma/cli-engine@0.10.0` (up from 0.9.0). A project that depends on `@prisma/cli-engine` itself must move to `0.10.0`.
|
|
8
|
+
detection:
|
|
9
|
+
glob: "**/{package.json,pnpm-workspace.yaml}"
|
|
10
|
+
matches:
|
|
11
|
+
- '"@prisma/cli-engine":\s*"[^"]*(?<![\d.])0\.\d(?!\d)'
|
|
12
|
+
- '[''"]?@prisma/cli-engine[''"]?:\s*[''"]?[\^~]?0\.\d(?![\d])'
|
|
13
|
+
- id: prisma-7-commands-answer-v7-command
|
|
14
|
+
summary: |
|
|
15
|
+
A Prisma 7 command the ORM answers, such as `prisma migrate dev`, now fails with `CLI.V7_COMMAND` instead of `CLI.COMMAND_MOVED`, still with exit code 2.
|
|
16
|
+
- id: planner-warnings-json-field
|
|
17
|
+
summary: |
|
|
18
|
+
In `--json` output, `db update` and `db init` list the planner's warnings under `plannerWarnings` instead of `warnings`, as `migration plan` does.
|
|
19
|
+
- id: mongo-fields-take-a-type
|
|
20
|
+
summary: |
|
|
21
|
+
The MongoDB TypeScript builder writes a field as `field.scalar(type.X())`, where `type` holds the type constructors the target and extension packs contribute, as PSL names them: `field.objectId()` is now `field.scalar(type.ObjectId())`, `field.date()` is `field.scalar(type.DateTime())` (on MongoDB `Date` is now a calendar date), `field.vector({ typeParams: { length: 3 } })` is `field.scalar(type.Vector(3))`, and `field.scalar('mongo/string@1')` is `field.scalar(type.String())`. `field.objectId()`, `field.string()`, `field.double()`, `field.int32()`, `field.bool()`, `field.date()`, `field.int64()`, `field.int64Number()`, `field.decimal128()`, `field.binary()`, `field.json()`, `field.bson()`, `field.vector()` and `field.scalar(codecId)` are removed. `type` comes from the `defineContract` callback, or from `@prisma/orm-mongo/contract-builder`. Run `scripts/mongo-type-helpers/rewrite-mongo-field-types.ts` to rewrite them. The contract does not change. The detection matches MongoDB contract sources that call a removed helper.
|
|
22
|
+
detection:
|
|
23
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
24
|
+
matches:
|
|
25
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-(?:mongo|family-mongo/contract-ts)/contract-builder[\x27"])[\s\S]*(?<![\w$])field\s*\.\s*(?:(?:objectId|string|double|int32|bool|date|int64|int64Number|decimal128|binary|json|bson|vector)\s*\(|scalar\s*\(\s*[\x27"])'
|
|
26
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-(?:mongo|family-mongo/contract-ts)/contract-builder[\x27"])(?=[\s\S]*\bfield\s*(?:as\s+|:\s*)[A-Za-z_$][\w$]*)[\s\S]*\.\s*(?:(?:objectId|string|double|int32|bool|date|int64|int64Number|decimal128|binary|json|bson|vector)\s*\(|scalar\s*\(\s*[\x27"])'
|
|
27
|
+
script: ./scripts/mongo-type-helpers/rewrite-mongo-field-types.ts
|
|
28
|
+
- id: mongo-date-is-a-calendar-date
|
|
29
|
+
summary: |
|
|
30
|
+
On MongoDB, `Date` is now a calendar date, stored as a BSON date at midnight UTC and read as a string such as `"2024-02-29"`. `DateTime` with no arguments is what `Date` was: an instant read as a JavaScript `Date` (`mongo/date@1`). Rewrite `Date` to `DateTime` in MongoDB schemas and `type.Date()` to `type.DateTime()` in MongoDB TypeScript contracts with `scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts`. The contract does not change.
|
|
31
|
+
detection:
|
|
32
|
+
glob: "**/*.{prisma,ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
33
|
+
matches:
|
|
34
|
+
- '(?<![\s\S])(?![\s\S]*(?<![\w$])datasource[ \t]+\w+[ \t]*\{)(?=[\s\S]*(?:(?<![\w$])ObjectId(?![\w$])|@map\("_id"\)))[\s\S]*\n[ \t]+[A-Za-z_]\w*[ \t]+(?:=[ \t]*)?Date(?![\w$])'
|
|
35
|
+
- '(?<![\s\S])(?=[\s\S]*@(?:prisma/orm-(?:mongo|family-mongo/contract-ts)|internal/mongo)/contract-builder[\x27"])[\s\S]*(?<![\w$])[A-Za-z_$][\w$]*\s*\.\s*Date\s*\('
|
|
36
|
+
- '(?<![\s\S])(?=[\s\S]*[\x27"]@prisma/orm-mongo/config[\x27"])[\s\S]*(?<![\w$])contract\s*:\s*[\x27"][^\x27"]+?(?<!\.ts)[\x27"]'
|
|
37
|
+
script: ./scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts
|
|
38
|
+
- id: temporal-polyfill-is-a-peer-dependency-of-mongo
|
|
39
|
+
summary: |
|
|
40
|
+
`temporal-polyfill` is now a required peer dependency of `@prisma/orm-mongo` and `@prisma/orm-target-mongo`. The MongoDB control plane imports it, because `DateTime(as: temporal)`, `Date(as: temporal)` and `Time(as: temporal)` read `Temporal` values. npm, pnpm and bun install it automatically (npm with `legacy-peer-deps` set does not: see `temporal-polyfill-with-legacy-peer-deps`). A project that installs with Yarn must add `temporal-polyfill` (`^1.0.4`) to its own dependencies.
|
|
41
|
+
detection:
|
|
42
|
+
glob: "**/yarn.lock"
|
|
43
|
+
contains:
|
|
44
|
+
- "@prisma/orm-mongo@"
|
|
45
|
+
- "@prisma/orm-target-mongo@"
|
|
46
|
+
anyMatch: true
|
|
47
|
+
- id: temporal-polyfill-with-legacy-peer-deps
|
|
48
|
+
summary: |
|
|
49
|
+
npm does not install peer dependencies when `legacy-peer-deps` is set, so a MongoDB project that installs with npm and that setting must add `temporal-polyfill` (`^1.0.4`) to its own dependencies, as a Yarn project must. The MongoDB control plane imports it. The setting can come from an `.npmrc`, the user's npm config or the environment, which no file shows, so the detection matches every `package.json` that depends on `@prisma/orm-mongo` or `@prisma/orm-target-mongo`, and the step checks the setting npm uses.
|
|
50
|
+
detection:
|
|
51
|
+
glob: "**/package.json"
|
|
52
|
+
contains:
|
|
53
|
+
- '"@prisma/orm-mongo"'
|
|
54
|
+
- '"@prisma/orm-target-mongo"'
|
|
55
|
+
anyMatch: true
|
|
56
|
+
- id: mongo-validator-change-checks-documents
|
|
57
|
+
summary: |
|
|
58
|
+
A MongoDB validator change that `migration plan` or `db update` writes now checks the documents first, and the apply stops while a document does not fit the new validator. Existing `migration.ts` files are unchanged.
|
|
59
|
+
- id: mongo-type-change-is-asked
|
|
60
|
+
summary: |
|
|
61
|
+
A MongoDB field type change that can lose values is now a question, answered with `--convert` or `--delete`, as on SQL. A cast that keeps every value, such as `Int` to `Int64`, is planned with nothing asked.
|
|
62
|
+
- id: mongo-new-required-field-gets-temporary-value
|
|
63
|
+
summary: |
|
|
64
|
+
A new required MongoDB field is now filled with a temporary value in the documents that lack it, as on SQL, unless `--backfill` names it.
|
|
65
|
+
- id: create-extension-not-exported
|
|
66
|
+
summary: |
|
|
67
|
+
`@prisma/orm-postgres/migration` no longer exports the free function `createExtension`, which a `migration.ts` could not call correctly since 8.0.0-rc.22. A `migration.ts` that imports it now fails at once with `does not provide an export named 'createExtension'`. Call the method on the migration class instead: `createExtension('btree_gist')` becomes `this.createExtension({ extension: 'btree_gist' })`. The migration's `ops.json` does not change, so there is no need to run `node migration.ts` again.
|
|
68
|
+
detection:
|
|
69
|
+
glob: "**/migration.{ts,mts}"
|
|
70
|
+
matches:
|
|
71
|
+
- '(?<![\w$.])createExtension\s*\('
|
|
72
|
+
- '\bimport\s*\{[^}]*(?<![\w$])createExtension(?![\w$])[^}]*\}\s*from\s*[\x27"]@prisma/orm-postgres/migration[\x27"]'
|
|
73
|
+
- id: data-transform-not-exported
|
|
74
|
+
summary: |
|
|
75
|
+
`@prisma/orm-postgres/migration` no longer exports the free function `dataTransform`, which took an internal fourth argument a `migration.ts` cannot pass. A `migration.ts` that imports it now fails at once with `does not provide an export named 'dataTransform'`. Call the method on the migration class instead: `this.dataTransform(endContract, name, { check, run })`. The planner writes the method. The types `DataTransformClosure` and `DataTransformOptions` are still exported.
|
|
76
|
+
detection:
|
|
77
|
+
glob: "**/migration.{ts,mts}"
|
|
78
|
+
matches:
|
|
79
|
+
- '\bimport\s*\{[^}]*(?<![\w$])dataTransform(?![\w$])[^}]*\}\s*from\s*[\x27"]@prisma/orm-postgres/migration[\x27"]'
|
|
80
|
+
- id: raw-parts-hold-statement-asts
|
|
81
|
+
summary: |
|
|
82
|
+
The `parts` of `RawExpr` and `RawQueryAst` (from `@prisma/orm-family-sql/relational-core/ast`) are now `ReadonlyArray<RawPart>`, where `RawPart = string | AnyExpression | SelectAst | InsertAst | UpdateAst | DeleteAst`. A raw template places a builder query, or a builder mutation after `.returning()`, as one statement part. Code that walks `parts` and treats every non-string part as an expression must handle the four statement kinds. The detection matches files that import these nodes and read `.parts`.
|
|
83
|
+
detection:
|
|
84
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
85
|
+
matches:
|
|
86
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-family-sql/relational-core/(?:ast|expression)[\x27"])(?=[\s\S]*(?<![\w$])(?:RawExpr|RawQueryAst|RawPart)(?![\w$]))[\s\S]*\.parts(?![\w$])'
|
|
87
|
+
- id: mysql-explicit-isolation-default
|
|
88
|
+
summary: Configure ReadCommitted explicitly if MySQL callbacks relied on the previous session-wide override.
|
|
89
|
+
- id: contract-artifacts-restamp
|
|
90
|
+
summary: |
|
|
91
|
+
An extension that writes its own package version into the contracts it emits, such as the Supabase extension, now writes 8.0.0-rc.24. Run `contract emit` once after upgrading so the emitted `contract.json` and `contract.d.ts` match the installed extension.
|
|
92
|
+
detection:
|
|
93
|
+
glob: "**/contract.json"
|
|
94
|
+
contains:
|
|
95
|
+
- '"version": "8.0.0-rc.23"'
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
# 8.0.0-rc.23 → 8.0.0-rc.24 — User upgrade instructions
|
|
99
|
+
|
|
100
|
+
## Order of the steps
|
|
101
|
+
|
|
102
|
+
Do the steps in this order, and skip a step that does not apply to the project:
|
|
103
|
+
|
|
104
|
+
1. Upgrade the Prisma packages. A project that depends on `@prisma/cli-engine` itself moves it to `0.10.0` (`engine-pin-moves-to-0-10-0`). A MongoDB project that installs with Yarn, or with npm and `legacy-peer-deps`, adds `temporal-polyfill` to its dependencies (`temporal-polyfill-is-a-peer-dependency-of-mongo`, `temporal-polyfill-with-legacy-peer-deps`).
|
|
105
|
+
2. Change the MongoDB contract sources. Run the field-types script first (`mongo-fields-take-a-type`), then the date-types script (`mongo-date-is-a-calendar-date`). The first script writes `field.date()` as `field.scalar(type.DateTime())`, so the second has nothing left to do for it; the second rewrites `Date` to `DateTime` in MongoDB schemas.
|
|
106
|
+
3. Run `prisma contract emit` and commit what it writes. The MongoDB contracts must not change; the only change to expect is the extension version stamp (`contract-artifacts-restamp`).
|
|
107
|
+
4. In PostgreSQL `migration.ts` files, call `this.createExtension(...)` and `this.dataTransform(...)` instead of the free functions (`create-extension-not-exported`, `data-transform-not-exported`). Existing `ops.json` files do not change.
|
|
108
|
+
5. Change the remaining code: MySQL callback transactions that relied on READ COMMITTED (`mysql-explicit-isolation-default`), code that walks the `parts` of a raw SQL node (`raw-parts-hold-statement-asts`), and scripts that read the CLI's `--json` planner warnings or check for `CLI.COMMAND_MOVED` (`planner-warnings-json-field`, `prisma-7-commands-answer-v7-command`).
|
|
109
|
+
6. On MongoDB, the next `migration plan` or `db update` checks documents against a changed validator, asks about field type changes that can lose values, and fills new required fields with a temporary value. Read those three entries before planning the next schema change (`mongo-validator-change-checks-documents`, `mongo-type-change-is-asked`, `mongo-new-required-field-gets-temporary-value`).
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## The CLI moves to `@prisma/cli-engine` 0.10.0 and answers Prisma 7 commands with `CLI.V7_COMMAND`
|
|
113
|
+
|
|
114
|
+
### `engine-pin-moves-to-0-10-0`
|
|
115
|
+
|
|
116
|
+
For every file matched by `detection`, change the `@prisma/cli-engine` version (`0.9.0`, `^0.9.0` or any other 0.x below 0.10) to `0.10.0` and reinstall. Projects assembled by the `prisma` CLI resolve the engine automatically.
|
|
117
|
+
|
|
118
|
+
### `prisma-7-commands-answer-v7-command`
|
|
119
|
+
|
|
120
|
+
`prisma generate`, `validate`, `format`, `studio`, `db pull`, `db push`, `db seed`, `db execute` and the six `prisma migrate` commands fail with `CLI.V7_COMMAND`. The error names the Prisma 8 commands to run instead and their `--help`, or links the CLI docs when Prisma 8 has no equivalent. A script that checks for `CLI.COMMAND_MOVED` after running one of these commands checks for `CLI.V7_COMMAND` instead.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## The CLI's `--json` output lists planner warnings under `plannerWarnings`
|
|
124
|
+
|
|
125
|
+
### `planner-warnings-json-field`
|
|
126
|
+
|
|
127
|
+
A script that reads the planner's warnings from the `--json` result of `db update` or `db init` reads `plannerWarnings` instead of `warnings`. Each entry is unchanged: `kind`, `summary` and `why`. `migration plan --json` lists them under `plannerWarnings` too, and its `warnings` keeps its own messages, such as a default origin that forks the migration graph.
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## MongoDB fields take a type from `type`
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
// Before
|
|
134
|
+
export const contract = defineContract({}, ({ field, model }) => ({
|
|
135
|
+
models: {
|
|
136
|
+
Doc: model('Doc', {
|
|
137
|
+
fields: {
|
|
138
|
+
_id: field.objectId(),
|
|
139
|
+
embedding: field.vector({ typeParams: { length: 3 } }),
|
|
140
|
+
raw: field.scalar('mongo/bson@1'),
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
},
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
// After
|
|
147
|
+
export const contract = defineContract({}, ({ field, model, type }) => ({
|
|
148
|
+
models: {
|
|
149
|
+
Doc: model('Doc', {
|
|
150
|
+
fields: {
|
|
151
|
+
_id: field.scalar(type.ObjectId()),
|
|
152
|
+
embedding: field.scalar(type.Vector(3)),
|
|
153
|
+
raw: field.scalar(type.Bson()),
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
},
|
|
157
|
+
}));
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### `mongo-fields-take-a-type`
|
|
161
|
+
|
|
162
|
+
Commit your work first. The script reads your code with the TypeScript compiler, so the project needs `typescript` installed; a JavaScript project adds it as a dev dependency for the run. From the project root, run:
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
node <path-to-this-guide>/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Pass files or directories to limit it. The script prints a line for each call it leaves. Rewrite each one by hand, except where the line says the script cannot tell the `field` is the MongoDB builder's and it is not. Then type-check the project. The script neither changes nor reports a `field.scalar` call whose argument is computed, such as `field.scalar(codecIdOf(kind))`, because it cannot tell a codec id from a type there; the type check reports each one that passes a codec id, since `field.scalar` takes only a type now. Where the type check cannot see it, in plain JavaScript or with an argument typed `any`, `contract emit` refuses the call with `CONTRACT.ARGUMENT_INVALID`. Write those with `type.X()`.
|
|
169
|
+
|
|
170
|
+
A field written with an extension's codec id, such as `field.scalar('shout/text@1')`, is one the script reports: write the type constructor the extension contributes, such as `field.scalar(type.shout.Text())`.
|
|
171
|
+
|
|
172
|
+
MongoDB PSL gains `Vector` and `Vector(length)` for `mongo/vector@1`, which had no PSL name before. It now reads the arguments of a type call, so `Vector(3)` keeps its length. A type that takes no arguments, written with one, such as `String(5)`, used to have the argument ignored and is now refused with a message naming the argument; remove the argument.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## MongoDB: `Date` is a calendar date, and `temporal-polyfill` is a peer dependency
|
|
176
|
+
|
|
177
|
+
### `mongo-date-is-a-calendar-date`
|
|
178
|
+
|
|
179
|
+
```prisma
|
|
180
|
+
// Before: an instant
|
|
181
|
+
model Order {
|
|
182
|
+
id ObjectId @id @map("_id")
|
|
183
|
+
paidAt Date
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// After: the same instant, the same contract
|
|
187
|
+
model Order {
|
|
188
|
+
id ObjectId @id @map("_id")
|
|
189
|
+
paidAt DateTime
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
MongoDB now has the convenience date and time types PostgreSQL, SQLite and MySQL have. `Date` is the calendar date, so a field that holds an instant must be written `DateTime`. Commit your work first, then from the project root run:
|
|
194
|
+
|
|
195
|
+
```sh
|
|
196
|
+
node <path-to-this-guide>/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
It rewrites `Date` to `DateTime` in MongoDB schemas, including in `types {}` aliases, and `type.Date()` to `type.DateTime()` in MongoDB TypeScript contracts. No release had `type.Date()` for an instant, because MongoDB's `type` helpers ship in this release too; the script rewrites it for a contract written against an unreleased build that already had them. Pass files or directories to limit it. Fix by hand each line it reports, then run `prisma contract emit`: the contract must not change.
|
|
200
|
+
|
|
201
|
+
A field you miss still compiles. Its TypeScript type becomes `string`, and reading a document whose value has a time of day fails with an error that names the field. Worse, `@onCreate(now())` or `@onUpdate(now())` on it writes today's date at midnight UTC, losing the time, with no error, so check every generated timestamp field. A field that really holds a calendar date can stay `Date`, if every stored value is at midnight UTC; it then reads `"2024-02-29"` instead of a `Date`. A Prisma 6 schema read with `prisma6Schema` is not rewritten: its `DateTime` and `DateTime @db.Date` stay instants read as a JavaScript `Date`.
|
|
202
|
+
|
|
203
|
+
### `temporal-polyfill-is-a-peer-dependency-of-mongo`
|
|
204
|
+
|
|
205
|
+
For each Yarn project that `detection` matches, add `"temporal-polyfill": "^1.0.4"` to `dependencies` in the `package.json` that depends on `@prisma/orm-mongo` or `@prisma/orm-target-mongo`, then reinstall.
|
|
206
|
+
|
|
207
|
+
### `temporal-polyfill-with-legacy-peer-deps`
|
|
208
|
+
|
|
209
|
+
Skip this if the project installs with Yarn (see `temporal-polyfill-is-a-peer-dependency-of-mongo`), pnpm or bun. For a project that installs with npm, run `npm config get legacy-peer-deps` in the folder of each `package.json` that `detection` matches. It reports the setting npm uses there, from any `.npmrc`, the user's npm config or the `npm_config_legacy_peer_deps` environment variable. Where it prints `true`, or the project's install command passes `--legacy-peer-deps`, add `"temporal-polyfill": "^1.0.4"` to that `package.json`'s `dependencies`, then reinstall.
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## MongoDB plans rewrite the documents a schema change touches
|
|
213
|
+
|
|
214
|
+
### `mongo-validator-change-checks-documents`
|
|
215
|
+
|
|
216
|
+
Every validator change a new plan writes is `collMod(..., { ..., checkDocuments: true })`: as its own precheck, after the plan's rewrites, it checks that every document fits the new validator. When `db migrate` or `db update` stops with `MIGRATION.PRECHECK_FAILED` because documents do not fit:
|
|
217
|
+
|
|
218
|
+
1. Find them with the `mongosh` query the error prints, and change them so they fit the new validator. The old validator is still in place and may reject a document changed to the new shape, so an update that fixes one can skip document validation: write a `dataTransform` in `migration.ts`, or in `mongosh` run an update command with `bypassDocumentValidation: true`, such as `db.runCommand({ update: "users", updates: [{ q: { _id: … }, u: { $set: { … } } }], bypassDocumentValidation: true })`. Run the command again. For a field the change makes required, `migration plan --backfill Model.field` writes a step to fill it instead.
|
|
219
|
+
2. Or, under `db migrate`, apply the validator over them as before: set `checkDocuments` to `false` on that `collMod` in the migration's `migration.ts`, run the file with `node`, and run `db migrate` again. Those documents then fail their next update until they fit. `db update` writes no `migration.ts`, so there the documents must be fixed first.
|
|
220
|
+
|
|
221
|
+
Operations of the migration that ran before the validator change stay applied; a re-run skips them.
|
|
222
|
+
|
|
223
|
+
A database adopted from Prisma 6 has no validator, so its first plan adds one and checks every collection.
|
|
224
|
+
|
|
225
|
+
### `mongo-type-change-is-asked`
|
|
226
|
+
|
|
227
|
+
Where a plan now asks about a field, answer with `--delete Model.field`, which casts the values with `$convert` and fails on a value it cannot cast (a change such as `String` to `Boolean`, where `$convert` would turn `"false"` into `true`, has no cast and offers `--convert` only), or plan it with `migration plan --convert Model.field` and write the update in the `placeholder('Model.field:update')` slot of the data transform it writes.
|
|
228
|
+
|
|
229
|
+
### `mongo-new-required-field-gets-temporary-value`
|
|
230
|
+
|
|
231
|
+
To write your own value instead of the temporary one, plan the change with `migration plan --backfill Model.field` and write the update in the `placeholder('Model.field:update')` slot of the data transform it writes. A new required field under a unique index gets no temporary value, since every document would get the same one: on a collection with documents, the unique index build stops the apply first, because the documents that lack the field all hold `null`, and its error names `--backfill`. Plan it with `--backfill`.
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## `createExtension` and `dataTransform` are no longer free functions
|
|
235
|
+
|
|
236
|
+
### `create-extension-not-exported`
|
|
237
|
+
|
|
238
|
+
`@prisma/orm-postgres/migration` no longer exports `createExtension`. Since 8.0.0-rc.22 the free function took an internal argument that only the migration class can supply, so a `migration.ts` that called it failed with `Cannot read properties of undefined (reading 'lowerToExecuteRequest')`. Now the import fails at once instead.
|
|
239
|
+
|
|
240
|
+
In every `migration.ts` the detection matches, call the method and remove `createExtension` from the import:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
// Before
|
|
244
|
+
import { createExtension, Migration, MigrationCLI } from '@prisma/orm-postgres/migration';
|
|
245
|
+
|
|
246
|
+
override get operations() {
|
|
247
|
+
return [createExtension('btree_gist'), ...];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// After
|
|
251
|
+
import { Migration, MigrationCLI } from '@prisma/orm-postgres/migration';
|
|
252
|
+
|
|
253
|
+
override get operations() {
|
|
254
|
+
return [this.createExtension({ extension: 'btree_gist' }), ...];
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Without `schema`, the method creates the extension where the old function did: in the connection's current schema, unless the extension's control file names one. The migration's `ops.json` does not change, and there is no need to run `node migration.ts` again: `prisma db migrate` applies `ops.json` and does not load `migration.ts`.
|
|
259
|
+
|
|
260
|
+
### `data-transform-not-exported`
|
|
261
|
+
|
|
262
|
+
`@prisma/orm-postgres/migration` no longer exports the free function `dataTransform`. It took an internal fourth argument that only the migration class can supply, so a `migration.ts` could not call it correctly. Remove `dataTransform` from the import and call `this.dataTransform(endContract, name, { check, run })`, as the planner writes it. The types `DataTransformClosure` and `DataTransformOptions` are still exported.
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
## Raw parts can hold a statement AST
|
|
266
|
+
|
|
267
|
+
### `raw-parts-hold-statement-asts`
|
|
268
|
+
|
|
269
|
+
`RawExpr.parts` and `RawQueryAst.parts` used to hold strings and expression nodes. They now hold `RawPart`, which adds `SelectAst`, `InsertAst`, `UpdateAst` and `DeleteAst`: a builder query interpolated into `db.raw.sql` or `fns.raw` lands in the parts as its statement AST. A `RawQueryAst` interpolated into another raw template is still spread into the outer parts, so it never appears as a part.
|
|
270
|
+
|
|
271
|
+
In every file the detection matches, find each walk over `parts` that sends a non-string part to an expression handler, and give the statement kinds their own branch. Each statement AST has `kind` `'select'`, `'insert'`, `'update'` or `'delete'`, which no expression kind uses. A renderer renders a statement part with the function it uses for that statement at top level, with no parentheses:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
// Before
|
|
275
|
+
parts.map((part) => (typeof part === 'string' ? part : renderExpr(part, ctx))).join('');
|
|
276
|
+
|
|
277
|
+
// After
|
|
278
|
+
parts
|
|
279
|
+
.map((part) => {
|
|
280
|
+
if (typeof part === 'string') {
|
|
281
|
+
return part;
|
|
282
|
+
}
|
|
283
|
+
switch (part.kind) {
|
|
284
|
+
case 'select':
|
|
285
|
+
return renderSelect(part, ctx);
|
|
286
|
+
case 'insert':
|
|
287
|
+
return renderInsert(part, ctx);
|
|
288
|
+
case 'update':
|
|
289
|
+
return renderUpdate(part, ctx);
|
|
290
|
+
case 'delete':
|
|
291
|
+
return renderDelete(part, ctx);
|
|
292
|
+
default:
|
|
293
|
+
return renderExpr(part, ctx);
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
.join('');
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
A walker that only needs parameters can call `part.collectParamRefs()` on every non-string part, since the statement ASTs have it too. `RawQueryAst.collectParamRefs()` and `rewrite()` already reach into statement parts.
|
|
300
|
+
|
|
301
|
+
`ExpressionFolder` has a new optional `mutation` arm, called for an INSERT, UPDATE or DELETE part of a `RawExpr`, beside the `select` arm called for a SELECT part. A folder that leaves it out gets `empty` for a mutation part, so existing folders compile unchanged; add the arm where a mutation's contents matter.
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
## Preserve an intentional MySQL callback isolation choice
|
|
305
|
+
|
|
306
|
+
### `mysql-explicit-isolation-default`
|
|
307
|
+
|
|
308
|
+
MySQL no longer sets every session to READ COMMITTED. Unconfigured explicit callback transactions now use the server/session default. If application code relied on the previous override, add `transactionOptions: { isolationLevel: 'ReadCommitted' }` to its MySQL client factory, or pass `{ isolationLevel: 'ReadCommitted' }` as the second argument to the relevant `transaction(callback, options)` calls.
|
|
309
|
+
|
|
310
|
+
You can also import `{ IsolationLevel }` from `@prisma/orm-mysql/runtime` and use `IsolationLevel.ReadCommitted` in either position. This optional constant syntax does not require migrating existing strings.
|
|
311
|
+
|
|
312
|
+
A defined per-call level overrides the factory level. An omitted or undefined level inherits it; null does not reset defaults and is rejected. ORM-owned implicit transactions continue to use ReadCommitted, independently of callback options. Manual lower-level transactions do not inherit factory defaults.
|
|
313
|
+
|
|
314
|
+
Verify behavior against the deployment's configured database default and concurrent transactions. Do not assume the server default is RepeatableRead. This change does not introduce batch transactions, timeout/maxWait options, P2028 handling or retry behavior.
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
## `contract-artifacts-restamp`
|
|
318
|
+
|
|
319
|
+
For every `contract.json` matched by `detection`, run the project's emit command (`prisma contract emit`, or the project's `contract:emit` script) once after upgrading. This entry accounts for the extension's embedded `version` moving to `8.0.0-rc.24`; any other difference in the emitted files comes from an earlier entry in this guide.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Rewrites `Date` to `DateTime` in MongoDB schemas and `type.Date()` to `type.DateTime()` in MongoDB TypeScript contracts. On MongoDB, `Date` was an instant read as a JavaScript `Date`; it is now a calendar date, and `DateTime` with no arguments is what `Date` was, so the contract does not change.
|
|
4
|
+
*
|
|
5
|
+
* A `.prisma` file is a MongoDB schema when the nearest `prisma.config.*` at or above its folder imports `@prisma/orm-mongo`. So is any file such a config names as its `contract`, whatever its extension, except a `.ts` contract. A schema with a `datasource` block, which is a Prisma 6 or Prisma 7 schema, and one a config reads with `prisma6Schema(...)` are left alone. A TypeScript or JavaScript file is a MongoDB contract when it imports a MongoDB contract builder entry; in it, a call of `Date` on `type`, or on a name `type` is imported or destructured as, becomes `DateTime`.
|
|
6
|
+
*
|
|
7
|
+
* A schema that declares a model, type or enum named `Date`, in any of its files, is left as it is, because `Date` there names that declaration. The script prints one line per file it changes, and one line per place it leaves for a person: a schema that declares its own `Date`, and a call of `Date` on a name it cannot tell is the `type` of a MongoDB contract builder.
|
|
8
|
+
*
|
|
9
|
+
* Usage: node rewrite-mongo-date-types.ts [file or directory ...]
|
|
10
|
+
*
|
|
11
|
+
* The paths default to the working directory, which is also where the script looks for `prisma.config.*` files. In a directory it reads every file outside `node_modules`, `.git`, `dist` and `build`.
|
|
12
|
+
*/
|
|
13
|
+
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
15
|
+
|
|
16
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', 'build']);
|
|
17
|
+
const CONFIG_FILE = /^prisma\.config\.(?:[cm]?ts|[cm]?js)$/;
|
|
18
|
+
const SOURCE_FILE = /\.(?:[cm]?ts|tsx|[cm]?js|jsx)$/;
|
|
19
|
+
const MONGO_CONFIG_IMPORT = /['"]@prisma\/orm-mongo(?:\/[\w/-]*)?['"]/;
|
|
20
|
+
const CONTRACT_PATH = /\bcontract\s*:\s*['"]([^'"]+?)(?<!\.ts)['"]/g;
|
|
21
|
+
const PRISMA6_SCHEMA_PATH = /\bprisma6Schema\s*\(\s*['"]([^'"]+)['"]/g;
|
|
22
|
+
const DATASOURCE_BLOCK = /(?:^|\n)[ \t]*datasource[ \t]+\w+[ \t]*\{/;
|
|
23
|
+
const FIELD_OR_ALIAS_OF_TYPE_DATE = /^([ \t]+[A-Za-z_]\w*[ \t]+(?:=[ \t]*)?)Date(?![\w$])/gm;
|
|
24
|
+
const MONGO_BUILDER_IMPORT =
|
|
25
|
+
/['"](?:@prisma\/orm-mongo|@prisma\/orm-family-mongo\/contract-ts|@internal\/mongo|@internal\/mongo-contract-ts)\/contract-builder['"]/;
|
|
26
|
+
const TYPE_ALIASES = /(?<![\w$])type\s*(?:as|:)\s*([A-Za-z_$][\w$]*)/g;
|
|
27
|
+
const DECLARES_DATE = /(?:^|\n)[ \t]*(?:model|type|enum|view)[ \t]+Date[ \t]*\{/;
|
|
28
|
+
const OTHER_DATE_CALL = /(?<![\w$])[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*\.\s*Date\s*\(/g;
|
|
29
|
+
|
|
30
|
+
function filesUnder(path: string): string[] {
|
|
31
|
+
if (!statSync(path).isDirectory()) return [path];
|
|
32
|
+
return readdirSync(path, { withFileTypes: true }).flatMap((entry) => {
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
return SKIPPED_DIRECTORIES.has(entry.name) ? [] : filesUnder(join(path, entry.name));
|
|
35
|
+
}
|
|
36
|
+
return entry.isFile() ? [join(path, entry.name)] : [];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Whether a file is `path`, or one a glob `path` names, as the CLI expands a `contract` glob: `*` and `?` within a folder, `**` across folders, `{a,b}` for either. */
|
|
41
|
+
function pathMatcher(path: string): (file: string) => boolean {
|
|
42
|
+
if (!/[*?{]/.test(path)) return (file) => file === path;
|
|
43
|
+
const glob = path.split(sep).join('/');
|
|
44
|
+
let source = '';
|
|
45
|
+
for (let index = 0; index < glob.length; index += 1) {
|
|
46
|
+
const char = glob[index] ?? '';
|
|
47
|
+
if (glob.startsWith('**/', index)) {
|
|
48
|
+
source += '(?:.*/)?';
|
|
49
|
+
index += 2;
|
|
50
|
+
} else if (glob.startsWith('**', index)) {
|
|
51
|
+
source += '.*';
|
|
52
|
+
index += 1;
|
|
53
|
+
} else if (char === '*') source += '[^/]*';
|
|
54
|
+
else if (char === '?') source += '[^/]';
|
|
55
|
+
else if (char === '{') source += '(?:';
|
|
56
|
+
else if (char === '}') source += ')';
|
|
57
|
+
else if (char === ',') source += '|';
|
|
58
|
+
else source += char.replace(/[.+^$()|[\]\\]/g, '\\$&');
|
|
59
|
+
}
|
|
60
|
+
const pattern = new RegExp(`^${source}$`);
|
|
61
|
+
return (file) => pattern.test(file.split(sep).join('/'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface Config {
|
|
65
|
+
readonly dir: string;
|
|
66
|
+
readonly mongo: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readConfigs(root: string): {
|
|
70
|
+
readonly configs: readonly Config[];
|
|
71
|
+
readonly named: ReadonlyArray<{
|
|
72
|
+
readonly matches: (file: string) => boolean;
|
|
73
|
+
readonly dir: string;
|
|
74
|
+
}>;
|
|
75
|
+
readonly prisma6: ReadonlySet<string>;
|
|
76
|
+
} {
|
|
77
|
+
const configs: Config[] = [];
|
|
78
|
+
const named: { matches: (file: string) => boolean; dir: string }[] = [];
|
|
79
|
+
const prisma6 = new Set<string>();
|
|
80
|
+
for (const file of filesUnder(root)) {
|
|
81
|
+
if (!CONFIG_FILE.test(file.split(sep).at(-1) ?? '')) continue;
|
|
82
|
+
const text = readFileSync(file, 'utf8');
|
|
83
|
+
const dir = dirname(file);
|
|
84
|
+
const mongo = MONGO_CONFIG_IMPORT.test(text);
|
|
85
|
+
configs.push({ dir, mongo });
|
|
86
|
+
if (!mongo) continue;
|
|
87
|
+
for (const [, path = ''] of text.matchAll(CONTRACT_PATH)) {
|
|
88
|
+
named.push({ matches: pathMatcher(resolve(dir, path)), dir });
|
|
89
|
+
}
|
|
90
|
+
for (const [, path = ''] of text.matchAll(PRISMA6_SCHEMA_PATH)) prisma6.add(resolve(dir, path));
|
|
91
|
+
}
|
|
92
|
+
return { configs, named, prisma6 };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isInside(file: string, dir: string): boolean {
|
|
96
|
+
return file.startsWith(`${dir}${sep}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The folder of the MongoDB config whose schema `file` is part of, or `undefined` when it is no MongoDB schema. A schema's files share it, so a model one file declares is seen from every other. */
|
|
100
|
+
function mongoSchemaOf(file: string, configs: ReturnType<typeof readConfigs>): string | undefined {
|
|
101
|
+
if (configs.prisma6.has(file)) return undefined;
|
|
102
|
+
const namedBy = configs.named.find((entry) => entry.matches(file));
|
|
103
|
+
if (namedBy !== undefined) return namedBy.dir;
|
|
104
|
+
const nearest = configs.configs
|
|
105
|
+
.filter((config) => isInside(file, config.dir))
|
|
106
|
+
.sort((a, b) => b.dir.length - a.dir.length)[0];
|
|
107
|
+
return nearest?.mongo === true ? nearest.dir : undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Where a schema declares its own model, type or enum named `Date`. */
|
|
111
|
+
interface DateDeclaration {
|
|
112
|
+
readonly file: string;
|
|
113
|
+
readonly line: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The first declaration of `Date` in each MongoDB schema, by its config's folder, read from every schema file under `root`. */
|
|
117
|
+
function dateDeclarations(
|
|
118
|
+
schemaFiles: readonly string[],
|
|
119
|
+
configs: ReturnType<typeof readConfigs>,
|
|
120
|
+
): ReadonlyMap<string, DateDeclaration> {
|
|
121
|
+
const declarations = new Map<string, DateDeclaration>();
|
|
122
|
+
for (const file of schemaFiles) {
|
|
123
|
+
const schema = mongoSchemaOf(file, configs);
|
|
124
|
+
if (schema === undefined || declarations.has(schema)) continue;
|
|
125
|
+
const text = readFileSync(file, 'utf8');
|
|
126
|
+
const declared = DATASOURCE_BLOCK.test(text) ? null : DECLARES_DATE.exec(text);
|
|
127
|
+
if (declared !== null) {
|
|
128
|
+
declarations.set(schema, {
|
|
129
|
+
file,
|
|
130
|
+
line: lineOf(text, declared.index + declared[0].indexOf('Date')),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return declarations;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** What a rewrite did: the new text, how many places it rewrote, and the lines it left for a person, each with the reason. */
|
|
138
|
+
interface Rewrite {
|
|
139
|
+
readonly text: string;
|
|
140
|
+
readonly count: number;
|
|
141
|
+
readonly left: readonly string[];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const UNCHANGED = (text: string): Rewrite => ({ text, count: 0, left: [] });
|
|
145
|
+
|
|
146
|
+
function lineOf(text: string, offset: number): number {
|
|
147
|
+
return text.slice(0, offset).split('\n').length;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function rewriteSchema(text: string, declaration: DateDeclaration | undefined): Rewrite {
|
|
151
|
+
if (DATASOURCE_BLOCK.test(text)) return UNCHANGED(text);
|
|
152
|
+
if (declaration !== undefined) {
|
|
153
|
+
const [first] = text.matchAll(FIELD_OR_ALIAS_OF_TYPE_DATE);
|
|
154
|
+
return first === undefined
|
|
155
|
+
? UNCHANGED(text)
|
|
156
|
+
: {
|
|
157
|
+
text,
|
|
158
|
+
count: 0,
|
|
159
|
+
left: [
|
|
160
|
+
`line ${lineOf(text, first.index + first[0].length - 'Date'.length)}: Date names the Date declared in ${relative(root, declaration.file)} line ${declaration.line}, not MongoDB's date; the script leaves this schema as it is`,
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
let count = 0;
|
|
165
|
+
const rewritten = text.replace(FIELD_OR_ALIAS_OF_TYPE_DATE, (_whole, before: string) => {
|
|
166
|
+
count += 1;
|
|
167
|
+
return `${before}DateTime`;
|
|
168
|
+
});
|
|
169
|
+
return { text: rewritten, count, left: [] };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function rewriteContract(text: string): Rewrite {
|
|
173
|
+
if (!MONGO_BUILDER_IMPORT.test(text)) return UNCHANGED(text);
|
|
174
|
+
const receivers = new Set(['type', ...[...text.matchAll(TYPE_ALIASES)].map(([, name]) => name)]);
|
|
175
|
+
const call = new RegExp(
|
|
176
|
+
`(?<![\\w$])((?:${[...receivers].join('|').replaceAll('$', '\\$')})\\s*\\.\\s*)Date(\\s*\\()`,
|
|
177
|
+
'g',
|
|
178
|
+
);
|
|
179
|
+
let count = 0;
|
|
180
|
+
const rewritten = text.replace(call, (_whole, before: string, after: string) => {
|
|
181
|
+
count += 1;
|
|
182
|
+
return `${before}DateTime${after}`;
|
|
183
|
+
});
|
|
184
|
+
const left = [...rewritten.matchAll(OTHER_DATE_CALL)].map(
|
|
185
|
+
(match) =>
|
|
186
|
+
`line ${lineOf(rewritten, match.index)}: ${match[0].trim()}): the script cannot tell this is the type of a MongoDB contract builder; if it is, write DateTime`,
|
|
187
|
+
);
|
|
188
|
+
return { text: rewritten, count, left };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const root = process.cwd();
|
|
192
|
+
const configs = readConfigs(root);
|
|
193
|
+
const isSchemaFile = (file: string) =>
|
|
194
|
+
file.endsWith('.prisma') || configs.named.some((entry) => entry.matches(file));
|
|
195
|
+
const declarations = dateDeclarations(filesUnder(root).filter(isSchemaFile), configs);
|
|
196
|
+
const paths = process.argv.slice(2);
|
|
197
|
+
const files = (paths.length === 0 ? [root] : paths.map((path) => resolve(root, path))).flatMap(
|
|
198
|
+
filesUnder,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
let changed = 0;
|
|
202
|
+
for (const file of [...new Set(files)].sort()) {
|
|
203
|
+
const isSchema = isSchemaFile(file);
|
|
204
|
+
if (!isSchema && !SOURCE_FILE.test(file)) continue;
|
|
205
|
+
const schema = isSchema ? mongoSchemaOf(file, configs) : undefined;
|
|
206
|
+
if (isSchema && schema === undefined) continue;
|
|
207
|
+
const text = readFileSync(file, 'utf8');
|
|
208
|
+
const result = isSchema
|
|
209
|
+
? rewriteSchema(text, schema === undefined ? undefined : declarations.get(schema))
|
|
210
|
+
: rewriteContract(text);
|
|
211
|
+
const name = relative(root, file);
|
|
212
|
+
if (result.count > 0) {
|
|
213
|
+
writeFileSync(file, result.text);
|
|
214
|
+
changed += 1;
|
|
215
|
+
const what = isSchema ? 'field type' : 'type.Date() call';
|
|
216
|
+
console.log(`${name}: rewrote ${result.count} ${what}${result.count === 1 ? '' : 's'}.`);
|
|
217
|
+
}
|
|
218
|
+
for (const line of result.left) console.log(`${name}: ${line}.`);
|
|
219
|
+
}
|
|
220
|
+
console.log(`Changed ${changed} file${changed === 1 ? '' : 's'}.`);
|