@quickback-dev/cli 0.69.0 → 0.70.0
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/index.js +1 -1
- package/dist/lib/audit-canon.js +3 -3
- package/dist/lib/audit-canon.js.map +1 -1
- package/dist/skill/docs/api/query-params.md +1 -1
- package/dist/skill/docs/define/areas.md +1 -1
- package/dist/skill/docs/define/bundles.md +23 -3
- package/dist/skill/docs/define/escape-hatches.md +2 -2
- package/dist/skill/docs/define/schema.md +12 -2
- package/dist/skill/docs/define/scopes.md +7 -1
- package/dist/skill/docs/platform/auth/security.md +2 -1
- package/dist/skill/docs/platform/database/neon.md +10 -4
- package/dist/skill/docs/tooling/claude-skill.md +1 -1
- package/package.json +1 -1
- package/src/skill/docs/api/query-params.md +1 -1
- package/src/skill/docs/define/areas.md +1 -1
- package/src/skill/docs/define/bundles.md +23 -3
- package/src/skill/docs/define/escape-hatches.md +2 -2
- package/src/skill/docs/define/schema.md +12 -2
- package/src/skill/docs/define/scopes.md +7 -1
- package/src/skill/docs/platform/auth/security.md +2 -1
- package/src/skill/docs/platform/database/neon.md +10 -4
- package/src/skill/docs/tooling/claude-skill.md +1 -1
package/dist/index.js
CHANGED
package/dist/lib/audit-canon.js
CHANGED
|
@@ -15,14 +15,14 @@ export const MANAGED_COLUMN_CANON = [
|
|
|
15
15
|
jsName: 'createdAt',
|
|
16
16
|
snakeName: 'created_at',
|
|
17
17
|
audit: true,
|
|
18
|
-
pgLine: `createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),`,
|
|
18
|
+
pgLine: `createdAt: timestamp("created_at", { withTimezone: true, precision: 3 }).notNull().defaultNow(),`,
|
|
19
19
|
sqliteLine: `createdAt: text("created_at").notNull().default(${EPOCH}).$defaultFn(${ISO_NOW}),`,
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
jsName: 'modifiedAt',
|
|
23
23
|
snakeName: 'modified_at',
|
|
24
24
|
audit: true,
|
|
25
|
-
pgLine: `modifiedAt: timestamp("modified_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => new Date()),`,
|
|
25
|
+
pgLine: `modifiedAt: timestamp("modified_at", { withTimezone: true, precision: 3 }).notNull().defaultNow().$onUpdate(() => new Date()),`,
|
|
26
26
|
sqliteLine: `modifiedAt: text("modified_at").notNull().default(${EPOCH}).$defaultFn(${ISO_NOW}).$onUpdate(${ISO_NOW}),`,
|
|
27
27
|
},
|
|
28
28
|
{
|
|
@@ -43,7 +43,7 @@ export const MANAGED_COLUMN_CANON = [
|
|
|
43
43
|
jsName: 'deletedAt',
|
|
44
44
|
snakeName: 'deleted_at',
|
|
45
45
|
audit: false,
|
|
46
|
-
pgLine: `deletedAt: timestamp("deleted_at", { withTimezone: true }),`,
|
|
46
|
+
pgLine: `deletedAt: timestamp("deleted_at", { withTimezone: true, precision: 3 }),`,
|
|
47
47
|
sqliteLine: `deletedAt: text("deleted_at"),`,
|
|
48
48
|
},
|
|
49
49
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-canon.js","sourceRoot":"","sources":["../../src/lib/audit-canon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAC3C,MAAM,OAAO,GAAG,gCAAgC,CAAC;AAEjD,MAAM,CAAC,MAAM,oBAAoB,GAAsC;IACrE;QACE,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,YAAY;QACvB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"audit-canon.js","sourceRoot":"","sources":["../../src/lib/audit-canon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAC3C,MAAM,OAAO,GAAG,gCAAgC,CAAC;AAEjD,MAAM,CAAC,MAAM,oBAAoB,GAAsC;IACrE;QACE,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,YAAY;QACvB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,kGAAkG;QAC1G,UAAU,EAAE,mDAAmD,KAAK,gBAAgB,OAAO,IAAI;KAChG;IACD;QACE,MAAM,EAAE,YAAY;QACpB,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,gIAAgI;QACxI,UAAU,EAAE,qDAAqD,KAAK,gBAAgB,OAAO,eAAe,OAAO,IAAI;KACxH;IACD;QACE,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,YAAY;QACvB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,gCAAgC;QACxC,UAAU,EAAE,gCAAgC;KAC7C;IACD;QACE,MAAM,EAAE,YAAY;QACpB,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,kCAAkC;QAC1C,UAAU,EAAE,kCAAkC;KAC/C;IACD;QACE,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,YAAY;QACvB,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,2EAA2E;QACnF,UAAU,EAAE,gCAAgC;KAC7C;IACD;QACE,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,YAAY;QACvB,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,gCAAgC;QACxC,UAAU,EAAE,gCAAgC;KAC7C;CACF,CAAC"}
|
|
@@ -91,7 +91,7 @@ currently wired into the emitted route.
|
|
|
91
91
|
- `count` — number of records returned on this page
|
|
92
92
|
- `page` / `pageSize` — derived from `?offset=` and `?limit=`
|
|
93
93
|
- `hasMore` — whether more rows exist in the queried direction. Without `?total=true` it comes from a `limit + 1` over-fetch probe, so it never lies on a final page that exactly fills the limit; with `?total=true` it is page arithmetic (`page < totalPages`) on offset pages, and the probe again on cursor pages.
|
|
94
|
-
- `nextCursor` / `prevCursor` — keyset cursors; pass them back as `?starting_after=` and `?ending_before=`. Treat them as opaque, but they are encoded, not encrypted: they carry the boundary row's sort-key values. Either can be `null` — including when the sort includes a [masked](/define/masking) column the caller may sort by (`query.roles`) but not see (`show.roles`), or a column the response does not carry (a view sorting on a field it doesn't list, or `?fields=` without the sort key); page with `?offset=` in that case.
|
|
94
|
+
- `nextCursor` / `prevCursor` — keyset cursors; pass them back as `?starting_after=` and `?ending_before=`. Treat them as opaque, but they are encoded, not encrypted: they carry the boundary row's sort-key values. Either can be `null` — including when the sort includes a [masked](/define/masking) column the caller may sort by (`query.roles`) but not see (`show.roles`), or a column the response does not carry (a view sorting on a field it doesn't list, or `?fields=` without the sort key); page with `?offset=` in that case. A cursor carries a timestamp sort key at millisecond precision, so sort on a column that stores milliseconds: the managed `createdAt` / `modifiedAt` / `deletedAt` do on both dialects (Postgres stores them as `timestamptz(3)`). A Postgres timestamp column you declare with microsecond precision and fill with `now()` can repeat or skip rows across pages.
|
|
95
95
|
- `total` / `totalPages` — present **only** when the request passed `?total=true` (see below)
|
|
96
96
|
|
|
97
97
|
There is no `limit` or `offset` member in `pagination`.
|
|
@@ -424,7 +424,7 @@ The compiler emits one synthetic `src/routes/__namespace-event-scope.routes.ts`
|
|
|
424
424
|
|
|
425
425
|
### Multi-lane via — first match wins
|
|
426
426
|
|
|
427
|
-
When more than one relationship can authorize a caller for the namespaced resource, pass `via:` as an array. The middleware
|
|
427
|
+
When more than one relationship can authorize a caller for the namespaced resource, pass `via:` as an array. The middleware starts every lane's probe at once and takes the first match in declaration order — a later lane never wins over an earlier lane that also matches, and `ctx.<exposeAs>` is hydrated from the lane that won. A probe that fails surfaces only when every earlier lane missed; a failure in a lane after the winner is ignored.
|
|
428
428
|
|
|
429
429
|
```typescript
|
|
430
430
|
authz: {
|
|
@@ -42,10 +42,30 @@ export default defineBundle({
|
|
|
42
42
|
soft-delete filter apply by construction — and the target table's REAL
|
|
43
43
|
mask function is applied (the same read projection the CRUD list endpoint
|
|
44
44
|
runs), so masked columns are safe to include. Every list slice lands as
|
|
45
|
-
`{ data: rows }`
|
|
45
|
+
`{ data: rows, hasMore, nextCursor }` — `data` is the per-resource
|
|
46
|
+
cache-seed contract; `hasMore` and `nextCursor` are additive.
|
|
47
|
+
- **Ordering is deterministic.** `orderBy` keys apply in the order you list
|
|
48
|
+
them. The primary key `id` is appended ascending as the final tie-break
|
|
49
|
+
unless you already listed it, the same rule as the
|
|
50
|
+
[CRUD list](/api/query-params#pagination). Without a unique final key,
|
|
51
|
+
`LIMIT` picks among tied rows arbitrarily on Postgres.
|
|
52
|
+
- **Truncation is visible.** With `limit`, the section reads one extra row:
|
|
53
|
+
`hasMore: true` means more rows match than were returned. Without `limit`,
|
|
54
|
+
`hasMore` is always `false`.
|
|
55
|
+
- **`nextCursor` continues on the table's CRUD list.** When `hasMore` is
|
|
56
|
+
true, `nextCursor` is the same keyset cursor the CRUD list emits. Fetch
|
|
57
|
+
the next page with that list endpoint, passing the section's `where` as
|
|
58
|
+
equality filters, its `orderBy` as `?sort=`, and the cursor as
|
|
59
|
+
`?starting_after=`. For `orderBy: [{ createdAt: "desc" }]` and
|
|
60
|
+
`where: { eventId }`, that is
|
|
61
|
+
`GET /api/v1/guests?eventId=<id>&sort=-createdAt&starting_after=<nextCursor>`.
|
|
62
|
+
The CRUD list appends the same `id` tie-break, so the cursor lines up.
|
|
63
|
+
`nextCursor` is `null` when there is nothing more, when `columns` omits a
|
|
64
|
+
sort key (or `id`), or when a sort key is [masked](/define/masking) for the
|
|
65
|
+
caller. In those cases, raise `limit` or page the CRUD list with `?offset=`.
|
|
46
66
|
- **`sections` filter**: omitted/empty = all. An un-wanted list section
|
|
47
|
-
returns `{ data: [] }` (drop-in
|
|
48
|
-
un-wanted `custom` sections are absent.
|
|
67
|
+
returns `{ data: [], hasMore: false, nextCursor: null }` (drop-in
|
|
68
|
+
compatible with existing clients); un-wanted `custom` sections are absent.
|
|
49
69
|
- **All sections run in one `Promise.all`.**
|
|
50
70
|
- **ETag**: SHA-1 hex over `{ scopeSeed: <path params>, userId, payload }`.
|
|
51
71
|
An `ifNoneMatch` match returns `{ success: true, etag, notModified: true }`
|
|
@@ -157,9 +157,9 @@ Reference implementations, both ports of the same table:
|
|
|
157
157
|
- `examples/recruitment/quickback/features/interviews/interview_scores.ts` (SQLite)
|
|
158
158
|
- `examples/recruitment-neon/quickback/features/interviews/interview_scores.ts` (Postgres)
|
|
159
159
|
|
|
160
|
-
Postgres uses `timestamp("…", { withTimezone: true }).notNull().defaultNow()` for the
|
|
160
|
+
Postgres uses `timestamp("…", { withTimezone: true, precision: 3 }).notNull().defaultNow()` for the
|
|
161
161
|
timestamps, `.$onUpdate(() => new Date())` on `modifiedAt`, plain `text(…)` for the
|
|
162
|
-
actor columns, and `timestamp("deleted_at", { withTimezone: true })` for `deletedAt`.
|
|
162
|
+
actor columns, and `timestamp("deleted_at", { withTimezone: true, precision: 3 })` for `deletedAt`.
|
|
163
163
|
|
|
164
164
|
## Attaching pillars to a raw Drizzle table
|
|
165
165
|
|
|
@@ -535,7 +535,7 @@ Default to `feature()`. Drop to Drizzle only when:
|
|
|
535
535
|
|
|
536
536
|
Features in the same project may mix freely — Quickback dispatches per feature — so one interop table doesn't force the rest of the project off `feature()`.
|
|
537
537
|
|
|
538
|
-
One dialect rule: interop files **without** a `defineTable(...)` default export (internal child tables) are not dialect-translated — author them in the target database's dialect. On Postgres providers (`neon`, `planetscale-postgres`), a `sqliteTable` interop source without `defineTable` is a compile-time error; write it with `pgTable` from `drizzle-orm/pg-core` instead. Sources **with** `defineTable(...)` keep compiling across dialects automatically. On Postgres, managed audit timestamps a `sqliteTable` source declares in the SQLite shape (`createdAt` / `modifiedAt` / `deletedAt` as `text`) are emitted as `timestamptz`, the same as every other Postgres table; API responses still carry the same ISO-8601 string.
|
|
538
|
+
One dialect rule: interop files **without** a `defineTable(...)` default export (internal child tables) are not dialect-translated — author them in the target database's dialect. On Postgres providers (`neon`, `planetscale-postgres`), a `sqliteTable` interop source without `defineTable` is a compile-time error; write it with `pgTable` from `drizzle-orm/pg-core` instead. Sources **with** `defineTable(...)` keep compiling across dialects automatically. On Postgres, managed audit timestamps a `sqliteTable` source declares in the SQLite shape (`createdAt` / `modifiedAt` / `deletedAt` as `text`) are emitted as `timestamptz(3)`, the same as every other Postgres table; API responses still carry the same ISO-8601 string.
|
|
539
539
|
|
|
540
540
|
### Drizzle Column Types
|
|
541
541
|
|
|
@@ -765,7 +765,7 @@ The scoped `db` an action receives types every managed key as `?: never` on `.in
|
|
|
765
765
|
|
|
766
766
|
The runtime layer **hard-stamps** every audit field on every write, so the audit log can never be forged by a crafted request body or by a client echoing a row back into a PATCH.
|
|
767
767
|
|
|
768
|
-
On Postgres the RLS migration adds a database-side backstop: `BEFORE INSERT` / `BEFORE UPDATE` triggers on every feature table (`public.set_audit_fields_on_insert()` / `_on_update()`). They set `created_at` / `modified_at` to the database's `now()` and apply the same actor rule as the wrapper — the actor column always names whoever did the write:
|
|
768
|
+
On Postgres the RLS migration adds a database-side backstop: `BEFORE INSERT` / `BEFORE UPDATE` triggers on every feature table (`public.set_audit_fields_on_insert()` / `_on_update()`). They set `created_at` / `modified_at` to the database's `now()` truncated to the millisecond (`date_trunc('milliseconds', now())`) and apply the same actor rule as the wrapper — the actor column always names whoever did the write:
|
|
769
769
|
|
|
770
770
|
- a verified caller (`auth.user_id()`) always wins, so no request can write someone else's id;
|
|
771
771
|
- with no verified caller — a `scope:` principal, a delegated principal, the service lane, a `system:` actor — the actor the Worker already stamped is kept;
|
|
@@ -773,6 +773,16 @@ On Postgres the RLS migration adds a database-side backstop: `BEFORE INSERT` / `
|
|
|
773
773
|
|
|
774
774
|
`created_at` / `created_by` never change on update.
|
|
775
775
|
|
|
776
|
+
**Postgres stores managed timestamps at millisecond precision.** `createdAt` / `modifiedAt` / `deletedAt` are `timestamp(3) with time zone`, the same precision as D1's ISO text, a JS `Date`, and the wire format (`.sssZ`). A keyset cursor carries its boundary value through a `Date`, so a microsecond column would never compare equal to the cursor: ascending pages repeated rows and descending pages skipped rows that shared a millisecond (#602). The triggers truncate rather than round, so a stamp never lands after the transaction's `now()`. The column `DEFAULT now()` (reached only by raw SQL on a table without the triggers) is rounded to the millisecond by Postgres. Timestamp columns you declare yourself keep the precision you give them.
|
|
777
|
+
|
|
778
|
+
Recompiling a Postgres project last compiled by 0.69.0 or earlier adds a migration that changes each managed column's type:
|
|
779
|
+
|
|
780
|
+
```sql
|
|
781
|
+
ALTER TABLE "app"."notes" ALTER COLUMN "created_at" SET DATA TYPE timestamp (3) with time zone USING "created_at"::timestamp (3) with time zone;
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
Existing values are **rounded** to the nearest millisecond (`…08.624500` becomes `…08.625`). The type change rewrites the table under an `ACCESS EXCLUSIVE` lock, so apply it in a quiet window on large tables. The same compile re-emits the trigger functions (`CREATE OR REPLACE`) in a new RLS migration.
|
|
785
|
+
|
|
776
786
|
Because the value would be discarded anyway, the generated `db` handle refuses it at the type level: on the scoped `db`, `.insert().values()` types `createdAt` / `modifiedAt` / `createdBy` / `modifiedBy` / `deletedAt` / `deletedBy` as `?: never`, and `.update().set()` types the audit quartet plus `deletedBy` the same way. Supplying one is a **compile error** — not a silent discard.
|
|
777
787
|
|
|
778
788
|
```ts
|
|
@@ -349,7 +349,7 @@ so it can only ever carry the role the caller actually proved this request.
|
|
|
349
349
|
- A **bulk-grant lane** (`{ roles: [...] }` or `{ team: true }`) mints **no** scope role — it opens the gate via the caller's org role without proving a relationship. The gate passes; the caller carries their org role, not a minted scope role.
|
|
350
350
|
- **The org claim is only ever signed beside a membership role.** Every mint site — `/scope/v1/enter`, the namespace resolver, `/api/v1/token` — writes `orgId` into the token only when a membership `role` accompanies it, and the auth middleware ignores an `orgId` claim that arrives without a `role`. A relationship-promoted tenant (the in-request `ctx.activeOrgId` stamped from the proven row so the firewall resolves) is never persisted as a bare tenant grant.
|
|
351
351
|
- **`/scope/v1/enter` drops the org claims for a foreign-tenant instance.** When the relationship's `from` table carries an organization column, the enter route reads it off the proven row (the same row the probe already fetched — no extra query) and compares it with `ctx.activeOrgId`. A mismatch — an org-B member entering an org-A event — mints the token **without** `orgId` / `role`: a relationship-only principal, exactly the state the namespace resolver gives the same caller. The caller keeps their org seat for org-B requests by using their session or a plain `/api/v1/token`; the scope token is for the scope. A `from` table with no organization column (a global reference relationship) leaves the claim untouched.
|
|
352
|
-
- **Every mint tenant-binds the instance.** A relationship row is matched without tenant scoping (a cross-tenant attendee has no `activeOrgId`), so the row alone can't prove which tenant's instance it names. When the relationship's `from` table carries an organization column, every site that mints from a relationship row — `/scope/v1/enter`, [`ctx.mintScope`](#sessionless-scope-mint--ctxmintscope), and this namespace resolver (the in-memory stamp **and** the `mintScope` token) — also loads the **instance** row, through its own firewall with tenant scopes stripped so soft-delete still applies, and grants the role only when the instance's organization equals the proving row's. A row created in org B naming org A's event proves nothing about org A and grants nothing; a deleted instance grants nothing. (The namespace gate itself still passes on the proven row; the caller just carries no scope for the foreign instance.) The instance table is `authz.scopes.<kind>.instance` when declared (`instance: 'events'`), else the target of the relationship's `resource.column` foreign key, else the one table whose firewall pins its primary key to `ctx.scope.<kind>` (`{ field: 'id', equals: 'ctx.scope.event' }`). Several such tables is a compile error naming them — set `instance`. If nothing resolves, the compiler warns: set `instance` (or declare the FK) so the instance can be bound. A `from` table with no organization column has no tenant to compare, so it gets no binding.
|
|
352
|
+
- **Every mint tenant-binds the instance.** A relationship row is matched without tenant scoping (a cross-tenant attendee has no `activeOrgId`), so the row alone can't prove which tenant's instance it names. When the relationship's `from` table carries an organization column, every site that mints from a relationship row — `/scope/v1/enter`, [`ctx.mintScope`](#sessionless-scope-mint--ctxmintscope), and this namespace resolver (the in-memory stamp **and** the `mintScope` token) — also loads the **instance** row, through its own firewall with tenant scopes stripped so soft-delete still applies, and grants the role only when the instance's organization equals the proving row's. A row created in org B naming org A's event proves nothing about org A and grants nothing; a deleted instance grants nothing. (The namespace gate itself still passes on the proven row; the caller just carries no scope for the foreign instance.) The instance table is `authz.scopes.<kind>.instance` when declared (`instance: 'events'`), else the target of the relationship's `resource.column` foreign key, else the one table whose firewall pins its primary key to `ctx.scope.<kind>` (`{ field: 'id', equals: 'ctx.scope.event' }`). Several such tables is a compile error naming them — set `instance`. If nothing resolves, the compiler warns: set `instance` (or declare the FK) so the instance can be bound. A `from` table with no organization column has no tenant to compare, so it gets no binding. When the namespace gate already hydrated the instance table by the same path param, the resolver takes the instance's organization from `ctx.<exposeAs>` instead of reading it again — that row passed the table's full firewall, and any row the full firewall admits, the tenant-stripped one admits too.
|
|
353
353
|
|
|
354
354
|
### The bulk-grant lane is tenant-bound
|
|
355
355
|
|
|
@@ -365,6 +365,12 @@ gets). No relationship → `403`. Any `ctx.roles`-based check in the action then
|
|
|
365
365
|
fails for them, scoped-db inserts stamp the *instance's* org, and the
|
|
366
366
|
namespace re-mint carries no org claim.
|
|
367
367
|
|
|
368
|
+
The check and the hydration are one read for a caller in their own org: the
|
|
369
|
+
resolver loads the row by id, `ctx.activeOrgId`, and the table's firewall, and
|
|
370
|
+
uses it as `ctx.<exposeAs>`. A miss falls back to the tenant-only check, so a
|
|
371
|
+
foreign instance still re-evaluates through the relationship lanes and an
|
|
372
|
+
own-tenant row the firewall hides (soft-deleted, say) still `404`s.
|
|
373
|
+
|
|
368
374
|
Multi-target namespaces (lanes that hydrate *different* tables) hydrate nothing
|
|
369
375
|
for a role caller, so there is nothing to bind there — put the tenant check in
|
|
370
376
|
the firewall of each table instead (an org arm in an [`any` group tenant-binds
|
|
@@ -202,7 +202,7 @@ The compiler always emits a per-route rule for **every** credential endpoint
|
|
|
202
202
|
Better Auth mounts — not just password sign-in — so an OTP verify door (a
|
|
203
203
|
6-digit, 10<sup>6</sup>-space code) is never left under the 100/min general
|
|
204
204
|
limit. Your `customRules` **merge on top**: declare a path to change its limit,
|
|
205
|
-
or add paths for project plugins.
|
|
205
|
+
`false` to exempt it, or add paths for project plugins.
|
|
206
206
|
|
|
207
207
|
| Route(s) | Default | Reasoning |
|
|
208
208
|
|----------|---------|-----------|
|
|
@@ -214,6 +214,7 @@ or add paths for project plugins.
|
|
|
214
214
|
| `/phone-number/send-otp`, `/phone-number/verify`, `/phone-number/request-password-reset`, `/phone-number/reset-password` | 5/min per IP | SMS OTP brute force + SMS cost |
|
|
215
215
|
| `/two-factor/send-otp`, `/two-factor/verify-otp`, `/two-factor/verify-totp`, `/two-factor/verify-backup-code` | 5/min per IP | Second-factor brute force |
|
|
216
216
|
| `/device/init` / `/device/poll` / `/device/token` | 5 / 30 / 10 per min per IP | Device-code enumeration, polling, token exchange |
|
|
217
|
+
| `/get-session`, `/token` | **exempt** | Read-only, called on every page load; not credential doors. With database storage each limited call is a counter read and write in front of the session check. Declare the path in `customRules` to limit it again |
|
|
217
218
|
| Everything else under `/auth/v1` | `max` (100/min per IP) | General abuse prevention |
|
|
218
219
|
|
|
219
220
|
Set an edge rate-limit binding as well for defence in depth
|
|
@@ -1460,11 +1460,11 @@ export const interviewScores = pgTable('interview_scores', {
|
|
|
1460
1460
|
interviewId: text('interview_id').notNull(),
|
|
1461
1461
|
rating: integer('rating').notNull(),
|
|
1462
1462
|
// ── quickback:audit (compiler-managed — edits are validated, not merged) ──
|
|
1463
|
-
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
1464
|
-
modifiedAt: timestamp('modified_at', { withTimezone: true }).notNull().defaultNow().$onUpdate(() => new Date()),
|
|
1463
|
+
createdAt: timestamp('created_at', { withTimezone: true, precision: 3 }).notNull().defaultNow(),
|
|
1464
|
+
modifiedAt: timestamp('modified_at', { withTimezone: true, precision: 3 }).notNull().defaultNow().$onUpdate(() => new Date()),
|
|
1465
1465
|
createdBy: text('created_by'),
|
|
1466
1466
|
modifiedBy: text('modified_by'),
|
|
1467
|
-
deletedAt: timestamp('deleted_at', { withTimezone: true }),
|
|
1467
|
+
deletedAt: timestamp('deleted_at', { withTimezone: true, precision: 3 }),
|
|
1468
1468
|
deletedBy: text('deleted_by'),
|
|
1469
1469
|
});
|
|
1470
1470
|
```
|
|
@@ -1482,10 +1482,16 @@ Tables **with** `defineTable(...)` are unaffected — existing `sqliteTable`
|
|
|
1482
1482
|
sources with a resource config still compile to the Postgres dialect
|
|
1483
1483
|
automatically. Managed audit timestamps declared in the SQLite shape
|
|
1484
1484
|
(`createdAt` / `modifiedAt` / `deletedAt` as `text`) are emitted as
|
|
1485
|
-
`timestamptz`, like every other Postgres table — the audit wrapper and the RLS
|
|
1485
|
+
`timestamptz(3)`, like every other Postgres table — the audit wrapper and the RLS
|
|
1486
1486
|
audit triggers both stamp timestamps, not strings. API responses carry the same
|
|
1487
1487
|
ISO-8601 string as on D1.
|
|
1488
1488
|
|
|
1489
|
+
Managed audit timestamps are stored at millisecond precision (`timestamptz(3)`),
|
|
1490
|
+
and the audit triggers stamp `date_trunc('milliseconds', now())`, so keyset
|
|
1491
|
+
cursors page them exactly. Projects last compiled by 0.69.0 or earlier get a
|
|
1492
|
+
type-change migration on the next compile that rounds existing values — see
|
|
1493
|
+
[How auto-injection works](/define/schema#how-auto-injection-works-two-layers).
|
|
1494
|
+
|
|
1489
1495
|
## When to choose Neon vs D1
|
|
1490
1496
|
|
|
1491
1497
|
| Factor | Neon | D1 |
|
|
@@ -187,7 +187,7 @@ Claude generates correct syntax for your database:
|
|
|
187
187
|
createdAt: text("created_at").notNull().default('1970-01-01T00:00:00.000Z').$defaultFn(() => new Date().toISOString())
|
|
188
188
|
|
|
189
189
|
// PostgreSQL / Neon
|
|
190
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
190
|
+
createdAt: timestamp("created_at", { withTimezone: true, precision: 3 }).notNull().defaultNow()
|
|
191
191
|
```
|
|
192
192
|
|
|
193
193
|
In the `q` DSL you write `...q.audit()` instead and the compiler emits the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quickback-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.70.0",
|
|
4
4
|
"description": "CLI for Quickback — define your backend in TypeScript, compile to a fully wired Cloudflare Worker (or Bun / Node) with auth, database, migrations, security, CMS, and Account UI.",
|
|
5
5
|
"author": "Kardoe Incorporated <paul@kardoe.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -91,7 +91,7 @@ currently wired into the emitted route.
|
|
|
91
91
|
- `count` — number of records returned on this page
|
|
92
92
|
- `page` / `pageSize` — derived from `?offset=` and `?limit=`
|
|
93
93
|
- `hasMore` — whether more rows exist in the queried direction. Without `?total=true` it comes from a `limit + 1` over-fetch probe, so it never lies on a final page that exactly fills the limit; with `?total=true` it is page arithmetic (`page < totalPages`) on offset pages, and the probe again on cursor pages.
|
|
94
|
-
- `nextCursor` / `prevCursor` — keyset cursors; pass them back as `?starting_after=` and `?ending_before=`. Treat them as opaque, but they are encoded, not encrypted: they carry the boundary row's sort-key values. Either can be `null` — including when the sort includes a [masked](/define/masking) column the caller may sort by (`query.roles`) but not see (`show.roles`), or a column the response does not carry (a view sorting on a field it doesn't list, or `?fields=` without the sort key); page with `?offset=` in that case.
|
|
94
|
+
- `nextCursor` / `prevCursor` — keyset cursors; pass them back as `?starting_after=` and `?ending_before=`. Treat them as opaque, but they are encoded, not encrypted: they carry the boundary row's sort-key values. Either can be `null` — including when the sort includes a [masked](/define/masking) column the caller may sort by (`query.roles`) but not see (`show.roles`), or a column the response does not carry (a view sorting on a field it doesn't list, or `?fields=` without the sort key); page with `?offset=` in that case. A cursor carries a timestamp sort key at millisecond precision, so sort on a column that stores milliseconds: the managed `createdAt` / `modifiedAt` / `deletedAt` do on both dialects (Postgres stores them as `timestamptz(3)`). A Postgres timestamp column you declare with microsecond precision and fill with `now()` can repeat or skip rows across pages.
|
|
95
95
|
- `total` / `totalPages` — present **only** when the request passed `?total=true` (see below)
|
|
96
96
|
|
|
97
97
|
There is no `limit` or `offset` member in `pagination`.
|
|
@@ -424,7 +424,7 @@ The compiler emits one synthetic `src/routes/__namespace-event-scope.routes.ts`
|
|
|
424
424
|
|
|
425
425
|
### Multi-lane via — first match wins
|
|
426
426
|
|
|
427
|
-
When more than one relationship can authorize a caller for the namespaced resource, pass `via:` as an array. The middleware
|
|
427
|
+
When more than one relationship can authorize a caller for the namespaced resource, pass `via:` as an array. The middleware starts every lane's probe at once and takes the first match in declaration order — a later lane never wins over an earlier lane that also matches, and `ctx.<exposeAs>` is hydrated from the lane that won. A probe that fails surfaces only when every earlier lane missed; a failure in a lane after the winner is ignored.
|
|
428
428
|
|
|
429
429
|
```typescript
|
|
430
430
|
authz: {
|
|
@@ -42,10 +42,30 @@ export default defineBundle({
|
|
|
42
42
|
soft-delete filter apply by construction — and the target table's REAL
|
|
43
43
|
mask function is applied (the same read projection the CRUD list endpoint
|
|
44
44
|
runs), so masked columns are safe to include. Every list slice lands as
|
|
45
|
-
`{ data: rows }`
|
|
45
|
+
`{ data: rows, hasMore, nextCursor }` — `data` is the per-resource
|
|
46
|
+
cache-seed contract; `hasMore` and `nextCursor` are additive.
|
|
47
|
+
- **Ordering is deterministic.** `orderBy` keys apply in the order you list
|
|
48
|
+
them. The primary key `id` is appended ascending as the final tie-break
|
|
49
|
+
unless you already listed it, the same rule as the
|
|
50
|
+
[CRUD list](/api/query-params#pagination). Without a unique final key,
|
|
51
|
+
`LIMIT` picks among tied rows arbitrarily on Postgres.
|
|
52
|
+
- **Truncation is visible.** With `limit`, the section reads one extra row:
|
|
53
|
+
`hasMore: true` means more rows match than were returned. Without `limit`,
|
|
54
|
+
`hasMore` is always `false`.
|
|
55
|
+
- **`nextCursor` continues on the table's CRUD list.** When `hasMore` is
|
|
56
|
+
true, `nextCursor` is the same keyset cursor the CRUD list emits. Fetch
|
|
57
|
+
the next page with that list endpoint, passing the section's `where` as
|
|
58
|
+
equality filters, its `orderBy` as `?sort=`, and the cursor as
|
|
59
|
+
`?starting_after=`. For `orderBy: [{ createdAt: "desc" }]` and
|
|
60
|
+
`where: { eventId }`, that is
|
|
61
|
+
`GET /api/v1/guests?eventId=<id>&sort=-createdAt&starting_after=<nextCursor>`.
|
|
62
|
+
The CRUD list appends the same `id` tie-break, so the cursor lines up.
|
|
63
|
+
`nextCursor` is `null` when there is nothing more, when `columns` omits a
|
|
64
|
+
sort key (or `id`), or when a sort key is [masked](/define/masking) for the
|
|
65
|
+
caller. In those cases, raise `limit` or page the CRUD list with `?offset=`.
|
|
46
66
|
- **`sections` filter**: omitted/empty = all. An un-wanted list section
|
|
47
|
-
returns `{ data: [] }` (drop-in
|
|
48
|
-
un-wanted `custom` sections are absent.
|
|
67
|
+
returns `{ data: [], hasMore: false, nextCursor: null }` (drop-in
|
|
68
|
+
compatible with existing clients); un-wanted `custom` sections are absent.
|
|
49
69
|
- **All sections run in one `Promise.all`.**
|
|
50
70
|
- **ETag**: SHA-1 hex over `{ scopeSeed: <path params>, userId, payload }`.
|
|
51
71
|
An `ifNoneMatch` match returns `{ success: true, etag, notModified: true }`
|
|
@@ -157,9 +157,9 @@ Reference implementations, both ports of the same table:
|
|
|
157
157
|
- `examples/recruitment/quickback/features/interviews/interview_scores.ts` (SQLite)
|
|
158
158
|
- `examples/recruitment-neon/quickback/features/interviews/interview_scores.ts` (Postgres)
|
|
159
159
|
|
|
160
|
-
Postgres uses `timestamp("…", { withTimezone: true }).notNull().defaultNow()` for the
|
|
160
|
+
Postgres uses `timestamp("…", { withTimezone: true, precision: 3 }).notNull().defaultNow()` for the
|
|
161
161
|
timestamps, `.$onUpdate(() => new Date())` on `modifiedAt`, plain `text(…)` for the
|
|
162
|
-
actor columns, and `timestamp("deleted_at", { withTimezone: true })` for `deletedAt`.
|
|
162
|
+
actor columns, and `timestamp("deleted_at", { withTimezone: true, precision: 3 })` for `deletedAt`.
|
|
163
163
|
|
|
164
164
|
## Attaching pillars to a raw Drizzle table
|
|
165
165
|
|
|
@@ -535,7 +535,7 @@ Default to `feature()`. Drop to Drizzle only when:
|
|
|
535
535
|
|
|
536
536
|
Features in the same project may mix freely — Quickback dispatches per feature — so one interop table doesn't force the rest of the project off `feature()`.
|
|
537
537
|
|
|
538
|
-
One dialect rule: interop files **without** a `defineTable(...)` default export (internal child tables) are not dialect-translated — author them in the target database's dialect. On Postgres providers (`neon`, `planetscale-postgres`), a `sqliteTable` interop source without `defineTable` is a compile-time error; write it with `pgTable` from `drizzle-orm/pg-core` instead. Sources **with** `defineTable(...)` keep compiling across dialects automatically. On Postgres, managed audit timestamps a `sqliteTable` source declares in the SQLite shape (`createdAt` / `modifiedAt` / `deletedAt` as `text`) are emitted as `timestamptz`, the same as every other Postgres table; API responses still carry the same ISO-8601 string.
|
|
538
|
+
One dialect rule: interop files **without** a `defineTable(...)` default export (internal child tables) are not dialect-translated — author them in the target database's dialect. On Postgres providers (`neon`, `planetscale-postgres`), a `sqliteTable` interop source without `defineTable` is a compile-time error; write it with `pgTable` from `drizzle-orm/pg-core` instead. Sources **with** `defineTable(...)` keep compiling across dialects automatically. On Postgres, managed audit timestamps a `sqliteTable` source declares in the SQLite shape (`createdAt` / `modifiedAt` / `deletedAt` as `text`) are emitted as `timestamptz(3)`, the same as every other Postgres table; API responses still carry the same ISO-8601 string.
|
|
539
539
|
|
|
540
540
|
### Drizzle Column Types
|
|
541
541
|
|
|
@@ -765,7 +765,7 @@ The scoped `db` an action receives types every managed key as `?: never` on `.in
|
|
|
765
765
|
|
|
766
766
|
The runtime layer **hard-stamps** every audit field on every write, so the audit log can never be forged by a crafted request body or by a client echoing a row back into a PATCH.
|
|
767
767
|
|
|
768
|
-
On Postgres the RLS migration adds a database-side backstop: `BEFORE INSERT` / `BEFORE UPDATE` triggers on every feature table (`public.set_audit_fields_on_insert()` / `_on_update()`). They set `created_at` / `modified_at` to the database's `now()` and apply the same actor rule as the wrapper — the actor column always names whoever did the write:
|
|
768
|
+
On Postgres the RLS migration adds a database-side backstop: `BEFORE INSERT` / `BEFORE UPDATE` triggers on every feature table (`public.set_audit_fields_on_insert()` / `_on_update()`). They set `created_at` / `modified_at` to the database's `now()` truncated to the millisecond (`date_trunc('milliseconds', now())`) and apply the same actor rule as the wrapper — the actor column always names whoever did the write:
|
|
769
769
|
|
|
770
770
|
- a verified caller (`auth.user_id()`) always wins, so no request can write someone else's id;
|
|
771
771
|
- with no verified caller — a `scope:` principal, a delegated principal, the service lane, a `system:` actor — the actor the Worker already stamped is kept;
|
|
@@ -773,6 +773,16 @@ On Postgres the RLS migration adds a database-side backstop: `BEFORE INSERT` / `
|
|
|
773
773
|
|
|
774
774
|
`created_at` / `created_by` never change on update.
|
|
775
775
|
|
|
776
|
+
**Postgres stores managed timestamps at millisecond precision.** `createdAt` / `modifiedAt` / `deletedAt` are `timestamp(3) with time zone`, the same precision as D1's ISO text, a JS `Date`, and the wire format (`.sssZ`). A keyset cursor carries its boundary value through a `Date`, so a microsecond column would never compare equal to the cursor: ascending pages repeated rows and descending pages skipped rows that shared a millisecond (#602). The triggers truncate rather than round, so a stamp never lands after the transaction's `now()`. The column `DEFAULT now()` (reached only by raw SQL on a table without the triggers) is rounded to the millisecond by Postgres. Timestamp columns you declare yourself keep the precision you give them.
|
|
777
|
+
|
|
778
|
+
Recompiling a Postgres project last compiled by 0.69.0 or earlier adds a migration that changes each managed column's type:
|
|
779
|
+
|
|
780
|
+
```sql
|
|
781
|
+
ALTER TABLE "app"."notes" ALTER COLUMN "created_at" SET DATA TYPE timestamp (3) with time zone USING "created_at"::timestamp (3) with time zone;
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
Existing values are **rounded** to the nearest millisecond (`…08.624500` becomes `…08.625`). The type change rewrites the table under an `ACCESS EXCLUSIVE` lock, so apply it in a quiet window on large tables. The same compile re-emits the trigger functions (`CREATE OR REPLACE`) in a new RLS migration.
|
|
785
|
+
|
|
776
786
|
Because the value would be discarded anyway, the generated `db` handle refuses it at the type level: on the scoped `db`, `.insert().values()` types `createdAt` / `modifiedAt` / `createdBy` / `modifiedBy` / `deletedAt` / `deletedBy` as `?: never`, and `.update().set()` types the audit quartet plus `deletedBy` the same way. Supplying one is a **compile error** — not a silent discard.
|
|
777
787
|
|
|
778
788
|
```ts
|
|
@@ -349,7 +349,7 @@ so it can only ever carry the role the caller actually proved this request.
|
|
|
349
349
|
- A **bulk-grant lane** (`{ roles: [...] }` or `{ team: true }`) mints **no** scope role — it opens the gate via the caller's org role without proving a relationship. The gate passes; the caller carries their org role, not a minted scope role.
|
|
350
350
|
- **The org claim is only ever signed beside a membership role.** Every mint site — `/scope/v1/enter`, the namespace resolver, `/api/v1/token` — writes `orgId` into the token only when a membership `role` accompanies it, and the auth middleware ignores an `orgId` claim that arrives without a `role`. A relationship-promoted tenant (the in-request `ctx.activeOrgId` stamped from the proven row so the firewall resolves) is never persisted as a bare tenant grant.
|
|
351
351
|
- **`/scope/v1/enter` drops the org claims for a foreign-tenant instance.** When the relationship's `from` table carries an organization column, the enter route reads it off the proven row (the same row the probe already fetched — no extra query) and compares it with `ctx.activeOrgId`. A mismatch — an org-B member entering an org-A event — mints the token **without** `orgId` / `role`: a relationship-only principal, exactly the state the namespace resolver gives the same caller. The caller keeps their org seat for org-B requests by using their session or a plain `/api/v1/token`; the scope token is for the scope. A `from` table with no organization column (a global reference relationship) leaves the claim untouched.
|
|
352
|
-
- **Every mint tenant-binds the instance.** A relationship row is matched without tenant scoping (a cross-tenant attendee has no `activeOrgId`), so the row alone can't prove which tenant's instance it names. When the relationship's `from` table carries an organization column, every site that mints from a relationship row — `/scope/v1/enter`, [`ctx.mintScope`](#sessionless-scope-mint--ctxmintscope), and this namespace resolver (the in-memory stamp **and** the `mintScope` token) — also loads the **instance** row, through its own firewall with tenant scopes stripped so soft-delete still applies, and grants the role only when the instance's organization equals the proving row's. A row created in org B naming org A's event proves nothing about org A and grants nothing; a deleted instance grants nothing. (The namespace gate itself still passes on the proven row; the caller just carries no scope for the foreign instance.) The instance table is `authz.scopes.<kind>.instance` when declared (`instance: 'events'`), else the target of the relationship's `resource.column` foreign key, else the one table whose firewall pins its primary key to `ctx.scope.<kind>` (`{ field: 'id', equals: 'ctx.scope.event' }`). Several such tables is a compile error naming them — set `instance`. If nothing resolves, the compiler warns: set `instance` (or declare the FK) so the instance can be bound. A `from` table with no organization column has no tenant to compare, so it gets no binding.
|
|
352
|
+
- **Every mint tenant-binds the instance.** A relationship row is matched without tenant scoping (a cross-tenant attendee has no `activeOrgId`), so the row alone can't prove which tenant's instance it names. When the relationship's `from` table carries an organization column, every site that mints from a relationship row — `/scope/v1/enter`, [`ctx.mintScope`](#sessionless-scope-mint--ctxmintscope), and this namespace resolver (the in-memory stamp **and** the `mintScope` token) — also loads the **instance** row, through its own firewall with tenant scopes stripped so soft-delete still applies, and grants the role only when the instance's organization equals the proving row's. A row created in org B naming org A's event proves nothing about org A and grants nothing; a deleted instance grants nothing. (The namespace gate itself still passes on the proven row; the caller just carries no scope for the foreign instance.) The instance table is `authz.scopes.<kind>.instance` when declared (`instance: 'events'`), else the target of the relationship's `resource.column` foreign key, else the one table whose firewall pins its primary key to `ctx.scope.<kind>` (`{ field: 'id', equals: 'ctx.scope.event' }`). Several such tables is a compile error naming them — set `instance`. If nothing resolves, the compiler warns: set `instance` (or declare the FK) so the instance can be bound. A `from` table with no organization column has no tenant to compare, so it gets no binding. When the namespace gate already hydrated the instance table by the same path param, the resolver takes the instance's organization from `ctx.<exposeAs>` instead of reading it again — that row passed the table's full firewall, and any row the full firewall admits, the tenant-stripped one admits too.
|
|
353
353
|
|
|
354
354
|
### The bulk-grant lane is tenant-bound
|
|
355
355
|
|
|
@@ -365,6 +365,12 @@ gets). No relationship → `403`. Any `ctx.roles`-based check in the action then
|
|
|
365
365
|
fails for them, scoped-db inserts stamp the *instance's* org, and the
|
|
366
366
|
namespace re-mint carries no org claim.
|
|
367
367
|
|
|
368
|
+
The check and the hydration are one read for a caller in their own org: the
|
|
369
|
+
resolver loads the row by id, `ctx.activeOrgId`, and the table's firewall, and
|
|
370
|
+
uses it as `ctx.<exposeAs>`. A miss falls back to the tenant-only check, so a
|
|
371
|
+
foreign instance still re-evaluates through the relationship lanes and an
|
|
372
|
+
own-tenant row the firewall hides (soft-deleted, say) still `404`s.
|
|
373
|
+
|
|
368
374
|
Multi-target namespaces (lanes that hydrate *different* tables) hydrate nothing
|
|
369
375
|
for a role caller, so there is nothing to bind there — put the tenant check in
|
|
370
376
|
the firewall of each table instead (an org arm in an [`any` group tenant-binds
|
|
@@ -202,7 +202,7 @@ The compiler always emits a per-route rule for **every** credential endpoint
|
|
|
202
202
|
Better Auth mounts — not just password sign-in — so an OTP verify door (a
|
|
203
203
|
6-digit, 10<sup>6</sup>-space code) is never left under the 100/min general
|
|
204
204
|
limit. Your `customRules` **merge on top**: declare a path to change its limit,
|
|
205
|
-
or add paths for project plugins.
|
|
205
|
+
`false` to exempt it, or add paths for project plugins.
|
|
206
206
|
|
|
207
207
|
| Route(s) | Default | Reasoning |
|
|
208
208
|
|----------|---------|-----------|
|
|
@@ -214,6 +214,7 @@ or add paths for project plugins.
|
|
|
214
214
|
| `/phone-number/send-otp`, `/phone-number/verify`, `/phone-number/request-password-reset`, `/phone-number/reset-password` | 5/min per IP | SMS OTP brute force + SMS cost |
|
|
215
215
|
| `/two-factor/send-otp`, `/two-factor/verify-otp`, `/two-factor/verify-totp`, `/two-factor/verify-backup-code` | 5/min per IP | Second-factor brute force |
|
|
216
216
|
| `/device/init` / `/device/poll` / `/device/token` | 5 / 30 / 10 per min per IP | Device-code enumeration, polling, token exchange |
|
|
217
|
+
| `/get-session`, `/token` | **exempt** | Read-only, called on every page load; not credential doors. With database storage each limited call is a counter read and write in front of the session check. Declare the path in `customRules` to limit it again |
|
|
217
218
|
| Everything else under `/auth/v1` | `max` (100/min per IP) | General abuse prevention |
|
|
218
219
|
|
|
219
220
|
Set an edge rate-limit binding as well for defence in depth
|
|
@@ -1460,11 +1460,11 @@ export const interviewScores = pgTable('interview_scores', {
|
|
|
1460
1460
|
interviewId: text('interview_id').notNull(),
|
|
1461
1461
|
rating: integer('rating').notNull(),
|
|
1462
1462
|
// ── quickback:audit (compiler-managed — edits are validated, not merged) ──
|
|
1463
|
-
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
1464
|
-
modifiedAt: timestamp('modified_at', { withTimezone: true }).notNull().defaultNow().$onUpdate(() => new Date()),
|
|
1463
|
+
createdAt: timestamp('created_at', { withTimezone: true, precision: 3 }).notNull().defaultNow(),
|
|
1464
|
+
modifiedAt: timestamp('modified_at', { withTimezone: true, precision: 3 }).notNull().defaultNow().$onUpdate(() => new Date()),
|
|
1465
1465
|
createdBy: text('created_by'),
|
|
1466
1466
|
modifiedBy: text('modified_by'),
|
|
1467
|
-
deletedAt: timestamp('deleted_at', { withTimezone: true }),
|
|
1467
|
+
deletedAt: timestamp('deleted_at', { withTimezone: true, precision: 3 }),
|
|
1468
1468
|
deletedBy: text('deleted_by'),
|
|
1469
1469
|
});
|
|
1470
1470
|
```
|
|
@@ -1482,10 +1482,16 @@ Tables **with** `defineTable(...)` are unaffected — existing `sqliteTable`
|
|
|
1482
1482
|
sources with a resource config still compile to the Postgres dialect
|
|
1483
1483
|
automatically. Managed audit timestamps declared in the SQLite shape
|
|
1484
1484
|
(`createdAt` / `modifiedAt` / `deletedAt` as `text`) are emitted as
|
|
1485
|
-
`timestamptz`, like every other Postgres table — the audit wrapper and the RLS
|
|
1485
|
+
`timestamptz(3)`, like every other Postgres table — the audit wrapper and the RLS
|
|
1486
1486
|
audit triggers both stamp timestamps, not strings. API responses carry the same
|
|
1487
1487
|
ISO-8601 string as on D1.
|
|
1488
1488
|
|
|
1489
|
+
Managed audit timestamps are stored at millisecond precision (`timestamptz(3)`),
|
|
1490
|
+
and the audit triggers stamp `date_trunc('milliseconds', now())`, so keyset
|
|
1491
|
+
cursors page them exactly. Projects last compiled by 0.69.0 or earlier get a
|
|
1492
|
+
type-change migration on the next compile that rounds existing values — see
|
|
1493
|
+
[How auto-injection works](/define/schema#how-auto-injection-works-two-layers).
|
|
1494
|
+
|
|
1489
1495
|
## When to choose Neon vs D1
|
|
1490
1496
|
|
|
1491
1497
|
| Factor | Neon | D1 |
|
|
@@ -187,7 +187,7 @@ Claude generates correct syntax for your database:
|
|
|
187
187
|
createdAt: text("created_at").notNull().default('1970-01-01T00:00:00.000Z').$defaultFn(() => new Date().toISOString())
|
|
188
188
|
|
|
189
189
|
// PostgreSQL / Neon
|
|
190
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
190
|
+
createdAt: timestamp("created_at", { withTimezone: true, precision: 3 }).notNull().defaultNow()
|
|
191
191
|
```
|
|
192
192
|
|
|
193
193
|
In the `q` DSL you write `...q.audit()` instead and the compiler emits the
|