PocketBase 0.40.6 + JS SDK 0.28.2; explicit JSON limits; setup steps for the new dashboard #28

Merged
reudy merged 2 commits from session/pocketbase-0.40 into main 2026-11-03 11:44:19 +01:00
8 changed files with 31 additions and 23 deletions
Showing only changes of commit 5e2db31b5e - Show all commits

View file

@ -3,7 +3,7 @@
## Stack ## Stack
- **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc. - **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc.
- **PocketBase** — server pinned to **0.23.12** (`docker-compose.yml`, image `elestio/pocketbase`, digest-pinned; runs as non-root uid 100 on port 8090), REST API via the `pocketbase` SDK (v0.26). Auth, DB, and image storage. Bump the server version deliberately (changelog, backup, test migrations). - **PocketBase** — server pinned to **0.40.6** (`docker-compose.yml`, image `elestio/pocketbase`, digest-pinned; runs as non-root uid 100 on port 8090), REST API via the `pocketbase` SDK (v0.28). Auth, DB, and image storage. Bump the server version deliberately (changelog, backup, test migrations).
- **Tailwind CSS v4** + **DaisyUI 5** — utility-first CSS with DaisyUI components for admin; custom theme for the public site. - **Tailwind CSS v4** + **DaisyUI 5** — utility-first CSS with DaisyUI components for admin; custom theme for the public site.
- **Docker Compose** — four services: `app-admin`, `app-public`, `pocketbase`, and `caddy` (reverse proxy). - **Docker Compose** — four services: `app-admin`, `app-public`, `pocketbase`, and `caddy` (reverse proxy).
@ -134,7 +134,7 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type
- Collections: `pages` (slug, title, blocks[], published), `globals` (key, data), `media` (file, alt), `email_templates` (key, subject, blocks[], recipients, enabled); commerce: `items`, `slots`, `baskets`, `basket_lines`, `orders`, `order_lines`, `passes` (bundle/voucher codes) - Collections: `pages` (slug, title, blocks[], published), `globals` (key, data), `media` (file, alt), `email_templates` (key, subject, blocks[], recipients, enabled); commerce: `items`, `slots`, `baskets`, `basket_lines`, `orders`, `order_lines`, `passes` (bundle/voucher codes)
- Server load functions use `locals.pb.collection('pages').getFirstListItem()` - Server load functions use `locals.pb.collection('pages').getFirstListItem()`
- **Always build filters with `pb.filter('slug = {:slug}', { slug })`** — never interpolate values into filter strings (quotes break them). - **Always build filters with `pb.filter('slug = {:slug}', { slug })`** — never interpolate values into filter strings (quotes break them).
- **Schema changes**: add a migration to `pocketbase/pb_migrations/` (runs once, on the next PocketBase start) **and** mirror it in `pb_schema.json` (fresh installs import that after the migrations have already run). Migrations must skip missing collections and must not throw for data problems — a failing migration stops PocketBase from starting. - **Schema changes**: add a migration to `pocketbase/pb_migrations/` (runs once, on the next PocketBase start) **and** mirror it in `pb_schema.json` (fresh installs import that after the migrations have already run). Field settings go at the field's top level (`"maxSize": 2000000`), never under `options`: PocketBase has ignored `options` since 0.23. Migrations must skip missing collections and must not throw for data problems — a failing migration stops PocketBase from starting.
- **API rules**: CMS collections require `@request.auth.id != ''`, so `users` must never allow public sign-up (its createRule is superuser-only). Commerce writes (orders, order_lines, baskets, basket_lines) are superuser-only; they happen in the PocketBase shop hooks (`pocketbase/pb_hooks/shop/lib.js`), which bypass rules. - **API rules**: CMS collections require `@request.auth.id != ''`, so `users` must never allow public sign-up (its createRule is superuser-only). Commerce writes (orders, order_lines, baskets, basket_lines) are superuser-only; they happen in the PocketBase shop hooks (`pocketbase/pb_hooks/shop/lib.js`), which bypass rules.
- **Slot availability** (window start times, group-session places, blocking by overlapping bookings incl. get-ready time) is computed only by `availability()`/`windowStartTimes()`/`checkBooking()` in the shop hooks — the public listing, basket holds and the admin `/slots` page all go through it (`GET /api/shop/slots?item=&minutes=&from=&to=`, `?detail=1` for the admin). Slots are `window`s (services bookable at any of their lengths) or group `session`s; bookings carry their own `start`/`minutes` on basket/order lines. Never store booking state on a slot or re-implement the rule elsewhere; see the README's *Slot availability*. - **Slot availability** (window start times, group-session places, blocking by overlapping bookings incl. get-ready time) is computed only by `availability()`/`windowStartTimes()`/`checkBooking()` in the shop hooks — the public listing, basket holds and the admin `/slots` page all go through it (`GET /api/shop/slots?item=&minutes=&from=&to=`, `?detail=1` for the admin). Slots are `window`s (services bookable at any of their lengths) or group `session`s; bookings carry their own `start`/`minutes` on basket/order lines. Never store booking state on a slot or re-implement the rule elsewhere; see the README's *Slot availability*.
- **Customer personal data (GDPR)** lives in `orders.customerDetails`/`email`, `passes.email`/`recipientName`/`message` and (during checkout) `baskets` / `basket_lines.giftTo`/`giftMessage`. Admin access, correction, erasure (= anonymise the order, never delete it — the accounts need it) and the retention cron are in `pocketbase/pb_hooks/privacy/`; the admin `/customers` page only calls `/api/privacy/*`. A new place that stores customer details (e.g. a Google Calendar sync) must be covered by export, erase and retention too, and listed in the privacy draft (`app-admin/src/lib/admin/privacyTemplate.ts`). Don't load third-party resources on public pages (fonts are bundled; Stripe.js loads only at Pay) — each one sends visitors' IPs elsewhere and may need consent. See the README's *Personal data (GDPR)*. - **Customer personal data (GDPR)** lives in `orders.customerDetails`/`email`, `passes.email`/`recipientName`/`message` and (during checkout) `baskets` / `basket_lines.giftTo`/`giftMessage`. Admin access, correction, erasure (= anonymise the order, never delete it — the accounts need it) and the retention cron are in `pocketbase/pb_hooks/privacy/`; the admin `/customers` page only calls `/api/privacy/*`. A new place that stores customer details (e.g. a Google Calendar sync) must be covered by export, erase and retention too, and listed in the privacy draft (`app-admin/src/lib/admin/privacyTemplate.ts`). Don't load third-party resources on public pages (fonts are bundled; Stripe.js loads only at Pay) — each one sends visitors' IPs elsewhere and may need consent. See the README's *Personal data (GDPR)*.

