Deploy & ops
Production app: probeharbor.dev.
pnpm ops:check # verify .env has core keys
pnpm test && pnpm typecheck && pnpm build
pnpm db:pending # migrations not applied yet (then pnpm db:migrate)
pnpm secrets:push # sync .env → Worker secrets
pnpm deploy # astro build + wrangler deployAfter deploy:
- Infra IDs vs brand — Cloudflare Worker name may stay
garage-temp; some API paths like/api/garage-temps/*are stable URLs. User-facing brand is ProbeHarbor. - Set
SITE_URL/ORIGINWorker secrets tohttps://probeharbor.dev - Confirm cron triggers (
0 * * * *and15,30,45 * * * *inwrangler.jsonc) are active - Enable Cloudflare Email Sending for the domain in
SMTP_MAIL_FROM(see below) - Point Stripe webhooks at
/api/stripe/webhookwithSTRIPE_WEBHOOK_SECRET - Optional:
node --env-file=.env scripts/rename-stripe-products.mjsto rename Stripe product labels
Keep display amounts aligned with live Stripe:
pnpm audit:stripe
# or open /dashboard/ops → Stripe display price auditOutbound email (Cloudflare Email)
wrangler.jsonc uses an unrestricted MAILER send_email binding so drip, trial, alert, and digest mail can reach user addresses. Enable Email Sending for the domain in SMTP_MAIL_FROM:
- Cloudflare Dashboard → Email → Email Sending, or
- CLI:
wrangler email sending enable <your-sending-domain>
If the binding is locked with destination_address, mail to other inboxes fails with email to … not allowed. Drip cron treats that as restricted (job stays success) until Email Sending is enabled. The contact form still targets SMTP_MAIL_TO.
Helpers: src/lib/mailer.ts (sendPlainEmail, sendMailerRaw).
GitHub Actions deploy
Astro inlines import.meta.env at build time. Deploy must use real production secrets — never CI placeholders — or auth breaks.
One-time (Cloudflare API token with Workers edit):
CLOUDFLARE_API_TOKEN=... pnpm setup:github-secretsThat syncs CLOUDFLARE_* plus build secrets from .env into GitHub Actions secrets. Pushes to main then run .github/workflows/deploy.yml. Without those secrets the workflow succeeds with a skip notice (use pnpm deploy locally).
App version
Each workflow deploy gets a date-based version: YYYY.MM.DD (UTC), then YYYY.MM.DD.1, .2, … for later deploys the same day (scripts/app-version.mjs). The workflow:
- builds with
APP_VERSIONset, so the site footer showsv2026.10.28and Sentry groups Worker and browser errors under that release; - passes it to
wrangler deploy --tag, so it appears as the tag inwrangler deployments list; - after the deploy succeeds, publishes a GitHub Release
app-v<version>(which creates the tag on the deployed commit), with the commits since the previous app release as its notes.
A push that changes only planning files (IMPLEMENTATION_PLAN.md, IMPLEMENTATION_LOG.md, IMPROVEMENT_PLAN.md), CLAUDE.md or AGENTS.md since the last app release doesn't deploy (a notice says so). Run the Deploy workflow by hand (workflow_dispatch) to force one.
node scripts/app-version.mjs prints the next version. A local pnpm deploy has no version: the footer hides it, the Worker's Sentry release falls back to the Cloudflare version id and the browser's to the Sentry build plugin's. Firmware (FIRMWARE_VERSION / public/firmware/manifest.json) and the OpenAPI spec keep semver, because devices and integrators compare them.
Migrations and deploy order
Pushes to main deploy the Workers automatically. Database migrations do not run in CI: apply them yourself with pnpm db:migrate (files in db/migrations/, direct connection DATABASE_URL_UNPOOLED). Each file runs in its own transaction and is recorded with a checksum; a changed file stops the run. Run pnpm db:pending first to list what isn't applied yet.
Additive migrations (new nullable column, new table, new index) can go first, then push the code. That's the default order.
If new code writes to a new column or table, apply the migration before pushing. Otherwise those writes fail until it lands.
If a migration removes or tightens something the old code still uses, deploy the code first, then apply the migration.
Each recent migration file starts with a comment giving its deploy order and the SQL to undo it. Read it before
pnpm db:migrate.Before pushing,
pnpm db:pendinglists migrations not yet applied to production (exit 1 if any). It's read-only.After applying, run the read-only check from the migration's entry in
IMPLEMENTATION_LOG.mdwhen there is one (e.g. backfill counts).Migration gate. The deploy checks production before building (
node scripts/db-migrate.mjs --gate) and stops when a migration is pending and not marked-- deploy: after, or when an applied file was edited or is missing. Fix:pnpm db:migrate, then re-run the Deploy workflow (Actions → Deploy → Run workflow). A migration the code doesn't need yet (a drop of something the old code still reads) gets a header line-- deploy: after: it doesn't block, and the log lists it to apply after the deploy. If the database can't be reached the deploy stops too; in an emergency, run Deploy by hand with Skip the pending-migration check. CI'smigrationsjob runs the same check on every push as an early warning. Both connect asci_migration_check, a role that can read onlypublic.schema_migrations(migration 0005), and never print the database host. One-time setup (done for production), after applying 0005:bash# as the owner, on production; PASSWORD is a long random value psql "$DATABASE_URL_UNPOOLED" -c "CREATE ROLE ci_migration_check LOGIN PASSWORD '<PASSWORD>' IN ROLE migration_reader" # the same direct (unpooled) URL with that user and password: gh secret set MIGRATION_CHECK_DATABASE_URL # paste postgresql://ci_migration_check:<PASSWORD>@<host>/<db>?sslmode=requireWithout the secret both only print a notice (the deploy goes ahead). To revoke: delete the secret and
DROP ROLE ci_migration_check.
Rollback and recovery
Rehearsed: restoring a pnpm db:backup dump (2026-11-11, see below). Not rehearsed: a Worker rollback, a Layerbase restore from its own backups, and R2. Treat those parts as the procedure to follow and test, not as proof that they work.
Roll back the code (Workers)
Two Workers are deployed: garage-temp (the app, dist/server/wrangler.json) and probeharbor-i18n (translations, workers/i18n/wrangler.jsonc).
pnpm build # creates dist/server/wrangler.json
npx wrangler deployments list --config dist/server/wrangler.json # tag column = app version
npx wrangler rollback <version-id> --config dist/server/wrangler.json -m "reason"- A rollback swaps the running code within seconds. It does not undo database migrations, Worker secrets or cron changes.
- The next push to
maindeploys again. To keep the old code, alsogit revertthe bad commit and push (CI then deploy takes about 15 minutes). - If the bad version came with a migration the old code can't handle, undo the migration first, using the SQL in its header comment, after checking what data the undo would drop.
Database backups (Layerbase)
Layerbase has no point-in-time restore; it keeps its own backup every 12 hours (not verified here). The copies that matter are the ones you make: if the database is lost or corrupted between them, every reading, alert, account and device key since the last copy is gone.
Off-site copies are made every 6 hours (below). Also make a local one before a migration that changes or removes data:
pnpm db:backup- It reads
DATABASE_URL_UNPOOLEDfrom.env(Layerbase's direct connection string; the pooled one doesn't work withpg_dump), or another variable with--url-env NAME. It's local only and isn't pushed to the Worker. - It needs
pg_dump18 or newer (the database runs Postgres 18). - It writes
backups/probeharbor-<UTC time>.dump(compressed, custom format;backups/is gitignored). It only reads from the database. - A failed run leaves no file behind.
- The dump holds user data and hashed credentials: keep it encrypted, off shared drives, and delete old ones you don't need.
- Check a dump with
pg_restore --list <file> | head.
To restore into a new, empty database (never over the live database without a fresh dump first), put its connection string in .env (e.g. as RESTORE_DATABASE_URL) and run:
node scripts/db-restore.mjs <file>.dump --to-env RESTORE_DATABASE_URLIt refuses a target that already has tables, and works for any Postgres 18+. A plain pg_restore of a Layerbase dump fails on Postgres elsewhere (unrecognized parameter "pg_attver": Layerbase marks columns with a private option that pg_dump writes out); the script leaves those options out (they hold no data) and restores the rest in one transaction, stopping at the first error. Rehearsed 2026-11-15: a Layerbase production dump into plain Postgres 18: 54 tables, 301,924 rows, 479 options left out.
Restoring loses everything written after the dump.
Rehearsal (2026-11-11), into a throwaway local Postgres 18.6: a fresh pnpm db:backup (3.5 MB) restored with the command above in under a second, 0 errors. All 57 public tables matched production row for row, except sensor_readings, where the only difference was the readings posted after the dump started (every production row up to the dump's newest id was present). 11 users and 8 password logins came back. To check a restore the same way, count rows per table on both sides:
-- run on the restored database, then run its output on both databases
select string_agg(format('select %L t, count(*) n from public.%I', table_name, table_name), ' union all ')
from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE';Run it on production inside begin read only; … rollback;. Not covered by the rehearsal: restoring into a new Layerbase database and pointing the Worker at it (the Hyperdrive config's connection string, and DATABASE_URL), and signing in against a restored copy.
Automatic off-site backups
.github/workflows/db-backup.yml runs scripts/db-backup-offsite.sh every 6 hours (02:17, 08:17, 14:17, 20:17 UTC; the database is Layerbase since 2026-11-15, which has no point-in-time restore) (and on demand: Actions → Database backup → Run workflow):
pg_dump(viascripts/db-backup.mjs) with a read-only role;- checks the dump with
pg_restore --listand refuses one withoutsensor_readingsdata; - encrypts it with age to your public key and deletes the plain copy;
- uploads
db/probeharbor-<UTC time>.dump.ageto a private R2 bucket; - downloads it again and compares checksums.
The repo is public, so the dump is never a GitHub artifact and the database host is masked in the log. Only the age private key can read a backup: keep it in a password manager. Lose it and the backups are useless. A failed run (including "not configured") emails whoever last changed the schedule.
Setup (once):
Key pair. Install age (
sudo pacman -S age,brew install age), thenage-keygen -o probeharbor-backup-key.txt. Put that file in your password manager and delete it from disk. Save the public key it prints:gh variable set BACKUP_AGE_RECIPIENT --body "age1…".Bucket.
pnpm wrangler r2 bucket create probeharbor-db-backups, and a lifecycle rule deletingdb/objects after 35 days (dashboard: R2 → the bucket → Settings → Object lifecycle rules). Thengh variable set R2_BACKUP_BUCKET --body probeharbor-db-backupsandgh variable set R2_ACCOUNT_ID --body <Cloudflare account id>.R2 token. Dashboard: R2 → Manage API tokens → Create: Object Read & Write, that bucket only.
gh secret set R2_BACKUP_ACCESS_KEY_IDandgh secret set R2_BACKUP_SECRET_ACCESS_KEY(paste when asked).Read-only database role. Every table has row-level security, so the role needs
BYPASSRLSto see all rows. On Layerbase (psqlwith the direct string), as the ownerpostgres, in databaseprobeharbor:sqlcreate role backup_reader login bypassrls password '<long random>'; grant connect on database probeharbor to backup_reader; grant usage on schema public to backup_reader; grant select on all tables in schema public to backup_reader; grant select on all sequences in schema public to backup_reader; alter default privileges for role postgres in schema public grant select on tables to backup_reader; alter default privileges for role postgres in schema public grant select on sequences to backup_reader;If a host refuses
bypassrls, use the owner's direct connection string instead (whatpnpm db:backupuses); it works, with more access than a backup needs. Either way use the direct (unpooled) string:gh secret set BACKUP_DATABASE_URL.First run.
gh workflow run db-backup.yml, then check the run's summary ("Backed up N tables, … verified") and that the object is in the bucket.
Status: set up 2026-11-14 on Neon; restore rehearsed the same day into an empty local Postgres 18 (no errors; schema identical to a database built from the migrations). Moved to Layerbase with the database (2026-11-15: backup_reader with BYPASSRLS there, every 6 hours). The dump still leaves out a neon_auth schema if one exists (Neon's own auth product, unused; Layerbase has none). BACKUP_DATABASE_URL may be the bare URL or a psql '…' form.
Restore from R2: download the object (dashboard, pnpm wrangler r2 object get probeharbor-db-backups/db/<file> --remote --file <file>, or aws s3 cp s3://probeharbor-db-backups/db/<file> . --endpoint-url https://<account id>.r2.cloudflarestorage.com with an R2 token), then age -d -i probeharbor-backup-key.txt <file>.dump.age > <file>.dump and restore it with scripts/db-restore.mjs as above, into a new, empty database.
Other state
- R2
thermaltrace-history(history archives and chart images): R2 has no object versioning, so a deleted or overwritten object can't be recovered. The archive job had written no objects as of 2026-10-27 (history_archiveswas empty); the bucket mainly holds shared chart images, which aren't in the database dump. - Worker secrets come from your local
.envviapnpm secrets:push. Keep.envin a password manager. A lost.envmeans rotating every key. - Stripe is the source of truth for subscriptions. After a database restore, subscription rows can be older than Stripe; compare affected accounts against the Stripe dashboard. (
pnpm audit:stripechecks display prices only.)
Custom domain
The Worker binds probeharbor.dev (and www → apex via middleware). Legacy hostnames listed in wrangler.jsonc redirect with 301. Set SITE_URL and ORIGIN to https://probeharbor.dev, then pnpm secrets:push.
Public smoke (no auth)
pnpm smoke:public
pnpm ops:smoke # smoke + sitemap coverage + IndexNow dry run
pnpm ping:sitemaps # submit public URLs to IndexNow (also runs after each deploy)Submit https://probeharbor.dev/sitemap-index.xml in Google Search Console → Sitemaps.
Sitemaps are SSR routes (/sitemap-0.xml, /sitemap-index.xml) so they stay available on Cloudflare Workers even when static Asset uploads omit build-time XML.
Admin channel tests (SMS/push) run from Dashboard → Ops after sign-in.
External heartbeat
The Worker's "collect-history overdue" email runs inside the same cron it checks, so if the cron stops or the Worker is down, nothing gets sent. Point an uptime monitor that runs outside Cloudflare at:
GET https://probeharbor.dev/api/health| Response | Meaning |
|---|---|
200 {"status":"ok"} | collect-history succeeded within the last ~35 minutes |
503 {"status":"stale"} | no successful poll in ~35 minutes (two missed 15-minute runs plus grace) |
503 {"status":"unknown"} | the database couldn't be read |
| no answer or a 5xx from Cloudflare | Worker or edge down |
Alert on any non-200. Check every 5 minutes; a 1-minute interval adds load and catches nothing sooner, because the threshold is ~35 minutes. The endpoint needs no auth, returns no per-user or per-job detail and is not cached.
What watches it: GitHub Actions (.github/workflows/heartbeat.yml), from outside Cloudflare at :07, :22, :37 and :52, three tries a minute apart. A failed run emails whoever last changed the schedule. GitHub may start scheduled runs late and pauses them after 60 days without repo activity; re-enable under Actions → Heartbeat if that happens. A second, independent monitor (any uptime service outside Cloudflare, every 5 minutes, alert on non-200) would add a faster check.
Post-deploy smoke checklist
- [ ]
/system-status— healthy + recent cron runs - [ ]
/pricing— amounts match Stripe (monthly/annual toggle) - [ ]
/compare,/docs/api, case study CTAs →/pricing - [ ] Dashboard → Ops (admin) — email + channel smoke tests (SMS/push when configured)
- [ ] Enable NWS freeze alerts under Alerts after migration
- [ ] Save display prefs / alert settings (Actions) without full reload
- [ ] Optional:
OPS_DISCORD_WEBHOOK_URLfor failure Discord - [ ] Test alert → Share page webhook delivery log (Pro)
CI on every push to main: astro sync + typecheck, unit tests, build, Playwright smoke.