@quickback-dev/cli 0.66.11 → 0.66.13
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/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +14 -0
- package/dist/commands/deploy.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/api-client.d.ts +8 -0
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/deployment-target.d.ts +29 -0
- package/dist/lib/deployment-target.d.ts.map +1 -1
- package/dist/lib/deployment-target.js +26 -2
- package/dist/lib/deployment-target.js.map +1 -1
- package/dist/lib/deployment-target.test.js +37 -1
- package/dist/lib/deployment-target.test.js.map +1 -1
- package/dist/lib/migrations/command-runner.d.ts +2 -0
- package/dist/lib/migrations/command-runner.d.ts.map +1 -1
- package/dist/lib/migrations/command-runner.js +15 -6
- package/dist/lib/migrations/command-runner.js.map +1 -1
- package/dist/lib/migrations/command-runner.test.d.ts +2 -0
- package/dist/lib/migrations/command-runner.test.d.ts.map +1 -0
- package/dist/lib/migrations/command-runner.test.js +19 -0
- package/dist/lib/migrations/command-runner.test.js.map +1 -0
- package/dist/lib/migrations/drizzle-wrapper.d.ts.map +1 -1
- package/dist/lib/migrations/drizzle-wrapper.js +8 -1
- package/dist/lib/migrations/drizzle-wrapper.js.map +1 -1
- package/dist/lib/migrations/drizzle.test.js +1 -1
- package/dist/lib/migrations/drizzle.test.js.map +1 -1
- package/dist/lib/migrations/executor.js +2 -5
- package/dist/lib/migrations/executor.js.map +1 -1
- package/dist/lib/migrations/executor.test.js +1 -1
- package/dist/lib/migrations/executor.test.js.map +1 -1
- package/dist/lib/migrations/headless-generate.test.d.ts +2 -0
- package/dist/lib/migrations/headless-generate.test.d.ts.map +1 -0
- package/dist/lib/migrations/headless-generate.test.js +167 -0
- package/dist/lib/migrations/headless-generate.test.js.map +1 -0
- package/dist/lib/migrations/plan.js +6 -0
- package/dist/lib/migrations/plan.js.map +1 -1
- package/dist/lib/migrations/postprocessors/better-auth-upgrade.d.ts +16 -5
- package/dist/lib/migrations/postprocessors/better-auth-upgrade.d.ts.map +1 -1
- package/dist/lib/migrations/postprocessors/better-auth-upgrade.js +32 -102
- package/dist/lib/migrations/postprocessors/better-auth-upgrade.js.map +1 -1
- package/dist/lib/migrations/postprocessors/index.d.ts.map +1 -1
- package/dist/lib/migrations/postprocessors/index.js +73 -1
- package/dist/lib/migrations/postprocessors/index.js.map +1 -1
- package/dist/lib/migrations/postprocessors/index.test.js +95 -0
- package/dist/lib/migrations/postprocessors/index.test.js.map +1 -1
- package/dist/lib/migrations/postprocessors/trigger-sql.d.ts +18 -0
- package/dist/lib/migrations/postprocessors/trigger-sql.d.ts.map +1 -1
- package/dist/lib/migrations/postprocessors/trigger-sql.js +63 -0
- package/dist/lib/migrations/postprocessors/trigger-sql.js.map +1 -1
- package/dist/lib/migrations/prompt-runner.js +18 -4
- package/dist/lib/migrations/prompt-runner.js.map +1 -1
- package/dist/lib/migrations/prompt-runner.test.js +3 -6
- package/dist/lib/migrations/prompt-runner.test.js.map +1 -1
- package/dist/lib/migrations/types.d.ts +2 -1
- package/dist/lib/migrations/types.d.ts.map +1 -1
- package/dist/lib/migrations/types.js +1 -0
- package/dist/lib/migrations/types.js.map +1 -1
- package/dist/skill/docs/configure/index.md +1 -1
- package/dist/skill/docs/define/actions/scoped-db.md +3 -0
- package/dist/skill/docs/define/schema.md +58 -6
- package/dist/skill/docs/define/triggers.md +143 -20
- package/dist/skill/docs/index.md +3 -3
- package/dist/skill/docs/platform/auth/index.md +37 -16
- package/dist/skill/docs/platform/auth/plugins/subscriptions.md +25 -5
- package/dist/skill/docs/platform/database/neon.md +129 -18
- package/dist/skill/docs/platform/database/planetscale-postgres.md +16 -3
- package/dist/skill/docs/platform/index.md +1 -1
- package/dist/skill/docs/platform/storage/r2.md +75 -8
- package/dist/skill/docs/start/index.md +2 -2
- package/dist/skill/docs/tooling/cloud-compiler/troubleshooting.md +11 -0
- package/dist/skill/docs/tooling/output.md +49 -5
- package/dist/skill/docs/tooling/troubleshooting.md +4 -1
- package/package.json +5 -2
- package/src/skill/docs/configure/index.md +1 -1
- package/src/skill/docs/define/actions/scoped-db.md +3 -0
- package/src/skill/docs/define/schema.md +58 -6
- package/src/skill/docs/define/triggers.md +143 -20
- package/src/skill/docs/index.md +3 -3
- package/src/skill/docs/platform/auth/index.md +37 -16
- package/src/skill/docs/platform/auth/plugins/subscriptions.md +25 -5
- package/src/skill/docs/platform/database/neon.md +129 -18
- package/src/skill/docs/platform/database/planetscale-postgres.md +16 -3
- package/src/skill/docs/platform/index.md +1 -1
- package/src/skill/docs/platform/storage/r2.md +75 -8
- package/src/skill/docs/start/index.md +2 -2
- package/src/skill/docs/tooling/cloud-compiler/troubleshooting.md +11 -0
- package/src/skill/docs/tooling/output.md +49 -5
- package/src/skill/docs/tooling/troubleshooting.md +4 -1
|
@@ -27,6 +27,20 @@ comes exclusively from `env.HYPERDRIVE.connectionString`: feature queries and
|
|
|
27
27
|
Better Auth share the generated database helpers. `DATABASE_URL` is then a
|
|
28
28
|
compiler/migration input, not a deployed Worker secret.
|
|
29
29
|
|
|
30
|
+
### Where the tables go
|
|
31
|
+
|
|
32
|
+
One Neon **project** hosts one app, and that app uses the project's existing
|
|
33
|
+
database (`neondb` by default). Quickback's migrations create *schemas* inside
|
|
34
|
+
it — `app` for feature tables, `auth` for Better Auth, plus `webhooks`,
|
|
35
|
+
`audit` and `drizzle` when the project uses them.
|
|
36
|
+
|
|
37
|
+
Do **not** `CREATE DATABASE` per app inside a project. Postgres roles are
|
|
38
|
+
cluster-wide but grants, ownership and the migration ledger are per-database,
|
|
39
|
+
so an extra database silently splits the bootstrap: the roles look right in
|
|
40
|
+
`pg_roles` while the grants live somewhere the Worker never connects to. Point
|
|
41
|
+
`DATABASE_URL` at the project's own database and let the schemas do the
|
|
42
|
+
separating. Two apps means two Neon projects, not two databases.
|
|
43
|
+
|
|
30
44
|
Mixing providers — for example D1 for auth with Neon for features — is not
|
|
31
45
|
supported. The per-service config form is rejected at compile time:
|
|
32
46
|
|
|
@@ -449,6 +463,20 @@ content-addressed `<idx>_quickback_rls_<hash>` migration, so one
|
|
|
449
463
|
appends a new entry — recompiles with unchanged security append nothing. No
|
|
450
464
|
manual SQL application step exists.
|
|
451
465
|
|
|
466
|
+
### The default index set
|
|
467
|
+
|
|
468
|
+
Indexes are Drizzle's, not the security migration's: the compiler writes the
|
|
469
|
+
default set (tenant composite, FK columns, filtered columns, view-sortable
|
|
470
|
+
columns) into the schema source, so drizzle-kit generates and diffs them under
|
|
471
|
+
`<table>_<column>_idx` names. See
|
|
472
|
+
[The default index set](/define/schema#the-default-index-set) for the rules and
|
|
473
|
+
the `...q.indexes(t)` placeholder.
|
|
474
|
+
|
|
475
|
+
Older projects also carry `idx_<table>_<column>` copies the security migration
|
|
476
|
+
used to create. Those are dropped in the security migration's trailing
|
|
477
|
+
"retired indexes" section, which the journal runs after the schema migration
|
|
478
|
+
that created the replacements. Only `idx_*` names are dropped.
|
|
479
|
+
|
|
452
480
|
Quickback also dependency-orders Drizzle's standalone constraint replacements.
|
|
453
481
|
When a composite unique or primary key and its consuming foreign key are both
|
|
454
482
|
replaced, the generated migration drops the dependent foreign key first, drops
|
|
@@ -530,15 +558,25 @@ owner's row. It is the floor under the application, not a second application.
|
|
|
530
558
|
Quickback lowers your `firewall` config — and only your `firewall` config —
|
|
531
559
|
into policies that read the transaction-local claims described above through
|
|
532
560
|
`auth.user_id()`, `get_active_org_id()`, `get_active_team_id()`, `get_scope()`
|
|
533
|
-
and the `get_principal_*()` helpers. Each feature table gets exactly
|
|
534
|
-
policies:
|
|
561
|
+
and the `get_principal_*()` helpers. Each feature table gets exactly three
|
|
562
|
+
policies, plus a fourth only where a delegated-principal lane is declared:
|
|
535
563
|
|
|
536
564
|
| Policy | Kind | What it does |
|
|
537
565
|
|--------|------|--------------|
|
|
538
|
-
| `<table>_deny_anon` | RESTRICTIVE `FOR ALL` | Blocks any query carrying neither a stamped user id, nor a
|
|
566
|
+
| `<table>_deny_anon` | RESTRICTIVE `FOR ALL` | Blocks any query carrying neither a stamped user id, nor the service marker — nor, on a table with a delegated lane, a verified delegated/scope principal |
|
|
539
567
|
| `<table>_service_role` | permissive `FOR ALL` | Admits Worker-internal contexts — see [Background jobs and cross-tenant actions](#background-jobs-and-cross-tenant-actions) |
|
|
540
|
-
| `<table>
|
|
541
|
-
| `<table>
|
|
568
|
+
| `<table>_scope` | permissive `FOR ALL` | The firewall scope predicate. On a soft-deletable table `USING` also requires `deleted_at IS NULL OR public.in_soft_delete()` — see [The soft-delete lane](#the-soft-delete-lane); `WITH CHECK` is the scope predicate alone, so a row can be soft-deleted but never resurrected |
|
|
569
|
+
| `<table>_principal_fence` | RESTRICTIVE `FOR ALL` | **Only on tables with a `databaseAccess` lane or `access.principals`.** Caps every permissive policy, so no policy can broaden a request that carries the wrong principal type |
|
|
570
|
+
|
|
571
|
+
The fence is per-lane, not per-table, because on a table no principal can reach
|
|
572
|
+
it would read `get_principal_type() IS NULL` — blocking every principal, which
|
|
573
|
+
is exactly what leaving them out of `deny_anon` already does. Two policies for
|
|
574
|
+
one outcome; the compiler emits neither.
|
|
575
|
+
|
|
576
|
+
Every helper call inside a policy predicate is emitted as `(SELECT …)`. The
|
|
577
|
+
claims are transaction-local and stamped before the statement, so PostgreSQL
|
|
578
|
+
hoists the call into an **InitPlan** and evaluates it once per statement instead
|
|
579
|
+
of once per scanned row.
|
|
542
580
|
|
|
543
581
|
```typescript
|
|
544
582
|
firewall: [
|
|
@@ -552,13 +590,41 @@ ON "app"."documents" FOR ALL
|
|
|
552
590
|
TO quickback
|
|
553
591
|
USING (
|
|
554
592
|
organization_id = public.get_active_org_id()
|
|
555
|
-
AND deleted_at IS NULL
|
|
593
|
+
AND (deleted_at IS NULL OR public.in_soft_delete())
|
|
556
594
|
)
|
|
557
595
|
WITH CHECK (
|
|
558
596
|
organization_id = public.get_active_org_id()
|
|
559
597
|
);
|
|
560
598
|
```
|
|
561
599
|
|
|
600
|
+
### The soft-delete lane
|
|
601
|
+
|
|
602
|
+
`deleted_at IS NULL` keeps soft-deleted rows out of every caller's reach. On its
|
|
603
|
+
own it also blocks the delete that put them there.
|
|
604
|
+
|
|
605
|
+
PostgreSQL applies a SELECT-applicable policy's `USING` expression to the **new**
|
|
606
|
+
row of an `UPDATE`, not only the existing one, whenever the statement reads the
|
|
607
|
+
relation — which any `UPDATE … WHERE` does. The new row of a soft delete has
|
|
608
|
+
`deleted_at` set, so a bare `deleted_at IS NULL` refuses the statement with
|
|
609
|
+
`42501`, including the generated `DELETE` route's own write. Moving the filter to
|
|
610
|
+
a `FOR SELECT` policy does not help, and neither does dropping `RETURNING`: the
|
|
611
|
+
check follows the filter wherever it goes.
|
|
612
|
+
|
|
613
|
+
So the filter carries a lane. `public.in_soft_delete()` reads the
|
|
614
|
+
transaction-local `quickback.soft_delete` marker, and the generated write
|
|
615
|
+
chokepoint sets it for **exactly** the statement whose payload stamps
|
|
616
|
+
`deletedAt` — the same condition that stamps the audit columns. It is a
|
|
617
|
+
one-shot token: the claims preamble carries it into that statement's
|
|
618
|
+
transaction and clears it, so the next statement of the same request runs
|
|
619
|
+
without it.
|
|
620
|
+
|
|
621
|
+
It is the same trust model as the service marker: Worker-set, never derived from
|
|
622
|
+
request input. And it is narrower — it exempts the soft-delete filter and
|
|
623
|
+
nothing else. Tenancy, ownership and scope stay ANDed beside it, so a statement
|
|
624
|
+
inside the window still cannot cross a tenant; `WITH CHECK` never carries the
|
|
625
|
+
lane, so it cannot land a row the firewall rejects; and the emitted statement
|
|
626
|
+
keeps `deleted_at IS NULL` in its own `WHERE`, so it cannot resurrect one.
|
|
627
|
+
|
|
562
628
|
Exception tables (`firewall: [{ exception: true }]`) keep their permissive
|
|
563
629
|
`<table>_all` policy, and SYSTEM tables — idempotency keys, the webhook store,
|
|
564
630
|
Better Auth rate-limit counters, subscriptions, file metadata — stay
|
|
@@ -593,7 +659,8 @@ have to call still refuses them, and anything reaching the database outside a
|
|
|
593
659
|
generated route holds a caller-scoped handle whose tenant is already fenced.
|
|
594
660
|
|
|
595
661
|
The compiler enforces the shape at compile time. `QB-RLS-SCOPE-POLICY` requires
|
|
596
|
-
|
|
662
|
+
the three policies (and the fence wherever a delegated lane exists — and only
|
|
663
|
+
there), requires a tenant/owner/scope predicate in the scope policy's
|
|
597
664
|
`USING` clause, and **fails the build if any policy body calls `has_any_role`**.
|
|
598
665
|
Opt out with `compiler.securityContracts.rls.requireScopePolicy: false` —
|
|
599
666
|
`requireCrudPolicies` is the pre-016 name for the same key and is still honoured.
|
|
@@ -622,11 +689,14 @@ The retired names include the per-verb auth-table policies
|
|
|
622
689
|
dropped, so an upgraded database converges on the narrower set rather than
|
|
623
690
|
keeping a wider policy nobody emits any more.
|
|
624
691
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
692
|
+
**Indexes are rebuilt once.** The compiler used to infer `idx_<table>_<column>`
|
|
693
|
+
indexes in the security migration, alongside the `<table>_<column>_idx` indexes
|
|
694
|
+
Drizzle generates from the schema. Drizzle now owns the whole default set, so
|
|
695
|
+
the schema migration creates the drizzle-managed index and the security
|
|
696
|
+
migration that follows it in the journal drops the compiler-owned copy — the two
|
|
697
|
+
overlap for the length of one `db:migrate` run and nothing is ever left
|
|
698
|
+
unindexed. Only `idx_*` names are dropped; a drizzle-managed index is never
|
|
699
|
+
touched. See [the default index set](#the-default-index-set).
|
|
630
700
|
|
|
631
701
|
### Delegated principal RLS
|
|
632
702
|
|
|
@@ -717,7 +787,7 @@ tenant predicate can never match), but it means a `databaseAccess` arm is never
|
|
|
717
787
|
a place to write a restriction. A row that satisfies the arm is reachable even
|
|
718
788
|
when the table firewall would not have matched it, and even when it is
|
|
719
789
|
soft-deleted. Write the restriction in `firewall`; the restrictive
|
|
720
|
-
`<table>_deny_anon` and `<table>_principal_fence`
|
|
790
|
+
`<table>_deny_anon` and, where a lane is declared, `<table>_principal_fence` are the only arms
|
|
721
791
|
that cap every lane. The fence also means a table admits a principal type only
|
|
722
792
|
where its `access` (or its lane) names that type — a `ctx.principal.claims.*`
|
|
723
793
|
firewall arm on a table whose access names no principal is unreachable.
|
|
@@ -937,6 +1007,34 @@ precedent — so there is no separate `WEBHOOKS_DB` binding.
|
|
|
937
1007
|
(`requireOrgMember` / endpoint-ownership checks) before querying.
|
|
938
1008
|
- Webhooks require `connectionMode: 'http'`.
|
|
939
1009
|
|
|
1010
|
+
## Managed file storage on Neon
|
|
1011
|
+
|
|
1012
|
+
`fileStorage: { managed: true }` is supported on `http` and `hyperdrive`. The
|
|
1013
|
+
file metadata (`buckets`, `objects`) lives in a dedicated `files` Postgres
|
|
1014
|
+
schema of the **same** database — the `webhooks` precedent again — so there is
|
|
1015
|
+
no `FILES_DB` binding, no second drizzle config and no second migration target.
|
|
1016
|
+
|
|
1017
|
+
- The tables ride the project's single journal, reached through the
|
|
1018
|
+
`src/db/schema.ts` barrel.
|
|
1019
|
+
- Column shapes are 1:1 with the D1 version so no `/storage/v1/*` body changes:
|
|
1020
|
+
ISO-8601 date strings, JSON-encoded role and MIME lists, the same object keys
|
|
1021
|
+
and the same soft-delete column. The one divergence is numeric width —
|
|
1022
|
+
`size` and `file_size_limit` are `bigint`, because a Postgres `integer` would
|
|
1023
|
+
cap objects at 2 GiB.
|
|
1024
|
+
- The store is a SYSTEM table: RLS is enabled and forced with a single
|
|
1025
|
+
service-role policy, so only `createFilesDb()` (which wraps `createServiceDb`)
|
|
1026
|
+
can read or write it. There is no caller-scope policy and no role arm —
|
|
1027
|
+
public-versus-private file access is decided by the `/storage/v1/*` routes and
|
|
1028
|
+
the file-serving Worker before the handle is used, exactly as it was against
|
|
1029
|
+
the D1 binding.
|
|
1030
|
+
- The **file-serving Worker reads the same database over the same transport**:
|
|
1031
|
+
a `HYPERDRIVE` binding on Hyperdrive projects, or the same `DATABASE_URL`
|
|
1032
|
+
secret on HTTP projects — set on that Worker too. Never a mix of the two.
|
|
1033
|
+
- `connectionMode: 'websocket'` is rejected: it emits no `createServiceDb`.
|
|
1034
|
+
|
|
1035
|
+
See [File Storage](/platform/storage/r2) for the endpoints, bucket scopes and
|
|
1036
|
+
deployment steps.
|
|
1037
|
+
|
|
940
1038
|
## Encryption on Neon
|
|
941
1039
|
|
|
942
1040
|
The encryption pillar — `.encrypted()` (envelope) and `.sealed()` /
|
|
@@ -1070,11 +1168,18 @@ Hyperdrive's connection pool.
|
|
|
1070
1168
|
Anything not yet ported to Postgres is a compile-time error on Neon, never
|
|
1071
1169
|
silently-broken output:
|
|
1072
1170
|
|
|
1073
|
-
- **Managed file storage
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1171
|
+
- **Managed file storage with `connectionMode: 'websocket'`** is rejected: the
|
|
1172
|
+
websocket db index emits no `createServiceDb`, and both `createFilesDb` and
|
|
1173
|
+
the file-serving Worker wrap that handle. Managed storage is supported on
|
|
1174
|
+
`http` and `hyperdrive` — the buckets/objects metadata lives in a `files`
|
|
1175
|
+
schema of this same database (one journal, no `FILES_DB` binding). See
|
|
1176
|
+
[File Storage](/platform/storage/r2).
|
|
1177
|
+
- **The Better Auth `subscriptions` plugin** is supported. Its table is created
|
|
1178
|
+
as `auth.subscriptions` in the same journal as everything else and is a SYSTEM
|
|
1179
|
+
table — service-role only, like the webhook store — because entitlement state
|
|
1180
|
+
is written by the Stripe queue consumer and the admin endpoints and read by
|
|
1181
|
+
tier-role resolution, all of which run on the internal service lane. Rejected
|
|
1182
|
+
on **WebSocket mode**, which emits no `createServiceDb`.
|
|
1078
1183
|
- **Raw `sqliteTable` interop sources** on a Postgres target are rejected — write
|
|
1079
1184
|
child tables with `pgTable` (see [below](#raw-drizzle-interop-tables-must-use-pg-core)).
|
|
1080
1185
|
- **WebSocket mode** (deprecated) rejects webhooks, cross-tenant `unsafe`
|
|
@@ -1084,6 +1189,12 @@ silently-broken output:
|
|
|
1084
1189
|
|
|
1085
1190
|
Mixed database providers (e.g. D1 auth + Neon features) remain unsupported.
|
|
1086
1191
|
|
|
1192
|
+
Table [`triggers`](/define/triggers) are supported in **both** lanes here. A
|
|
1193
|
+
`sql:` body is PL/pgSQL and lowers to a `SECURITY INVOKER` function plus its
|
|
1194
|
+
trigger in the `app` schema, so a cross-table write from a trigger stays
|
|
1195
|
+
subject to RLS and grants. Bodies are never translated between dialects — a
|
|
1196
|
+
SQLite `RAISE(ABORT, ...)` on this provider is a compile error.
|
|
1197
|
+
|
|
1087
1198
|
## Deploying
|
|
1088
1199
|
|
|
1089
1200
|
### Projects with no custom domain
|
|
@@ -48,6 +48,19 @@ compile time, as is any runtime other than `cloudflare`.
|
|
|
48
48
|
`planetscale` — without the suffix — remains the MySQL provider name and is not
|
|
49
49
|
registered. Only `planetscale-postgres` selects this provider.
|
|
50
50
|
|
|
51
|
+
## Where the tables go
|
|
52
|
+
|
|
53
|
+
One PlanetScale **branch** hosts one app, and that app uses the branch's own
|
|
54
|
+
database. Quickback's migrations create *schemas* inside it — `app` for feature
|
|
55
|
+
tables, `auth` for Better Auth, plus `webhooks`, `audit` and `drizzle` when the
|
|
56
|
+
project uses them.
|
|
57
|
+
|
|
58
|
+
Do **not** `CREATE DATABASE` per app inside a branch. Roles are cluster-wide but
|
|
59
|
+
grants, ownership and the migration ledger are per-database, so an extra
|
|
60
|
+
database silently splits the bootstrap. Point the Hyperdrive config's
|
|
61
|
+
`<database>` at the branch's own database and let the schemas do the
|
|
62
|
+
separating. The same rule holds on [Neon](/platform/database/neon#where-the-tables-go).
|
|
63
|
+
|
|
51
64
|
## Roles: three SQL roles, one deployed
|
|
52
65
|
|
|
53
66
|
The first generated migration creates the same three roles it creates on Neon:
|
|
@@ -181,9 +194,9 @@ never silently-broken output:
|
|
|
181
194
|
|
|
182
195
|
| Feature | Status |
|
|
183
196
|
|---------|--------|
|
|
184
|
-
| Managed file storage (`managed: true`) |
|
|
185
|
-
| Better Auth `subscriptions` plugin |
|
|
186
|
-
| Generated SQL triggers |
|
|
197
|
+
| Managed file storage (`managed: true`) | **supported** — metadata lives in a `files` schema of the same database; the file-serving Worker binds the same Hyperdrive config |
|
|
198
|
+
| Better Auth `subscriptions` plugin | supported — `auth.subscriptions` in the same journal, service-role only ([Subscriptions](/platform/auth/plugins/subscriptions#where-the-table-lives)) |
|
|
199
|
+
| Generated SQL triggers (`sql:`) | supported — PL/pgSQL bodies, `SECURITY INVOKER` (see [Triggers](/define/triggers)) |
|
|
187
200
|
| `webhooksDatabaseId` / `webhooksDatabaseName` | rejected — D1-only keys; webhook tables live in the `webhooks` schema of the same database |
|
|
188
201
|
| `connectionMode` of `'http'` or `'websocket'` | rejected — no such driver for this provider |
|
|
189
202
|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
│ │ │ │ │
|
|
33
33
|
│ ┌──────┴──────┐ ┌──────┴──────┐ ┌──────┴──────┐ │
|
|
34
34
|
│ │ D1 │ │ Realtime │ │ R2 │ │
|
|
35
|
-
│ │ (
|
|
35
|
+
│ │ (Postgres) │ │ (WebSocket)│ │ (Storage) │ │
|
|
36
36
|
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
|
37
37
|
│ │
|
|
38
38
|
│ ┌─────────────┐ ┌─────────────────────────────────┐ │
|
|
@@ -11,11 +11,23 @@ Quickback provides built-in file storage using Cloudflare R2.
|
|
|
11
11
|
files worker.** You compute keys and store file references in your own table.
|
|
12
12
|
Use this when you already have a media table and only need to sign large or
|
|
13
13
|
confidential transfers — see [Presigned uploads](#presigned-uploads).
|
|
14
|
-
- **Managed (`managed: true`)** — adds the turnkey subsystem on top: a
|
|
15
|
-
metadata
|
|
14
|
+
- **Managed (`managed: true`)** — adds the turnkey subsystem on top: a
|
|
15
|
+
metadata store (buckets + objects), the `/storage/v1/*` upload/download/
|
|
16
16
|
manage endpoints, and a files worker for serving. Use this for listing photos,
|
|
17
17
|
avatars, and other files that should be **public-if-you-have-the-link**.
|
|
18
18
|
|
|
19
|
+
Managed mode works on every database provider. Where the metadata lives depends
|
|
20
|
+
on which one you chose:
|
|
21
|
+
|
|
22
|
+
| Database | Metadata store | Migrations |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `cloudflare-d1` | A second D1 database, bound as `FILES_DB` | Its own `drizzle.files.config.ts` and migration folder |
|
|
25
|
+
| `neon`, `planetscale-postgres` | A `files` schema in the **same** Postgres database as auth and feature data — no extra database, no binding | The project's single journal |
|
|
26
|
+
|
|
27
|
+
Nothing above the store moves: ids, object keys, JSON-encoded role and MIME
|
|
28
|
+
lists, ISO-8601 timestamps and soft deletion are identical, so every
|
|
29
|
+
`/storage/v1/*` request and response body is the same on both.
|
|
30
|
+
|
|
19
31
|
```ts
|
|
20
32
|
// Presign-only (default) — ctx.storage against a bucket, nothing else
|
|
21
33
|
defineFileStorage("cloudflare-r2", { bucketName: "my-app-media" })
|
|
@@ -117,7 +129,7 @@ export default {
|
|
|
117
129
|
managed: true,
|
|
118
130
|
binding: 'R2_BUCKET',
|
|
119
131
|
bucketName: 'my-app-files',
|
|
120
|
-
filesBinding: 'FILES_DB',
|
|
132
|
+
filesBinding: 'FILES_DB', // cloudflare-d1 only; ignored on Postgres
|
|
121
133
|
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
122
134
|
allowedTypes: ['image/jpeg', 'image/png', 'image/webp'],
|
|
123
135
|
},
|
|
@@ -127,7 +139,7 @@ export default {
|
|
|
127
139
|
```
|
|
128
140
|
|
|
129
141
|
> `managed: true` is what turns on everything on this page — the `/storage/v1/*`
|
|
130
|
-
> routes, the files worker, and the
|
|
142
|
+
> routes, the files worker, and the metadata store. Without it R2
|
|
131
143
|
> file storage is **presign-only**: the compiler signs requests against the
|
|
132
144
|
> bucket by name and emits **no** bucket binding into `wrangler.toml`, so
|
|
133
145
|
> `binding` and `filesBinding` are ignored and `env.R2_BUCKET` is `undefined`
|
|
@@ -379,6 +391,17 @@ https://files.yourdomain.com/public/org_abc/listings/3f2a…-hero.jpg
|
|
|
379
391
|
Store that URL on the listing row. Send it to the public listing page. This is
|
|
380
392
|
the right model for property photos, avatars, and shareable media.
|
|
381
393
|
|
|
394
|
+
No session is required, but the request is not unconditional: the files worker
|
|
395
|
+
looks the key up in the metadata store and serves bytes only when a live
|
|
396
|
+
(not soft-deleted) object exists in a bucket whose `readScope` is `public`.
|
|
397
|
+
Anything else is a **404**, not a 403 — an anonymous caller must not be able to
|
|
398
|
+
probe for private keys. So a soft-deleted public object stops being served, and
|
|
399
|
+
a key that merely *starts with* `public/` proves nothing on its own.
|
|
400
|
+
|
|
401
|
+
Public responses still carry `Cache-Control: public, max-age=31536000,
|
|
402
|
+
immutable`, so a CDN or browser that already has the bytes keeps them. Soft
|
|
403
|
+
deletion is not a revocation mechanism for something already fetched.
|
|
404
|
+
|
|
382
405
|
### Session-gated private files
|
|
383
406
|
|
|
384
407
|
Private files require a valid Better Auth session cookie:
|
|
@@ -409,7 +432,9 @@ When file storage is configured, the compiler generates:
|
|
|
409
432
|
|------|---------|
|
|
410
433
|
| `src/storage/routes.ts` | Storage API routes (upload, presign, confirm, download) |
|
|
411
434
|
| `src/storage/presign.ts` | R2 presigned-URL signer (`createPresigner`, backs `ctx.storage`) |
|
|
412
|
-
| `src/files/schema.ts` | Files
|
|
435
|
+
| `src/files/schema.ts` | Files metadata schema (buckets, objects) — `sqliteTable` on D1, a `files` Postgres schema otherwise |
|
|
436
|
+
| `src/files/index.ts` | `createFilesDb` — the D1 binding handle, or the Postgres service-lane handle |
|
|
437
|
+
| `drizzle.files.config.ts` | Second migration target — **D1 only** |
|
|
413
438
|
| `cloudflare-workers/files/index.ts` | Files worker for serving |
|
|
414
439
|
| `cloudflare-workers/files/wrangler.toml` | Files worker config |
|
|
415
440
|
|
|
@@ -428,15 +453,20 @@ After compiling:
|
|
|
428
453
|
wrangler r2 bucket create my-app-files
|
|
429
454
|
```
|
|
430
455
|
|
|
431
|
-
2. **Create the files database
|
|
456
|
+
2. **Create the files database** — `cloudflare-d1` only. On Postgres the
|
|
457
|
+
metadata lives in the `files` schema of the database you already have:
|
|
432
458
|
```bash
|
|
433
459
|
wrangler d1 create my-app-files
|
|
434
460
|
```
|
|
435
461
|
|
|
436
462
|
3. **Run migrations:**
|
|
437
463
|
```bash
|
|
464
|
+
# cloudflare-d1
|
|
438
465
|
wrangler d1 migrations apply my-app-files --local
|
|
439
466
|
wrangler d1 migrations apply my-app-files --remote
|
|
467
|
+
|
|
468
|
+
# Postgres — the files schema is in the project's single journal
|
|
469
|
+
npm run db:migrate
|
|
440
470
|
```
|
|
441
471
|
|
|
442
472
|
4. **Deploy the API:**
|
|
@@ -450,6 +480,18 @@ After compiling:
|
|
|
450
480
|
wrangler deploy
|
|
451
481
|
```
|
|
452
482
|
|
|
483
|
+
`quickback deploy` ships the API Worker only and then prints this command —
|
|
484
|
+
managed file storage is two deployed Workers, and having shipped one but not
|
|
485
|
+
the other is a real state worth seeing.
|
|
486
|
+
|
|
487
|
+
On Postgres the files worker reads the **same** database over the **same**
|
|
488
|
+
transport as the API Worker: a `HYPERDRIVE` binding (already in its
|
|
489
|
+
`wrangler.toml`), or a `DATABASE_URL` secret you must also set on this
|
|
490
|
+
Worker:
|
|
491
|
+
```bash
|
|
492
|
+
cd cloudflare-workers/files && wrangler secret put DATABASE_URL # HTTP only
|
|
493
|
+
```
|
|
494
|
+
|
|
453
495
|
6. **Set the R2 presign secrets** only if you use signed PUT/GET. Public-bucket
|
|
454
496
|
uploads through `POST /object` do not need them. See
|
|
455
497
|
[Presigned uploads](#presigned-uploads):
|
|
@@ -459,15 +501,40 @@ After compiling:
|
|
|
459
501
|
wrangler secret put R2_SECRET_ACCESS_KEY
|
|
460
502
|
```
|
|
461
503
|
|
|
504
|
+
### Named environments deploy two Workers per target
|
|
505
|
+
|
|
506
|
+
A project with [named environments](/configure/domains) must name the files
|
|
507
|
+
Worker for every target. It is never derived: the script name is the deployed
|
|
508
|
+
identity, and Wrangler's `routes` key is inheritable, so a shared
|
|
509
|
+
`<project>-files` default would let `deploy --env dev` replace production's file
|
|
510
|
+
server and take its hostname.
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
environments: {
|
|
514
|
+
dev: { name: 'app-dev', filesWorker: { name: 'app-files-dev', domain: 'files-dev.example.com' }, /* … */ },
|
|
515
|
+
prod: { name: 'app', filesWorker: { name: 'app-files', domain: 'files.example.com' }, /* … */ },
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
The compile fails with the config path to fix when a target omits it, or when
|
|
520
|
+
two targets claim the same Worker name or hostname. Omitting
|
|
521
|
+
`filesWorker.domain` emits `routes = []` — the explicit workers.dev-only
|
|
522
|
+
opt-out. The files Worker reuses that environment's R2 bucket and database
|
|
523
|
+
bindings; it does not declare its own.
|
|
524
|
+
|
|
525
|
+
```bash
|
|
526
|
+
cd cloudflare-workers/files && npx wrangler deploy --env dev
|
|
527
|
+
```
|
|
528
|
+
|
|
462
529
|
## Configuration Reference
|
|
463
530
|
|
|
464
531
|
| Option | Type | Default | Description |
|
|
465
532
|
|--------|------|---------|-------------|
|
|
466
|
-
| `managed` | `boolean` | `false` | Opt into the
|
|
533
|
+
| `managed` | `boolean` | `false` | Opt into the metadata store + `/storage/v1/*` + files worker. Off = presign-only. |
|
|
467
534
|
| `bucketName` | `string` | `<project>-media` | R2 bucket the signer targets (override per-call with `signPutUrl(key, { bucket })`) |
|
|
468
535
|
| `presign` | `object` | - | Env-var name overrides: `{ accountIdEnv, accessKeyIdEnv, secretAccessKeyEnv, endpointEnv }` |
|
|
469
536
|
| `binding` | `string` | `R2_BUCKET` | R2 bucket binding name (managed mode) |
|
|
470
|
-
| `filesBinding` | `string` | `FILES_DB` | Files metadata D1 binding (managed mode) |
|
|
537
|
+
| `filesBinding` | `string` | `FILES_DB` | Files metadata D1 binding (managed mode, `cloudflare-d1` only — Postgres uses the `files` schema of the single database and emits no binding) |
|
|
471
538
|
| `maxFileSize` | `number \| string` | 10MB | Max upload size — bytes or `"100mb"` (managed mode) |
|
|
472
539
|
| `allowedTypes` | `string[]` | Images only | Allowed MIME types (managed mode) |
|
|
473
540
|
| `publicDomain` | `string` | - | Custom domain for files worker (managed mode) |
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
You write declarative definitions in TypeScript — schema, security rules, validation,
|
|
4
4
|
custom actions — and **the compiler** emits a production Hono application running on
|
|
5
|
-
Cloudflare Workers, backed by D1 or Neon.
|
|
5
|
+
Cloudflare Workers, backed by D1 or Postgres (Neon or PlanetScale).
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
feature() ─┐
|
|
9
9
|
├─► quickback build ─► Hono API on Cloudflare
|
|
10
|
-
defineAction() ─┘
|
|
10
|
+
defineAction() ─┘ (D1 / Neon / PlanetScale)
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
When you run `quickback build`, it:
|
|
@@ -49,6 +49,11 @@ npx @quickback-dev/cli create cloudflare my-app
|
|
|
49
49
|
|
|
50
50
|
## Drizzle rename prompts in CI/headless compile
|
|
51
51
|
|
|
52
|
+
Run `quickback build` with the updated Quickback CLI. SQLite migration targets
|
|
53
|
+
automatically select **create** for new tables and columns when their migration
|
|
54
|
+
plan enables auto-create; explicit rename hints take precedence. The CLI handles
|
|
55
|
+
repeated prompts without user input. PostgreSQL targets require rename hints.
|
|
56
|
+
|
|
52
57
|
If compilation fails with an interactive Drizzle message like:
|
|
53
58
|
|
|
54
59
|
- `drizzle-kit requested interactive rename input, but Quickback compile is running headless`
|
|
@@ -83,6 +88,12 @@ If a hint is missing, compile now fails loudly with the exact key path to add, f
|
|
|
83
88
|
- `Expected hint key: compiler.migrations.renames.tables["events_v2"]`
|
|
84
89
|
- `Expected hint key: compiler.migrations.renames.columns["events"]["summary_text"]`
|
|
85
90
|
|
|
91
|
+
If the CLI already selected **create** but generation still failed, inspect the
|
|
92
|
+
end of the reported Drizzle output for the unfinished prompt or process error.
|
|
93
|
+
A failed generate or postprocessor leaves existing migration history untouched.
|
|
94
|
+
Do not use raw `drizzle-kit generate` as an equivalent workaround for an auth
|
|
95
|
+
upgrade: it skips Quickback's OAuth client backfills and resource-grant cleanup.
|
|
96
|
+
|
|
86
97
|
## `Critical command failed: Generate features database migrations`
|
|
87
98
|
|
|
88
99
|
drizzle-kit could not load the generated **features** schema. The usual cause on
|
|
@@ -288,18 +288,62 @@ src/
|
|
|
288
288
|
|
|
289
289
|
### File Storage (R2)
|
|
290
290
|
|
|
291
|
-
When `fileStorage` is configured:
|
|
291
|
+
When `fileStorage` is configured, presign-only mode emits just the signer:
|
|
292
292
|
|
|
293
293
|
```
|
|
294
294
|
src/
|
|
295
|
-
└──
|
|
296
|
-
└──
|
|
295
|
+
└── storage/
|
|
296
|
+
└── presign.ts # R2 presigned-URL signer (backs ctx.storage)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
`managed: true` adds the API routes, the metadata schema and a **second
|
|
300
|
+
deployed Worker** with its own `wrangler.toml`:
|
|
301
|
+
|
|
302
|
+
```
|
|
303
|
+
src/
|
|
304
|
+
├── routes/storage.ts # File upload/download endpoints
|
|
305
|
+
└── files/
|
|
306
|
+
├── schema.ts # buckets + objects
|
|
307
|
+
└── index.ts # createFilesDb
|
|
308
|
+
cloudflare-workers/
|
|
309
|
+
└── files/ # SECOND Worker — deployed separately
|
|
310
|
+
├── index.ts # public + session-gated file serving
|
|
311
|
+
└── wrangler.toml # its own name, bindings and routes
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
`cloudflare-workers/**` is included in the generated `tsconfig.json`, so
|
|
315
|
+
`npm run typecheck` covers both entrypoints.
|
|
316
|
+
|
|
317
|
+
Where the metadata lives, and therefore what else is emitted, depends on the
|
|
318
|
+
database provider:
|
|
319
|
+
|
|
320
|
+
| Provider | Metadata store | Extra output |
|
|
321
|
+
|---|---|---|
|
|
322
|
+
| `cloudflare-d1` | A second D1 database bound as `FILES_DB` | `drizzle.files.config.ts` + `quickback/drizzle/files/` |
|
|
323
|
+
| `neon`, `planetscale-postgres` | A `files` schema in the same Postgres database | none — the tables ride the single journal at `quickback/drizzle/` |
|
|
324
|
+
|
|
325
|
+
```
|
|
297
326
|
quickback/drizzle/
|
|
298
|
-
└── files/ # File metadata migrations
|
|
327
|
+
└── files/ # File metadata migrations — cloudflare-d1 only
|
|
299
328
|
├── meta/
|
|
300
329
|
└── 0000_*.sql
|
|
301
330
|
```
|
|
302
331
|
|
|
332
|
+
Under named environments the second Worker needs its own identity, declared per
|
|
333
|
+
target and never derived — a shared default would make `deploy --env dev`
|
|
334
|
+
overwrite production's file server, and Wrangler's inheritable `routes` would
|
|
335
|
+
take its hostname with it:
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
environments: {
|
|
339
|
+
dev: { name: 'app-dev', filesWorker: { name: 'app-files-dev', domain: 'files-dev.example.com' }, /* … */ },
|
|
340
|
+
prod: { name: 'app', filesWorker: { name: 'app-files', domain: 'files.example.com' }, /* … */ },
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Omitting `filesWorker.domain` emits `routes = []` for that target — the explicit
|
|
345
|
+
workers.dev-only opt-out, so it cannot inherit a sibling's hostname.
|
|
346
|
+
|
|
303
347
|
### Webhooks
|
|
304
348
|
|
|
305
349
|
When webhooks are enabled:
|
|
@@ -462,7 +506,7 @@ The CLI loads migration meta JSON from one location only — `<project>/quickbac
|
|
|
462
506
|
|
|
463
507
|
- `quickback/drizzle/auth/meta/`
|
|
464
508
|
- `quickback/drizzle/features/meta/`
|
|
465
|
-
- `quickback/drizzle/files/meta/`
|
|
509
|
+
- `quickback/drizzle/files/meta/` (cloudflare-d1 managed file storage)
|
|
466
510
|
- `quickback/drizzle/webhooks/meta/`
|
|
467
511
|
- `quickback/drizzle/audit/meta/`
|
|
468
512
|
- `quickback/drizzle/meta/` (single-database mode)
|
|
@@ -92,7 +92,10 @@ To clean up, you'd need to manually create a migration.
|
|
|
92
92
|
|
|
93
93
|
### Drizzle rename prompts in CI
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
Use the updated Quickback CLI for automatic SQLite create prompts. For an
|
|
96
|
+
actual rename, add explicit rename hints in your config. If generation fails
|
|
97
|
+
after the CLI answered a prompt, inspect the final Drizzle output in the error.
|
|
98
|
+
See [Drizzle rename prompts](/tooling/cloud-compiler/troubleshooting#drizzle-rename-prompts-in-ciheadless-compile).
|
|
96
99
|
|
|
97
100
|
### Cloudflare D1 destructive migrations
|
|
98
101
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quickback-dev/cli",
|
|
3
|
-
"version": "0.66.
|
|
3
|
+
"version": "0.66.13",
|
|
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",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
|
50
|
+
"zod": "^3.25.76",
|
|
50
51
|
"esbuild": "^0.27.2",
|
|
51
52
|
"ora": "^9.0.0",
|
|
52
53
|
"picocolors": "^1.0.0",
|
|
@@ -58,7 +59,9 @@
|
|
|
58
59
|
"@types/prompts": "^2.4.9",
|
|
59
60
|
"bun-types": "^1.3.5",
|
|
60
61
|
"tsx": "^4.19.0",
|
|
61
|
-
"typescript": "^5.9.0"
|
|
62
|
+
"typescript": "^5.9.0",
|
|
63
|
+
"drizzle-kit": "0.31.10",
|
|
64
|
+
"drizzle-orm": "0.45.2"
|
|
62
65
|
},
|
|
63
66
|
"peerDependencies": {
|
|
64
67
|
"typescript": ">=5.0.0 <7"
|
|
@@ -113,7 +113,7 @@ Every optional top-level key the config accepts is listed below. You never have
|
|
|
113
113
|
| `email` | `object` | Email delivery config (`provider`, `from`, `fromName`, `region`) — see [Email Configuration](#email-configuration) |
|
|
114
114
|
| `push` | `object` | Web Push (VAPID keys, TTL/urgency defaults, queue fan-out) — see [Push](/platform/push) |
|
|
115
115
|
| `bindings` | `object` | Extra Cloudflare bindings (durable objects, queues, R2, services, `vars`, AI) — see [Bindings](/configure/bindings) |
|
|
116
|
-
| `environments` | `object` | Named deployment targets (`dev`/`staging`/`production`) → one `[env.<name>]` Wrangler stanza each, on Cloudflare D1 or
|
|
116
|
+
| `environments` | `object` | Named deployment targets (`dev`/`staging`/`production`) → one `[env.<name>]` Wrangler stanza each, on Cloudflare D1 or Postgres over Hyperdrive (Neon or PlanetScale) — see [D1](/platform/database/d1#named-cloudflare-deployment-environments), [Neon](/platform/database/neon#named-cloudflare-deployment-environments) and [PlanetScale Postgres](/platform/database/planetscale-postgres) |
|
|
117
117
|
| `compiler` | `object` | Compiler internals — `features.auditFields: false`, `migrations.renames` (headless CI), Neon `migrations.foreignKeys`, `securityContracts`, `injectId`, `routes` |
|
|
118
118
|
| `build` | `object` | Build options (`outputDir`, `packageManager`, `dependencies`) — see [Custom Dependencies](#custom-dependencies) |
|
|
119
119
|
| `dev` | `object` | Local development settings (`port`, `api`, `cms`, `account`, `hostnames`) — see [Variables](/configure/variables) |
|
|
@@ -149,6 +149,9 @@ restriction: a row that satisfies the arm is reachable even when the table
|
|
|
149
149
|
firewall would not have matched it, and even when it is soft-deleted.
|
|
150
150
|
Restrictions belong in `firewall`. The restrictive `<table>_deny_anon` and
|
|
151
151
|
`<table>_principal_fence` policies remain the only arms that cap every lane.
|
|
152
|
+
(The fence is emitted precisely because this table declares a lane; a table
|
|
153
|
+
with no `databaseAccess` and no `access.principals` gets neither the fence nor
|
|
154
|
+
the principal arm of `deny_anon`, which blocks every principal just the same.)
|
|
152
155
|
|
|
153
156
|
### What the compiler refuses, and why
|
|
154
157
|
|