View file

@ -78,15 +78,13 @@ The app containers use two PocketBase URLs:
## PocketBase setup ## PocketBase setup
1. Open `http://db.localhost:8080/_/`. A fresh install, once the stack is up (written for the PocketBase 0.40 dashboard):
2. Create the first PocketBase admin user when prompted.
3. Import `pb_schema.json` from the PocketBase admin UI collection settings/import flow. This file uses the newer PocketBase `fields` schema format; if PocketBase still reports `Invalid collections configuration`, create the three collections manually using the fields below.
4. Create starter records:
- `pages`: slug `home`, title `Home`, `published: true`, and a blocks JSON array.
- `globals`: key `header`, data matching the header JSON in the project prompt.
- `globals`: key `footer`, data matching the footer JSON in the project prompt.
If the `globals` records do not exist, the app falls back to safe defaults and the admin globals page will create them. 1. **Create the first superuser.** PocketBase prints a one-time install link in its log (`docker compose logs pocketbase`): `http://0.0.0.0:8090/_/#/pbinstall/<token>`. Open it with `http://0.0.0.0:8090` replaced by the address you reach PocketBase at, e.g. `http://db.localhost:8080/_/#/pbinstall/<token>`.
2. **Import the schema.** In the dashboard: **Settings → Import collections → Load from JSON file**, choose `pb_schema.json`, and **tick "Merge with the existing collections"**. It is off by default, and without it the import deletes every collection that isn't in the file, including `users` (so nobody but superusers could sign in to the admin). Review, then **Confirm and import**. `PUT /api/collections/import` with `"deleteMissing": false` does the same.
3. **Add content.** Sign in to the admin app and import a site from `backups/` under **Backup → Import** (see `backups/README.md`), or start from empty: pages are created under **Pages**, and **Site design** creates its own records the first time it is opened.
The migrations in `pocketbase/pb_migrations/` already ran when PocketBase first started (before the collections existed, so they skipped); the imported `pb_schema.json` is the end state they lead to. On that first start the privacy cron also logs `[privacy] retention at startup failed: … no rows in result set`, because the collections don't exist yet; it is harmless and gone from the next start.
### Switching PocketBase image (existing installs) ### Switching PocketBase image (existing installs)
@ -101,6 +99,16 @@ docker compose up -d
Fresh installs need nothing: a new volume is created with the right owner. Fresh installs need nothing: a new volume is created with the right owner.
### Upgrading to PocketBase 0.40 (existing installs)
PocketBase went from 0.23.12 to 0.40.6 (same image, same port and user, so nothing above changes). On its first start 0.40 upgrades `pb_data` in place, and that can't be undone by going back to the old image: **back up `pb_data` first**, and to roll back, restore that backup. Coming from the spectado image, do the `chown` above too.
What changed for this project:
- **JSON field limits.** PocketBase's default limit for JSON fields fell to 1MB in 0.29, and six of ours had relied on it (their limits were under `options` in `pb_schema.json`, which PocketBase ignores). Migration `1793400000_json_field_limits.js` sets them explicitly (page and email blocks 2MB, site design 1MB, …). Real pages are far below that.
- **New dashboard** at `db.…/_/` (rewritten in 0.37); the setup steps above describe it.
- Downloads now send a quoted filename (`filename="photo.jpg"`); nothing here depends on it.
### Migrations ### Migrations
`pocketbase/pb_migrations/` is mounted into the PocketBase container, which applies any new migration once when it starts (`docker compose up` / restart). The first one (`1791244800_lock_rules_dates_unique.js`) closes public sign-up on the `users` collection, makes order/basket writes superuser-only, adds `created`/`updated` dates and unique slug/key indexes. On an existing install, check the PocketBase log after restarting — if duplicate page slugs or global keys exist, the unique index is skipped with a log line. `1791331200_lock_order_lines.js` makes `order_lines` writes superuser-only (they were public). `pocketbase/pb_migrations/` is mounted into the PocketBase container, which applies any new migration once when it starts (`docker compose up` / restart). The first one (`1791244800_lock_rules_dates_unique.js`) closes public sign-up on the `users` collection, makes order/basket writes superuser-only, adds `created`/`updated` dates and unique slug/key indexes. On an existing install, check the PocketBase log after restarting — if duplicate page slugs or global keys exist, the unique index is skipped with a log line. `1791331200_lock_order_lines.js` makes `order_lines` writes superuser-only (they were public).
@ -134,7 +142,7 @@ Commerce collections (see the Stripe section above for context):
- `passes` — bundle/voucher codes: `code` text (unique, 8 characters, shown as `ABCD-2345`), `item` relation→items (the bundle), `order` relation→orders (empty when issued in the admin), `name` text, `parts` json (snapshot: `[{ item, name, minutes, count, value }]`, `value` = the part's share of the price), `email` text (buyer), `recipientName` / `message` text, `expiresAt` date, `status` select `active|void`, `anonymisedAt` date. What's used is never stored — see *Bundles and codes* - `passes` — bundle/voucher codes: `code` text (unique, 8 characters, shown as `ABCD-2345`), `item` relation→items (the bundle), `order` relation→orders (empty when issued in the admin), `name` text, `parts` json (snapshot: `[{ item, name, minutes, count, value }]`, `value` = the part's share of the price), `email` text (buyer), `recipientName` / `message` text, `expiresAt` date, `status` select `active|void`, `anonymisedAt` date. What's used is never stored — see *Bundles and codes*
- `email_templates` — `key` text (unique: `customer_confirmation` | `client_alert`), `subject` text, `blocks` json, `recipients` text, `enabled` bool - `email_templates` — `key` text (unique: `customer_confirmation` | `client_alert`), `subject` text, `blocks` json, `recipients` text, `enabled` bool
> **Schema format note:** `pb_schema.json` targets PocketBase 0.23+ using the `fields` array (not the legacy `schema` array). Field config (`collectionId`, `cascadeDelete`, `maxSelect`, `values`, number `min`/`max`/`onlyInt`) belongs at the field top level — 0.23 silently ignores anything nested under `options`, so the older number/text fields that still use `options` get no min/max on a fresh install. Importing the whole file via the PocketBase admin UI or `PUT /api/collections/import` creates or updates all collections in one pass. > **Schema format note:** `pb_schema.json` targets PocketBase 0.23+ using the `fields` array (not the legacy `schema` array). Field config (`collectionId`, `cascadeDelete`, `maxSelect`, `values`, number `min`/`max`/`onlyInt`) belongs at the field top level — 0.23 silently ignores anything nested under `options`, so the older number/text fields that still use `options` get no min/max on a fresh install (the JSON fields' `maxSize` has been moved up; see *Upgrading to PocketBase 0.40*). Importing the whole file via the PocketBase admin UI or `PUT /api/collections/import` creates or updates all collections in one pass; keep *Merge with the existing collections* ticked (`deleteMissing: false`), or `users` is deleted.
## Authentication ## Authentication

View file

@ -20,7 +20,7 @@
"@tiptap/starter-kit": "^3.23.4", "@tiptap/starter-kit": "^3.23.4",
"daisyui": "^5.5.19", "daisyui": "^5.5.19",
"nodemailer": "^10.0.12", "nodemailer": "^10.0.12",
"pocketbase": "^0.26.9", "pocketbase": "^0.28.2",
"svelte-tiptap": "^3.0.1", "svelte-tiptap": "^3.0.1",
"tailwindcss": "^4.3.0", "tailwindcss": "^4.3.0",
"uuid": "^14.0.0" "uuid": "^14.0.0"
@ -2499,9 +2499,9 @@
} }
}, },
"node_modules/pocketbase": { "node_modules/pocketbase": {
"version": "0.26.9", "version": "0.28.2",
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.26.9.tgz", "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.28.2.tgz",
"integrity": "sha512-Tiv1/hNuUzRdvT0d8hF03dfzuefQ1WdSRp1A1q3wzFC/WYhQcbU/Qlaubl/3ZDo6xvFXBS8JAgBS/L+ms7nkVQ==", "integrity": "sha512-5lS4g7iDZi90LxLai8kyUK4r5u1GkEAoZ3yuzTEFX97FyDQAoEmXWbTqf+pYA1hz5e/icBQu1MCUjM/9V8mitg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/postcss": { "node_modules/postcss": {

View file

@ -48,7 +48,7 @@
"@tiptap/starter-kit": "^3.23.4", "@tiptap/starter-kit": "^3.23.4",
"daisyui": "^5.5.19", "daisyui": "^5.5.19",
"nodemailer": "^10.0.12", "nodemailer": "^10.0.12",
"pocketbase": "^0.26.9", "pocketbase": "^0.28.2",
"svelte-tiptap": "^3.0.1", "svelte-tiptap": "^3.0.1",
"tailwindcss": "^4.3.0", "tailwindcss": "^4.3.0",
"uuid": "^14.0.0" "uuid": "^14.0.0"

View file

@ -13,7 +13,7 @@
"@tailwindcss/vite": "^4.3.0", "@tailwindcss/vite": "^4.3.0",
"daisyui": "^5.5.19", "daisyui": "^5.5.19",
"nodemailer": "^10.0.12", "nodemailer": "^10.0.12",
"pocketbase": "^0.26.9", "pocketbase": "^0.28.2",
"tailwindcss": "^4.3.0" "tailwindcss": "^4.3.0"
}, },
"devDependencies": { "devDependencies": {
@ -1964,9 +1964,9 @@
} }
}, },
"node_modules/pocketbase": { "node_modules/pocketbase": {
"version": "0.26.9", "version": "0.28.2",
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.26.9.tgz", "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.28.2.tgz",
"integrity": "sha512-Tiv1/hNuUzRdvT0d8hF03dfzuefQ1WdSRp1A1q3wzFC/WYhQcbU/Qlaubl/3ZDo6xvFXBS8JAgBS/L+ms7nkVQ==", "integrity": "sha512-5lS4g7iDZi90LxLai8kyUK4r5u1GkEAoZ3yuzTEFX97FyDQAoEmXWbTqf+pYA1hz5e/icBQu1MCUjM/9V8mitg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/postcss": { "node_modules/postcss": {

View file

@ -40,7 +40,7 @@
"@tailwindcss/vite": "^4.3.0", "@tailwindcss/vite": "^4.3.0",
"daisyui": "^5.5.19", "daisyui": "^5.5.19",
"nodemailer": "^10.0.12", "nodemailer": "^10.0.12",
"pocketbase": "^0.26.9", "pocketbase": "^0.28.2",
"tailwindcss": "^4.3.0" "tailwindcss": "^4.3.0"
} }
} }

