@hublo/sentinel 1.7.0-alpha.21 → 1.7.0-alpha.22
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/README.md +2 -1
- package/dist/bin/sentinel.js +9 -37
- package/dist/{chunk-UVXXEAHU.js → chunk-F3Q3JQJ6.js} +6 -4
- package/dist/{chunk-XTBHIKFG.js → chunk-JT7ZMH44.js} +5 -5
- package/dist/chunk-JT7ZMH44.js.map +1 -0
- package/dist/{chunk-BBNABWZ6.js → chunk-LX7EG6PJ.js} +2 -2
- package/dist/chunk-LX7EG6PJ.js.map +1 -0
- package/dist/chunk-NGLEGAEN.js +190 -0
- package/dist/chunk-NGLEGAEN.js.map +1 -0
- package/dist/{chunk-J2RMARWP.js → chunk-PMRL4MH6.js} +2 -2
- package/dist/{chunk-RI7R3S3T.js → chunk-VSUHHETH.js} +7701 -6601
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/roles/sql/config.d.ts +68 -0
- package/dist/roles/sql/config.js +8 -0
- package/dist/roles/static-analysis/config.js +1 -1
- package/dist/roles/test/setup/jest-parity.js +2 -2
- package/dist/roles/test/setup/workspace-entry.js +2 -2
- package/dist/{validate-YCTNTNFT.js → validate-IES226NX.js} +2 -2
- package/docs/sql-adoption.md +573 -0
- package/docs/static-analysis-study.md +10 -49
- package/docs/typescript-traces.md +142 -140
- package/docs/using-sentinel.md +2 -1
- package/package.json +5 -4
- package/dist/chunk-BBNABWZ6.js.map +0 -1
- package/dist/chunk-XTBHIKFG.js.map +0 -1
- package/dist/chunk-XYOIXC6A.js +0 -126
- package/dist/chunk-XYOIXC6A.js.map +0 -1
- package/dist/roles/code-churn/config.d.ts +0 -92
- package/dist/roles/code-churn/config.js +0 -10
- package/docs/code-churn-adoption.md +0 -237
- /package/dist/{chunk-J2RMARWP.js.map → chunk-PMRL4MH6.js.map} +0 -0
- /package/dist/roles/{code-churn → sql}/config.js.map +0 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
# SQL adoption cheat sheet
|
|
2
|
+
|
|
3
|
+
A quick reference for adopting the sentinel `sql` role on a module, for knowing what it checks, and
|
|
4
|
+
for moving a rule's level in `sql.config.mjs`. Why the role exists, and the measurements behind
|
|
5
|
+
its scope, are in [`sql-verification-study.md`](sql-verification-study.md); this page is what you
|
|
6
|
+
need to run it.
|
|
7
|
+
|
|
8
|
+
The role reads what a branch adds or changes:
|
|
9
|
+
|
|
10
|
+
- **the Prisma migrations** (`**/migrations/*/migration.sql`), checked by
|
|
11
|
+
[squawk](https://squawkhq.com) 2.72.0 against PostgreSQL 16.8;
|
|
12
|
+
- **every call that takes SQL text** in the module's TypeScript, checked by sentinel's own rules:
|
|
13
|
+
`$queryRawUnsafe` / `$executeRawUnsafe`, a `pg` `query` and a postgres.js `unsafe` under
|
|
14
|
+
`unsafe-sql-pasted-value`; the `Prisma.raw` and `Prisma.join` fragments under
|
|
15
|
+
`unsafe-sql-raw-fragment`. The table of [every entry point](#every-way-to-send-sql-text-and-what-reads-it)
|
|
16
|
+
says which are read and why the others need not be.
|
|
17
|
+
|
|
18
|
+
**Every finding is a warning until the module decides otherwise.** Nothing fails a run by default,
|
|
19
|
+
so adopting the role, or a sentinel upgrade that brings a new squawk rule, never turns a module red.
|
|
20
|
+
A module that wants a rule to block sets it to `error` (see [Rule levels](#rule-levels)).
|
|
21
|
+
|
|
22
|
+
## Adopt a module in two steps
|
|
23
|
+
|
|
24
|
+
Run from the **module's own directory**, the one that holds `prisma/migrations` or the raw SQL
|
|
25
|
+
calls. You do not need to install sentinel first: use `npx --yes` for a one-off.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# 1. write the module's config + the pinned devDependency
|
|
29
|
+
cd apps/.../<module>
|
|
30
|
+
npx --yes @hublo/sentinel@<version> --init --sql
|
|
31
|
+
|
|
32
|
+
# 2. fetch what step 1 declared
|
|
33
|
+
pnpm install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`--init` writes `sql.config.mjs`, adds the three scripts below and the `sql` nx target to the
|
|
37
|
+
module's `package.json`, and pins `@hublo/sentinel` into its `devDependencies`. It prints:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
wrote sql.config.mjs
|
|
41
|
+
wrote package.json
|
|
42
|
+
added sql.config.mjs; added the 3 `sql` scripts; every finding is a warning while the role is being adopted
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**A service that holds its database project: adopt both.** Eleven services of the monorepo keep
|
|
46
|
+
their Prisma project in `src/app/database`, a module of its own (`project.json` or `package.json`)
|
|
47
|
+
nested in the service. The migrations live in the **database project**, and the raw SQL calls in
|
|
48
|
+
the **service**: on `recruitment`, 29 files of raw SQL sit in the service and none in its database
|
|
49
|
+
project. So adopt the database project, **and the service** when its code makes raw SQL calls.
|
|
50
|
+
`--init` on the database project says so, with the files and the command:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
the module holding this one (../../..) makes raw SQL calls in 29 file(s) this module does not read: scripts/backfill-…, src/domains/…, … and 26 more. Adopt it too, from its directory: npx --yes @hublo/sentinel@<version> --init --sql
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`--init` on the service says the other half, whichever way round the two are adopted:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
131 migration(s) of this module belong to the project at src/app/database, which has not adopted the role: this module reads them. Once that project adopts it, they are reported there instead, from its directory: npx --yes @hublo/sentinel@<version> --init --sql
|
|
60
|
+
the project at src/app/database adopted the role itself: its 131 migration(s) are reported there, not here.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A module never reads a nested module that adopted the role itself, so nothing is reported twice;
|
|
64
|
+
while the nested one has not adopted, its parent reads its files, so nothing is read by no one.
|
|
65
|
+
Every `--run` of the service also says when its nested project reports the migrations, so "no
|
|
66
|
+
migration in this module" never reads as migrations nobody guards.
|
|
67
|
+
|
|
68
|
+
A module that holds no migration and no raw SQL call is skipped by name: there is nothing for the
|
|
69
|
+
role to read. An existing `sql.config.mjs` is the team's and is never rewritten by a re-init.
|
|
70
|
+
|
|
71
|
+
## Everyday use
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pnpm run sql # the summary, in your terminal. Writes nothing
|
|
75
|
+
pnpm run sql:json # sql-report/sql.json, for a machine
|
|
76
|
+
pnpm run sql:html # sql-report/sql.html, for a reader
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or without the scripts:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
sentinel --run --sql # same as the first script
|
|
83
|
+
sentinel --run --sql --output markdown # sql-report/sql.md, the pull-request recap
|
|
84
|
+
sentinel --inspect --sql --json # every setting and every rule's level, without running
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## What it reads: only what the branch adds or changes
|
|
88
|
+
|
|
89
|
+
The role compares the branch with `origin/main` and reads the migrations and the TypeScript files
|
|
90
|
+
the branch **adds or modifies**. An old migration has already run in production; reporting it again
|
|
91
|
+
on every pull request would bury the one that has not. The console says what was read and what
|
|
92
|
+
was not:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
read 1 migration(s) this branch adds or changes, compared with origin/main at 63d1ee7. The 1 other(s) in this module are unchanged and not read.
|
|
96
|
+
checked 1 call(s) taking SQL text ($queryRawUnsafe / $executeRawUnsafe, pg, postgres) and 2 Prisma fragment(s) (Prisma.raw, Prisma.join) in the 2 file(s) this branch adds or changes.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This is how the role reads, not a setting.
|
|
100
|
+
|
|
101
|
+
**Each migration is read the way Prisma runs it.** Prisma runs a file of one statement as it is,
|
|
102
|
+
and a file of several inside one transaction. So a file of several statements is read as running in
|
|
103
|
+
a transaction, and squawk reports what PostgreSQL refuses there:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
SET lock_timeout = '5s';
|
|
107
|
+
CREATE INDEX CONCURRENTLY "mission_x_idx" ON "Mission" ("x");
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
passes in alpha.10 and fails the deploy (P3018, then every next deploy refused until
|
|
111
|
+
`prisma migrate resolve`), proven on PostgreSQL 16.8 with Prisma 6.19.3. It is now reported as
|
|
112
|
+
`ban-concurrent-index-creation-in-transaction`, for `CREATE`, `DROP` and `REINDEX … CONCURRENTLY`
|
|
113
|
+
and `DETACH PARTITION … CONCURRENTLY`, with sentinel's note: give the statement a migration of its
|
|
114
|
+
own. A `CONCURRENTLY` alone in its file is fine, and not reported. The statements are counted by
|
|
115
|
+
squawk's own parser, so a `;` in a comment, a string or a function body is not a boundary.
|
|
116
|
+
|
|
117
|
+
Read that way, squawk no longer reports what concerns a table **created in the same file**: no
|
|
118
|
+
other session sees it before the file commits, so nothing waits on its locks. Measured on the
|
|
119
|
+
monorepo's 874 migrations: 932 findings of that kind are gone, and no finding on an existing table.
|
|
120
|
+
A file writing its own `BEGIN; … COMMIT;` applies under Prisma (proven), so squawk's
|
|
121
|
+
`transaction-nesting` is not reported for it unless the module gives the rule a level; a `COMMIT`
|
|
122
|
+
with no `BEGIN` before it still is.
|
|
123
|
+
|
|
124
|
+
squawk still asks for `lock_timeout` and `statement_timeout` once per file. In a file that **only
|
|
125
|
+
builds new tables** (every statement a `CREATE TABLE` or a `CREATE INDEX` on one of them, no
|
|
126
|
+
`REFERENCES`, `PARTITION OF`, `LIKE` or `INHERITS`), no statement can wait on a lock, and those two
|
|
127
|
+
are not reported. Whether an index is on an existing table is asked of squawk with every rule at its
|
|
128
|
+
default, so a module turning squawk's index advice `off` keeps the two timeouts. As soon as one statement can wait on an existing table they are, and the most
|
|
129
|
+
common migration Prisma writes is one: a new table **with a foreign key to an existing one** locks
|
|
130
|
+
that table. Measured on the monorepo: the two findings are gone from 45 migrations, each checked to
|
|
131
|
+
name no table it does not create. A migration Prisma generated for a new table with an index and a
|
|
132
|
+
foreign key went from 12 findings in alpha.10 to 6: the 4 type choices (`bigint`, `timestamptz`,
|
|
133
|
+
which a module may turn off) and the 2 timeouts the key calls for.
|
|
134
|
+
|
|
135
|
+
## What is checked, out of the box
|
|
136
|
+
|
|
137
|
+
| Source | Rules | On by default |
|
|
138
|
+
| ----------------------------------------------------------------- | ----- | --------------------------------------------- |
|
|
139
|
+
| squawk 2.72.0, its default rules | 50 | **yes**, at `warn` |
|
|
140
|
+
| squawk 2.72.0, its opt-in rules | 26 | no: one runs once the module gives it a level |
|
|
141
|
+
| sentinel, `unsafe-sql-pasted-value` and `unsafe-sql-raw-fragment` | 2 | **yes**, at `warn` |
|
|
142
|
+
| sentinel, `applied-migration-changed` | 1 | **yes**, at `warn` |
|
|
143
|
+
| sentinel, `enum-value-used-before-commit` | 1 | **yes**, at `warn` |
|
|
144
|
+
|
|
145
|
+
**54 rules run on every module**, the set squawk itself runs, plus sentinel's four. sentinel turns
|
|
146
|
+
no squawk rule off and turns no opt-in rule on: the choice of what runs by default is squawk's, and
|
|
147
|
+
a module moves it in its own config. `pnpm exec sentinel --inspect --sql --json` lists all 81 names
|
|
148
|
+
with the level each has in this module: squawk's 76, sentinel's four, and `syntax-error`.
|
|
149
|
+
|
|
150
|
+
**A migration that does not parse** is reported first, with its first error (the ones squawk gives
|
|
151
|
+
after it follow from it), and counts as **one finding** under `syntax-error`, at `warn` like every
|
|
152
|
+
rule, in the console, the html, the markdown and `sql.json` alike (there, the entry carries
|
|
153
|
+
`parserMessagesAfter`, how many messages squawk's parser gave after it). A module can set
|
|
154
|
+
`syntax-error` to `error` to fail its run on one; it cannot set it to `off`, since PostgreSQL refuses
|
|
155
|
+
that migration at deploy.
|
|
156
|
+
|
|
157
|
+
Every rule, what it catches and why it matters, is in [What each squawk rule catches](#what-each-squawk-rule-catches) below.
|
|
158
|
+
|
|
159
|
+
## Rule levels
|
|
160
|
+
|
|
161
|
+
A rule has one of three levels, the meanings lint already uses:
|
|
162
|
+
|
|
163
|
+
| Level | The rule runs? | A finding fails the run? | In the report |
|
|
164
|
+
| ---------------- | -------------- | ------------------------ | ---------------------------------------------------------------- |
|
|
165
|
+
| `warn` (default) | yes | no | listed |
|
|
166
|
+
| `error` | yes | **yes**, exit code 1 | listed first, marked `error` |
|
|
167
|
+
| `off` | no | no | named in a line of its own, so a reviewer sees it was turned off |
|
|
168
|
+
|
|
169
|
+
## The config file, `sql.config.mjs`
|
|
170
|
+
|
|
171
|
+
The one file a module writes, the shape of `static-analysis.config.mjs`. `--init` writes it with
|
|
172
|
+
every setting the module can move and the role's value today, generated from the defaults so it
|
|
173
|
+
cannot drift from them. A setting the module leaves out keeps the role's value; a setting it writes
|
|
174
|
+
**replaces** it, including inside a list, and the html report shows it as overridden by this module.
|
|
175
|
+
|
|
176
|
+
| Setting | Default | What it moves |
|
|
177
|
+
| --------------------- | ------------------------------------------ | ------------------------------------------------------ |
|
|
178
|
+
| `migrations.include` | `["**/migrations/*/migration.sql"]` | which files are migrations |
|
|
179
|
+
| `migrations.exclude` | `[]` | migrations never read |
|
|
180
|
+
| `unsafe.includeTests` | `true` | whether calls in test files are checked, by both rules |
|
|
181
|
+
| `unsafe.tests` | test folders and `*.spec`/`*.test`/… files | what counts as a test file |
|
|
182
|
+
| `ignore` | `node_modules`, `dist`, `coverage` | never read, by either check |
|
|
183
|
+
| `pgVersion` | `"16.8"` | the PostgreSQL version squawk checks against |
|
|
184
|
+
| `rules` | `{}`, every rule at its default | a level per rule, by its name |
|
|
185
|
+
|
|
186
|
+
An example that blocks two rules, silences one and turns an opt-in rule on:
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
// sql.config.mjs
|
|
190
|
+
import { defineSql } from '@hublo/sentinel/sql'
|
|
191
|
+
|
|
192
|
+
export default defineSql({
|
|
193
|
+
root: import.meta.dirname,
|
|
194
|
+
overrides: {
|
|
195
|
+
rules: {
|
|
196
|
+
'require-concurrent-index-creation': 'error',
|
|
197
|
+
'unsafe-sql-pasted-value': 'error',
|
|
198
|
+
'prefer-robust-stmts': 'off',
|
|
199
|
+
'ban-drop-index': 'warn',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
What the run prints with it:
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
this module turns off 1 rule(s) in sql.config.mjs, so they are not checked: prefer-robust-stmts.
|
|
209
|
+
✗ 6 finding(s): 2 error(s), from the rule(s) this module sets to "error" in sql.config.mjs, which fail this run, and 4 warning(s):
|
|
210
|
+
require-concurrent-index-creation 1 error
|
|
211
|
+
sentinel's note: Prisma runs a multi-statement file in a transaction, where CONCURRENTLY fails: give the statement its own migration.
|
|
212
|
+
prisma/migrations/20261116_index/migration.sql:2:1
|
|
213
|
+
unsafe-sql-pasted-value 1 error
|
|
214
|
+
src/app/missions.repository.ts:42:31
|
|
215
|
+
changing-column-type 1
|
|
216
|
+
prisma/migrations/20261116_index/migration.sql:4:43
|
|
217
|
+
...
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Each rule is followed by its first three places, `file:line:column`, and how many more; the page
|
|
221
|
+
(`sql:html`) has them all, with the SQL behind each.
|
|
222
|
+
|
|
223
|
+
`rules` names a rule by **squawk's name for it**, the name the report prints. A name that is not a
|
|
224
|
+
rule is refused in the module's own file, before anything runs, with the closest name:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
sql.config.mjs: `rules['prefer-robust-stmt']` is not a rule of squawk 2.72.0 or of sentinel. Did you mean 'prefer-robust-stmts'? The names are listed by `pnpm exec sentinel --inspect --sql --json`.
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
An older name squawk still accepts, such as `prefer-timestamptz`, is refused too, with the name to
|
|
231
|
+
write: squawk reports the rule under its new name, so a level on the old one would never apply.
|
|
232
|
+
|
|
233
|
+
The same goes for every other setting: a value of the wrong type, or a key the role does not have,
|
|
234
|
+
is refused in the module's file and the run fails, instead of running with something the module did
|
|
235
|
+
not mean. A string where a list is expected would otherwise ignore every file and report nothing.
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
sql.config.mjs: `ignore` must be a list of strings, like ['**/generated/**']; got "**/generated/**".
|
|
239
|
+
sql.config.mjs: `ignores` is not a setting of the sql role, so it would be ignored. The settings here are: migrations, unsafe, ignore, pgVersion, rules.
|
|
240
|
+
sql.config.mjs: defineSql takes `root` and `overrides`; `override` would be ignored.
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## What each squawk rule catches
|
|
244
|
+
|
|
245
|
+
One line per rule of squawk 2.72.0, written from the rule's own page at that version (`https://squawkhq.com/docs/<rule>`, which has the examples and the safe way to write the change). **On** runs by default; **opt-in** runs once the module gives it a level in `sql.config.mjs`.
|
|
246
|
+
|
|
247
|
+
### Locks the table: reads or writes wait while it runs
|
|
248
|
+
|
|
249
|
+
| Rule | Runs | What it catches | The risk in production |
|
|
250
|
+
| -------------------------------------- | ------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
251
|
+
| `adding-field-with-default` | **on** | a column added with a volatile default | the table is rewritten under `ACCESS EXCLUSIVE` (a non-volatile default is free since PostgreSQL 11) |
|
|
252
|
+
| `adding-foreign-key-constraint` | **on** | a foreign key added and validated at once | both tables are scanned under `SHARE ROW EXCLUSIVE`: no write to either while it runs |
|
|
253
|
+
| `adding-serial-primary-key-field` | **on** | a primary key added to an existing table | the index is built under `ACCESS EXCLUSIVE`: no read, no write |
|
|
254
|
+
| `changing-column-type` | **on** | a column type changed | `ACCESS EXCLUSIVE`, the table rewritten for most changes (not for a varchar widening, see sentinel's note), and readers of the old type may break |
|
|
255
|
+
| `constraint-missing-not-valid` | **on** | a constraint added without `NOT VALID` | the whole table is scanned while writes are blocked |
|
|
256
|
+
| `disallowed-unique-constraint` | **on** | a `UNIQUE` constraint added directly | its index is built under `ACCESS EXCLUSIVE`; build it `CONCURRENTLY` first |
|
|
257
|
+
| `prefer-repack` | **on** | `VACUUM FULL` or `CLUSTER` | `ACCESS EXCLUSIVE` for the whole run |
|
|
258
|
+
| `prefer-text-field` | **on** | a `varchar(n)` | changing its size later takes `ACCESS EXCLUSIVE`; `text` needs no such change |
|
|
259
|
+
| `require-concurrent-index-creation` | **on** | an index built without `CONCURRENTLY` | writes are blocked while it builds (sentinel's note: alone in its migration under Prisma) |
|
|
260
|
+
| `require-concurrent-index-deletion` | **on** | an index dropped without `CONCURRENTLY` | `ACCESS EXCLUSIVE` until the drop ends |
|
|
261
|
+
| `require-concurrent-partition-detach` | **on** | a partition detached without `CONCURRENTLY` | `ACCESS EXCLUSIVE` on the table |
|
|
262
|
+
| `require-concurrent-reindex` | **on** | `REINDEX` without `CONCURRENTLY` | `ACCESS EXCLUSIVE` on the index's table |
|
|
263
|
+
| `require-lock-timeout` | **on** | no `lock_timeout` before a statement that locks | a statement waiting for its lock makes every query behind it wait, with no limit |
|
|
264
|
+
| `require-statement-timeout` | **on** | no `statement_timeout` | a long migration holds its locks and resources with no limit |
|
|
265
|
+
| `ban-alter-domain-with-add-constraint` | **on** | a check constraint added to a domain | domains have poor support for online migrations: every column of the domain is checked |
|
|
266
|
+
| `ban-create-domain-with-constraint` | **on** | a domain created with a check constraint | the same poor support, from its creation |
|
|
267
|
+
|
|
268
|
+
### Breaks the application still running: a deploy runs old and new code side by side, and a rollback does not undo the migration
|
|
269
|
+
|
|
270
|
+
| Rule | Runs | What it catches | The risk in production |
|
|
271
|
+
| -------------------------------- | ------ | -------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
272
|
+
| `ban-drop-column` | **on** | a column dropped | the running version still reads or writes it |
|
|
273
|
+
| `ban-drop-table` | **on** | a table dropped | its queries fail |
|
|
274
|
+
| `ban-drop-view` | **on** | a view or materialized view dropped | its queries fail (`42P01`) |
|
|
275
|
+
| `ban-drop-schema` | **on** | a schema dropped | its queries fail; `CASCADE` drops everything in it |
|
|
276
|
+
| `ban-drop-sequence` | **on** | a sequence dropped | `nextval` fails; `CASCADE` removes the defaults using it |
|
|
277
|
+
| `ban-drop-function` | **on** | a function, procedure or aggregate dropped | its calls fail (`42883`) |
|
|
278
|
+
| `ban-drop-type` | **on** | a type, cast or operator dropped | casts naming it fail (`42704`); `CASCADE` drops its columns |
|
|
279
|
+
| `ban-drop-domain` | **on** | a domain dropped | casts and parameters using it fail |
|
|
280
|
+
| `ban-drop-extension` | **on** | an extension dropped | the objects it provides disappear |
|
|
281
|
+
| `ban-drop-database` | **on** | a database dropped | everything in it is gone |
|
|
282
|
+
| `ban-drop-constraint` | **on** | a constraint dropped, or set `NOT ENFORCED` | a guarantee disappears; `ON CONFLICT ON CONSTRAINT` inserts fail at once |
|
|
283
|
+
| `ban-drop-default` | **on** | a default dropped | inserts omitting the column fail (`23502`) or write `NULL` |
|
|
284
|
+
| `ban-drop-not-null` | **on** | a `NOT NULL` dropped | code that never expected `NULL` receives it |
|
|
285
|
+
| `ban-drop-generated-expression` | **on** | a generated column's expression dropped | new rows are no longer computed; inserts omitting it get `NULL` |
|
|
286
|
+
| `ban-alter-identity` | **on** | an identity column changed | inserts with or without an explicit value can fail |
|
|
287
|
+
| `renaming-column` | **on** | a column renamed | the running version uses the old name |
|
|
288
|
+
| `renaming-table` | **on** | a table renamed | the running version uses the old name |
|
|
289
|
+
| `renaming-object` | **on** | another object, or an enum value, renamed | clients using the old name fail |
|
|
290
|
+
| `ban-set-schema` | **on** | an object moved to another schema | its old qualified name fails |
|
|
291
|
+
| `adding-required-field` | **on** | a `NOT NULL` column added with no default | fails at once on a table with rows, and old code cannot insert |
|
|
292
|
+
| `adding-not-nullable-field` | **on** | a column set `NOT NULL` | fails if a row holds `NULL` |
|
|
293
|
+
| `ban-add-column` | opt-in | a column added | `SELECT *` changes shape and positional inserts break |
|
|
294
|
+
| `ban-add-composite-attribute` | opt-in | a composite type attribute added | clients reading the composite get another shape |
|
|
295
|
+
| `ban-add-enum-value` | opt-in | an enum value added | clients that do not know it receive it |
|
|
296
|
+
| `ban-alter-generated-expression` | opt-in | a generated column added or its expression changed | results change shape or value; stored ones are rewritten |
|
|
297
|
+
| `ban-alter-sequence-values` | opt-in | sequence options changed | identifiers may be reissued or go out of range |
|
|
298
|
+
| `ban-set-default` | opt-in | a default changed | clients omitting the column write another value |
|
|
299
|
+
| `ban-new-write-restriction` | opt-in | any new constraint, `NOT NULL` or unique index | writes the running version makes may be rejected |
|
|
300
|
+
| `ban-replace-view-function` | opt-in | `CREATE OR REPLACE` on a view, function or trigger | results or side effects change for unchanged SQL |
|
|
301
|
+
| `ban-drop-index` | opt-in | an index dropped | a unique guarantee or a query plan disappears |
|
|
302
|
+
| `ban-drop-trigger` | opt-in | a trigger dropped | its effects stop silently (`updated_at`, audit rows) |
|
|
303
|
+
| `ban-disable-trigger` | opt-in | a trigger or rule disabled or re-enabled | data written differently, or access refused |
|
|
304
|
+
| `ban-detach-inheritance` | opt-in | `DETACH PARTITION` or `NO INHERIT` | the parent table returns other rows |
|
|
305
|
+
| `ban-alter-view-options` | opt-in | view options changed | e.g. `security_invoker` changes who sees what; a rollback keeps it |
|
|
306
|
+
| `ban-alter-function-options` | opt-in | function options changed | execution or security changes, `search_path` included |
|
|
307
|
+
| `ban-alter-extension` | opt-in | `ALTER EXTENSION … UPDATE` or `DROP` | upgrade scripts can remove or change functions |
|
|
308
|
+
|
|
309
|
+
### Loses data, or fails to apply
|
|
310
|
+
|
|
311
|
+
| Rule | Runs | What it catches | The risk in production |
|
|
312
|
+
| ---------------------------------------------- | ------ | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
313
|
+
| `ban-truncate-cascade` | **on** | `TRUNCATE … CASCADE` | every table referencing it by foreign key is emptied too |
|
|
314
|
+
| `ban-uncommitted-transaction` | **on** | a `BEGIN` with no `COMMIT` | the migration reports success and applies nothing |
|
|
315
|
+
| `transaction-nesting` | **on** | a `BEGIN` or `COMMIT` inside a transaction | PostgreSQL has one transaction per session: a repeated `BEGIN` or `COMMIT` only warns, and does not do what it says |
|
|
316
|
+
| `ban-concurrent-index-creation-in-transaction` | **on** | `CONCURRENTLY` inside a transaction | PostgreSQL refuses it (`25001`): under Prisma, any file of several statements |
|
|
317
|
+
| `ban-duplicate-column-assignments` | **on** | a column assigned twice in one statement | PostgreSQL raises an error at run time |
|
|
318
|
+
| `prefer-robust-stmts` | **on** | a statement that fails when run twice (no `IF NOT EXISTS`) | a migration that failed halfway fails again when retried |
|
|
319
|
+
|
|
320
|
+
### Types and names that cause trouble later
|
|
321
|
+
|
|
322
|
+
| Rule | Runs | What it catches | The risk in production |
|
|
323
|
+
| ----------------------------- | ------ | ----------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
324
|
+
| `prefer-bigint-over-int` | **on** | an `int` (32-bit) key or counter | reaches its maximum, 2 147 483 647 |
|
|
325
|
+
| `prefer-bigint-over-smallint` | **on** | a `smallint` (16-bit) | reaches its maximum, 32 767 |
|
|
326
|
+
| `prefer-identity` | **on** | a `serial` column | permissions and schema changes are harder than with `GENERATED … AS IDENTITY` |
|
|
327
|
+
| `prefer-timestamp-tz` | **on** | a `timestamp` without time zone | the UTC offset is dropped: two instants 8 hours apart are stored the same |
|
|
328
|
+
| `ban-char-field` | **on** | a `char(n)` | blank-padded and almost always a mistake for `text` or `varchar` |
|
|
329
|
+
| `identifier-too-long` | **on** | a name over 63 bytes | PostgreSQL truncates it, and the real name differs from the one written |
|
|
330
|
+
| `require-enum-value-ordering` | **on** | an enum value added without `BEFORE` or `AFTER` | it lands last, which breaks an order that means something (status, priority) |
|
|
331
|
+
| `require-table-schema` | opt-in | a table named without its schema | resolved by `search_path`, which may not be the one meant |
|
|
332
|
+
|
|
333
|
+
### Access, configuration and replication (opt-in)
|
|
334
|
+
|
|
335
|
+
| Rule | Runs | What it catches | The risk in production |
|
|
336
|
+
| ------------------------------ | ------ | ---------------------------------------------- | ----------------------------------------------------------------------- |
|
|
337
|
+
| `ban-alter-database-options` | opt-in | `ALTER DATABASE` options | connection behaviour or results change for every client of the database |
|
|
338
|
+
| `ban-alter-system-options` | opt-in | `ALTER SYSTEM` | server settings change for every database and client |
|
|
339
|
+
| `ban-alter-role-options` | opt-in | `ALTER ROLE` / `ALTER USER` options | access or behaviour changes for clients using the role |
|
|
340
|
+
| `ban-revoke` | opt-in | `REVOKE`, a dropped role, an owner change | queries of existing clients fail; `DROP OWNED` removes objects |
|
|
341
|
+
| `ban-create-policy` | opt-in | `CREATE POLICY` | with row level security on, access changes |
|
|
342
|
+
| `ban-alter-policy-condition` | opt-in | `ALTER POLICY` with `USING` / `WITH CHECK` | clients read or write other rows |
|
|
343
|
+
| `ban-alter-policy-roles` | opt-in | `ALTER POLICY … TO` | the policy applies to other roles |
|
|
344
|
+
| `ban-drop-policy` | opt-in | a policy or rule dropped | access or rewrite behaviour changes |
|
|
345
|
+
| `ban-alter-row-level-security` | opt-in | row level security enabled, disabled or forced | access changes for existing clients |
|
|
346
|
+
| `ban-replica-identity` | opt-in | replica identity or a publication changed | logical replication consumers get stale, missing or changed data |
|
|
347
|
+
|
|
348
|
+
## sentinel's notes
|
|
349
|
+
|
|
350
|
+
squawk's advice is written for PostgreSQL in general. Under two rules, sentinel adds a note where
|
|
351
|
+
that advice meets the way Prisma runs a migration, each proven on PostgreSQL 16.8 with Prisma
|
|
352
|
+
6.19.3. **A note is added beside a finding; it never removes or changes one.**
|
|
353
|
+
|
|
354
|
+
- **`require-concurrent-index-creation` / `-deletion`.** Prisma runs a file of several statements
|
|
355
|
+
inside a transaction, where `CONCURRENTLY` fails (`25001`), nothing is applied and the next deploy
|
|
356
|
+
is refused (`P3009`). The note says to give the statement a migration of its own, alone in its
|
|
357
|
+
file, which applies.
|
|
358
|
+
- **`changing-column-type`, to `varchar` or `text`.** Widening a `varchar`, or changing it to
|
|
359
|
+
`text`, rewrites neither the table nor its index (under 4 ms on 2 million rows), but still waits
|
|
360
|
+
for the table's lock and makes every query behind it wait. The note says to put
|
|
361
|
+
`SET lock_timeout` before the `ALTER`. The statement does not say the type before it, so the
|
|
362
|
+
finding stays for every type change: narrowing a `varchar`, or leaving a `uuid`, does rewrite the
|
|
363
|
+
table.
|
|
364
|
+
|
|
365
|
+
## A migration already applied, `applied-migration-changed`
|
|
366
|
+
|
|
367
|
+
A migration that is already on the base (`origin/main`, or the pull request's base in CI) has run
|
|
368
|
+
wherever that base was deployed. Prisma knows it by its **folder name**, and never runs it twice.
|
|
369
|
+
So a branch must not touch it. Proven on PostgreSQL 16.8 with Prisma 6.19.3:
|
|
370
|
+
|
|
371
|
+
| The branch… | At the next deploy | The fix |
|
|
372
|
+
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
|
|
373
|
+
| **renames** it (a new folder name) | Prisma sees a migration it never ran, runs it, and it fails on what its first run created (P3018, 42P07); every next deploy is refused | keep the name; write any change as a new migration |
|
|
374
|
+
| **modifies** it | nothing: "No pending migrations", and `migrate status` says up to date. The change never reaches a database that ran it; a new one gets it | restore it; write the change as a new migration (`migrate dev --create-only`) |
|
|
375
|
+
| **deletes** it | nothing: the databases that ran it keep what it did, a new database no longer gets it | restore it; undo what it did in a new migration, if that is the intent |
|
|
376
|
+
|
|
377
|
+
Moving the migrations folder elsewhere under the **same folder names** (a database package moved
|
|
378
|
+
into its service) is not reported: Prisma has nothing to apply, proven. If a moved migration's text
|
|
379
|
+
changed too, it is reported as modified, naming its path on the base and where it went.
|
|
380
|
+
|
|
381
|
+
A migration is paired the way Prisma knows it, never by git's similarity (which pairs two different
|
|
382
|
+
migrations 50% alike as a rename, and misses a small one edited past that): a migration gone from
|
|
383
|
+
its place is a **move** when the branch adds one of the same folder name, a **rename** when it adds
|
|
384
|
+
the same content under another name, and **deleted** otherwise. Committed, staged or a plain `mv`
|
|
385
|
+
read the same. Content is compared the way git stores it, so a CRLF checkout on Windows is the same
|
|
386
|
+
file, and a change of mode alone (`chmod`) is no change.
|
|
387
|
+
|
|
388
|
+
A migration moved where the settings no longer see it (`migration.sql` renamed
|
|
389
|
+
`migration.sql.bak`, its folder moved into `archive/`) is reported **deleted**, whatever its folder
|
|
390
|
+
is called: Prisma no longer reads it either. What counts as a migration is `migrations.include`, on
|
|
391
|
+
both ends of a move.
|
|
392
|
+
|
|
393
|
+
**A folder left without its `migration.sql`** (renamed `.bak`, or deleted beside its `down.sql`) is
|
|
394
|
+
worse than a deletion, and said apart. Proven on PostgreSQL 16.8 with Prisma 6.19.3: a database that
|
|
395
|
+
ran it says nothing and applies the next migrations, but every database created from scratch (CI, a
|
|
396
|
+
new environment, a reset) stops at that folder with **P3015** "Could not find the migration file",
|
|
397
|
+
and no migration after it is applied. The fix: restore `migration.sql` as it is on the base.
|
|
398
|
+
|
|
399
|
+
The role compares with the base the branch forked from. When git cannot name it (a clone without
|
|
400
|
+
history), a module whose migrations are all gone says so in one line rather than nothing: CI must
|
|
401
|
+
fetch with `fetch-depth: 0`.
|
|
402
|
+
|
|
403
|
+
Measured on the history of `main` since 2025-01-01, against an oracle that reads names and content
|
|
404
|
+
the way Prisma does: 56 commits touched a migration already merged, in 60 module runs (44
|
|
405
|
+
modifications, 34 deletions), and the role agreed with the oracle on all 60. Two of those deletions
|
|
406
|
+
were renames that also changed the text: the old name is gone, and the new folder is a migration
|
|
407
|
+
Prisma has never seen, read as such.
|
|
408
|
+
|
|
409
|
+
## A new enum value used before it is committed, `enum-value-used-before-commit`
|
|
410
|
+
|
|
411
|
+
`ALTER TYPE "Status" ADD VALUE 'ARCHIVED'` then a use of `'ARCHIVED'` in the same migration: Prisma
|
|
412
|
+
runs a migration of several statements in one transaction, and PostgreSQL refuses a new enum value
|
|
413
|
+
before it is committed. Proven on PostgreSQL 16.8 with Prisma 6.19.3: the deploy fails with **P3018 /
|
|
414
|
+
55P04** "unsafe use of new value", and every next deploy is refused until `prisma migrate resolve`.
|
|
415
|
+
squawk 2.72.0 does not see it.
|
|
416
|
+
|
|
417
|
+
| In the same migration, after the `ADD VALUE` | At deploy (proven) | Reported |
|
|
418
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
|
|
419
|
+
| `UPDATE … = 'ARCHIVED'`, `SET DEFAULT 'ARCHIVED'`, `'ARCHIVED'::"Status"`, a `CHECK` naming it, a SQL function body using it, `IF NOT EXISTS` or not | **fails**, P3018 / 55P04 | **yes** |
|
|
420
|
+
| a `COMMIT;` first, or each part in a `BEGIN … COMMIT` of its own | applies | no |
|
|
421
|
+
| another value added, the same label added to another enum, the value named in a comment only | applies | no |
|
|
422
|
+
| the value alone in its migration, used in the next one | applies | no |
|
|
423
|
+
| the same word written into a **text** column | applies | yes: the rule reads text, not column types, so the message names the value and the enum, and a reviewer tells in one look |
|
|
424
|
+
|
|
425
|
+
The fix it prints: give the `ALTER TYPE … ADD VALUE` a migration of its own, before the one that
|
|
426
|
+
uses the value. Measured on the monorepo (874 migrations, 68 adding an enum value): no finding, and
|
|
427
|
+
the rule's split of each file into statements agrees with squawk's parser on all 874.
|
|
428
|
+
|
|
429
|
+
## The `Unsafe` rule, `unsafe-sql-pasted-value`
|
|
430
|
+
|
|
431
|
+
Prisma's tagged `` $queryRaw`…${value}…` `` sends each `${}` as a parameter. `$queryRawUnsafe` and
|
|
432
|
+
`$executeRawUnsafe` take a plain string: whatever is pasted into it runs as SQL. The rule reports a
|
|
433
|
+
call whose SQL text holds a part sentinel **cannot show** is a constant.
|
|
434
|
+
|
|
435
|
+
It clears what cannot carry text a caller chose:
|
|
436
|
+
|
|
437
|
+
- a string literal, or a template without a value;
|
|
438
|
+
- a template, `+`, ternary, `??`, `||` or `&&` built only of safe parts;
|
|
439
|
+
- arithmetic and comparisons, whose result is a number or a boolean;
|
|
440
|
+
- a `const` of the file, declared once under that name, whose value is safe;
|
|
441
|
+
- a name imported from a relative path, from a file that says `export const NAME = <safe>`;
|
|
442
|
+
- generated placeholders, ``list.map((_, index) => `$${index + 1}`).join(', ')``.
|
|
443
|
+
|
|
444
|
+
It reports everything else, and names the part it could not see:
|
|
445
|
+
|
|
446
|
+
```
|
|
447
|
+
`table` is pasted into the SQL text of $queryRawUnsafe, and sentinel cannot show it is constant: a quote in it would end the string and run the rest as SQL
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
The call is read in every form that reaches the method, not only `db.$queryRawUnsafe(text)`:
|
|
451
|
+
`.call(db, text)`, `.apply(db, [text])`, a method taken out of the client
|
|
452
|
+
(`const { $queryRawUnsafe } = db`, `const q = db.$queryRawUnsafe`, with or without `.bind(db)`),
|
|
453
|
+
and `...args` in place of the text, which is reported since what it holds cannot be seen. A name
|
|
454
|
+
bound several times in the file is followed only when every binding names the same method (two
|
|
455
|
+
methods of a service each taking `$queryRawUnsafe` out of `this.db`); bound to anything else
|
|
456
|
+
anywhere in the file, it is not: which binding a call reaches is a question of scope. An array
|
|
457
|
+
passed to `.apply` is read when it is written in the call; a named one is reported, since a
|
|
458
|
+
`const` array can still be changed.
|
|
459
|
+
`Prisma` imported as a namespace (`import * as P from '@prisma/…'`, then `P.Prisma.raw`) is read
|
|
460
|
+
too. None of these forms is in the monorepo today (2026-11-16); the 1 012 files that make a raw SQL
|
|
461
|
+
call read the same as before.
|
|
462
|
+
|
|
463
|
+
That includes a function parameter (the SQL arrives from a caller, unchecked where it is used), a
|
|
464
|
+
`let`, an object property, an enum member, a call, a name declared twice in the file, and an import
|
|
465
|
+
from a package. The rule never guesses: when it cannot see, it reports. The fix it prints is a
|
|
466
|
+
parameter (`$1` in the text, the value after it), or the tagged form; a table or column name cannot
|
|
467
|
+
be a parameter, so take it from a `const` of the file.
|
|
468
|
+
|
|
469
|
+
Measured on the monorepo's 219 calls before the rule was written: the 23 production calls match a
|
|
470
|
+
classification made by hand, one of them a real injection pasting data into a `VALUES` list.
|
|
471
|
+
|
|
472
|
+
**The same rule reads the two drivers the monorepo also uses**, each only in a file that imports
|
|
473
|
+
it (`import … from 'pg'` or `require('pg')`, `import … from 'postgres'`), so a `query` or an
|
|
474
|
+
`unsafe` of anything else is not read. A **type** import counts: `import type { Pool } from 'pg'`
|
|
475
|
+
with the pool injected in a constructor is the usual NestJS shape, and that file talks to pg:
|
|
476
|
+
|
|
477
|
+
| Driver | The call whose text is SQL | Its safe form | The fix printed |
|
|
478
|
+
| ------------------------ | ----------------------------------------------------------------- | -------------------------------------------------------- | ---------------------------------------------- |
|
|
479
|
+
| `pg` (node-postgres) | `client.query(text, values)`, or `client.query({ text, values })` | `$1` in the text, the value in the array | the parameter |
|
|
480
|
+
| `postgres` (postgres.js) | `sql.unsafe(text)` | the tagged `` sql`…${value}…` ``, which binds each value | the tagged form; `sql(name)` for an identifier |
|
|
481
|
+
|
|
482
|
+
Measured on `main` (f12da701121): 38 calls, 15 reported, none injectable. One is in production,
|
|
483
|
+
`apps/cloud/interop`: a `SET` list built by `.map` from a `const` list of column names, safe by
|
|
484
|
+
construction and reported because the rule does not follow the element of a `.map`. Six are in a
|
|
485
|
+
`mission` integration test (schema and table names the test makes). Eight are in `tools/scripts`,
|
|
486
|
+
outside any module.
|
|
487
|
+
|
|
488
|
+
## The `Prisma.raw` rule, `unsafe-sql-raw-fragment`
|
|
489
|
+
|
|
490
|
+
`Prisma.raw(text)` puts its text into a tagged query **as SQL, never as a parameter**: the same
|
|
491
|
+
hazard as the `Unsafe` methods, inside the safe form. Its argument is checked exactly like theirs,
|
|
492
|
+
with the same list of what is cleared, and reported under its own rule, so a module can set the two
|
|
493
|
+
levels apart. `Prisma` is recognised by its import from a `@prisma/` package, under any name
|
|
494
|
+
(`import { Prisma as AgencyPrisma }` included); a `raw` of anything else, `String.raw` among them,
|
|
495
|
+
is not read.
|
|
496
|
+
|
|
497
|
+
```
|
|
498
|
+
the SQL text of Prisma.raw is `sortOrder`, which sentinel cannot show is a constant: whatever was pasted into it, wherever it was built, runs as SQL
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
The fix it prints: a value goes into `` Prisma.sql`…` `` as `${value}`, which binds it. A keyword or
|
|
502
|
+
a column name cannot be bound, so write each choice as a literal, which the rule clears:
|
|
503
|
+
|
|
504
|
+
```ts
|
|
505
|
+
Prisma.sql`ORDER BY "lastName" ${order === 'DESC' ? Prisma.raw('DESC') : Prisma.raw('ASC')}`
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
Measured on `main` (f12da701121): 97 calls, 20 cleared (all literals or ternaries of literals) and 77
|
|
509
|
+
reported. None of the 77 was found injectable, and none can be proven safe where it is written:
|
|
510
|
+
|
|
511
|
+
| What the call receives | Calls | Why the rule cannot clear it |
|
|
512
|
+
| --------------------------------------------------------------------------------------------------------------- | ----: | ------------------------------------------------------------ |
|
|
513
|
+
| a value validated elsewhere: an enum checked by the HTTP DTO, a key of a column map, a filtered list of numbers | 37 | the proof is a type or a validator, files away from the call |
|
|
514
|
+
| an alias or a column name, a parameter of a SQL helper | 19 | the callers pass literals, in other files |
|
|
515
|
+
| a fragment of SQL built elsewhere, by a query builder or a helper | 21 | the text is made in another function |
|
|
516
|
+
|
|
517
|
+
That is the rule's purpose: on a branch that changes one of these files, the reviewer is told that
|
|
518
|
+
the safety of the text rests on code the call does not show.
|
|
519
|
+
|
|
520
|
+
**`Prisma.join(list, separator, prefix, suffix)`** is read too: Prisma binds the values of its
|
|
521
|
+
list, but its separator, prefix and suffix are SQL text. Measured on `main`: 88 calls with a
|
|
522
|
+
separator, every one a literal (`' AND '`, `' OR '`, `'\n'`), so none is reported.
|
|
523
|
+
|
|
524
|
+
## Every way to send SQL text, and what reads it
|
|
525
|
+
|
|
526
|
+
Measured on the monorepo (`main` f12da701121), every call that can send text to a database:
|
|
527
|
+
|
|
528
|
+
| Entry point | Calls | Its text is | Read by |
|
|
529
|
+
| ---------------------------------------------------------------------- | ------------: | -------------------------------------------------------- | --------------------------------------- |
|
|
530
|
+
| `` $queryRaw`…` ``, `` $executeRaw`…` ``, `` Prisma.sql`…` `` (tagged) | 332 and 1 079 | a template whose every `${}` Prisma binds | nothing to report: safe by construction |
|
|
531
|
+
| `$queryRaw(sql)` called as a function | 30 | a `Prisma.Sql` object; TypeScript refuses a plain string | nothing to report |
|
|
532
|
+
| `$queryRawUnsafe` / `$executeRawUnsafe` | 219 | SQL | `unsafe-sql-pasted-value` |
|
|
533
|
+
| `pg` `query` | 37 | SQL | `unsafe-sql-pasted-value` |
|
|
534
|
+
| postgres.js `unsafe` | 1 | SQL | `unsafe-sql-pasted-value` |
|
|
535
|
+
| `Prisma.raw` | 97 | SQL, pasted as is | `unsafe-sql-raw-fragment` |
|
|
536
|
+
| `Prisma.join` separator, prefix, suffix | 88 | SQL | `unsafe-sql-raw-fragment` |
|
|
537
|
+
| postgres.js tagged `` sql`…` `` | | a template whose every `${}` the driver binds | nothing to report |
|
|
538
|
+
| knex, TypeORM, Sequelize, mysql | 0 | | not used |
|
|
539
|
+
| MongoDB (35 imports) | | not SQL | outside this role |
|
|
540
|
+
|
|
541
|
+
## What the role does not read yet
|
|
542
|
+
|
|
543
|
+
Said here so that a clean report is not read as more than it is:
|
|
544
|
+
|
|
545
|
+
- **`VACUUM` in a migration of several statements.** PostgreSQL refuses it inside a transaction,
|
|
546
|
+
as it refuses `CONCURRENTLY`, and squawk 2.72.0 does not report it there. No migration of the
|
|
547
|
+
monorepo runs `VACUUM`.
|
|
548
|
+
- **The SQL text itself** of a raw query is not parsed: a tagged `$queryRaw` with only parameters is
|
|
549
|
+
safe from injection, and its SQL is not checked against any rule. A syntax error inside it is not
|
|
550
|
+
seen. That is the next step, with libpg-query.
|
|
551
|
+
- **JavaScript files** (`.js`, `.mjs`): the role reads TypeScript (`.ts`, `.mts`, `.cts`).
|
|
552
|
+
- **Files outside a module.** The role runs on a module; a script at the repository's root that
|
|
553
|
+
belongs to no module is read by no role.
|
|
554
|
+
- **What the ORM generates** (`findMany`, `update`, …) is not seen: there is no SQL text to read.
|
|
555
|
+
|
|
556
|
+
## How it was validated
|
|
557
|
+
|
|
558
|
+
On the published packages, `@hublo/sentinel@1.7.0-alpha.8` to `1.7.0-alpha.10` installed from npm, in a throwaway copy of
|
|
559
|
+
the monorepo (`main` f12da701121). Each check has an oracle that is not sentinel, and what it must
|
|
560
|
+
give was written before the run.
|
|
561
|
+
|
|
562
|
+
| Check | What was run | Result |
|
|
563
|
+
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
564
|
+
| Errors written on purpose | 12 migration errors (syntax, `DROP COLUMN`, an index without `CONCURRENTLY`, a required column, a validated foreign key, a rename, `timestamp`, a type change to `int`, a varchar widening, `TRUNCATE … CASCADE`, `BEGIN` with no `COMMIT`, `DROP TABLE`) in `libs/nest/db-main`; 10 code errors (a value pasted into `$queryRawUnsafe`, `+`, an SQL parameter, a `let`, a test file, `Prisma.raw` and its alias, `pg`, postgres.js, a `Prisma.join` separator) in `network` | 22 of 22 reported under the expected rule, with sentinel's note where one applies and not where none does |
|
|
565
|
+
| Safe code | a tagged `$queryRaw`, a literal `$executeRawUnsafe`, `Prisma.raw('ASC')`, a ternary of literals, `String.raw`, `pg` with `$1`, postgres.js tagged, `Prisma.join(c, ' AND ')` | 8 of 8 with no finding |
|
|
566
|
+
| Only the branch | the same module's 39 files with such calls, unchanged by the branch | not read, and said; no finding outside the files written |
|
|
567
|
+
| Levels | `error` on a rule; `error` with another rule `off`; a misspelt rule | exit 1 with the findings marked `error`; the rule turned off gone from the report; the typo refused with the right name |
|
|
568
|
+
| Known gaps | two `CONCURRENTLY` in one file (alpha.10), a syntax error inside a tagged `$queryRaw`, an ORM call | not reported, as this page says |
|
|
569
|
+
| History | every commit of `main` from 2026-09-01 to 2026-11-16 touching a migration or a raw SQL call: 513 commits, 1 020 module runs, compared with `git diff` for the files, with squawk run on its own for the findings, with a text count for the calls | 0 crash; the same findings and the same calls in every run; the files differ only where expected: a renamed migration (read on purpose) and the migrations of a nested database project its service also reads; median 0.6 s a module, 4 s at worst |
|
|
570
|
+
| On real pull requests | the role adopted with `--init --sql` on four modules and eight case pull requests in the monorepo, the comment posted by the `sql recap` workflow (hublo/monorepo#24439, #24440 to #24447) | every comment as written before the run |
|
|
571
|
+
| Adoption | `--init --sql` on the 47 modules holding SQL, then `pnpm install` and a run in each; three front modules | 47 of 47 adopted as this page says and run; the fronts skipped with the reason |
|
|
572
|
+
| The largest comment | the commit of the history with the most findings, 32 modules | 64 774 characters, under GitHub's limit: 21 modules shown, the others named with where to read them |
|
|
573
|
+
| Runs that cannot tell what changed | a folder that is not a module, a shallow clone, no `origin/main`, an unknown `NX_BASE`, no git | each fails, exit 1, naming the fix; never "no finding" over files nobody read |
|