View file

@ -8,7 +8,7 @@ services:
# and finds /pb_migrations and /pb_hooks next to /pb_data by default. # and finds /pb_migrations and /pb_hooks next to /pb_data by default.
# Data written by the old root-run image (spectado/pocketbase, now gone) # Data written by the old root-run image (spectado/pocketbase, now gone)
# must be chown'ed once — see the README's "Switching PocketBase image". # must be chown'ed once — see the README's "Switching PocketBase image".
image: docker.io/elestio/pocketbase:v0.23.12@sha256:e8c375d4fd50c4ee2f2922361392ba7c6b16c4d5df39bfc7cf2372af2bc3305e image: docker.io/elestio/pocketbase:v0.40.6@sha256:936756ccefb13cedaf2e7c49745412455bc81f2d1a511132f4012e411b970437
container_name: massage-pocketbase container_name: massage-pocketbase
restart: unless-stopped restart: unless-stopped
# Internal only — accessed via the caddy reverse proxy # Internal only — accessed via the caddy reverse proxy

View file

@ -19,7 +19,7 @@
"dependencies": { "dependencies": {
"@stripe/stripe-js": "^9.12.1", "@stripe/stripe-js": "^9.12.1",
"nodemailer": "^10.0.12", "nodemailer": "^10.0.12",
"pocketbase": "^0.26.9" "pocketbase": "^0.28.2"
}, },
"devDependencies": { "devDependencies": {
"@types/nodemailer": "^8.0.2" "@types/nodemailer": "^8.0.2"