Files
Docwell/Database/export-schema.sh
T
tajniak81andClaude Opus 5.5 b9be8be156
CI / go (Server) (push) Failing after 22m50s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 8m47s
CI / desktop (ubuntu-latest) (push) Successful in 2h56m50s
CI / mobile (push) Failing after 5m33s
CI / docker (push) Successful in 1h43m8s
Docs / build (push) Successful in 16m2s
Docs / deploy (push) Skipped
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Run docwell-db as a stock PocketBase and let the server set it up
docwell-db no longer needs a Docwell image: the stack runs
tajniak81/pocketbase-docker-root as it is, and docwell-server does what
the migrations and pb_hooks used to do inside PocketBase.

On start, docwell-server now:
- waits for PocketBase and imports Docwell's collections from an
  embedded snapshot (internal/pbschema). Existing collections and
  fields are matched by name, so their data is kept; the admin-managed
  users options (OAuth2 providers, magic link) are left untouched.
- writes the DOCWELL_APP_NAME, DOCWELL_WEB_URL, DOCWELL_MAIL_FROM,
  DOCWELL_SMTP_* and DOCWELL_S3_* settings into PocketBase, as the
  boot hook did.

It also replaces the hook's two routes: token checks use PocketBase's
auth-refresh (the organization name is read as the superuser), and
Docwell's own emails go out over SMTP from the server. PocketBase never
returns the SMTP password, so the server keeps a copy in the
superuser-only instance_settings collection; a password saved before
this change has to be entered once more in the admin panel.

Database/ keeps pb_migrations as the source of the schema;
export-schema.sh regenerates the snapshot from them. Database/Dockerfile
and pb_hooks are removed, the release no longer builds docwell-db, the
AIO image runs PocketBase without migrations or hooks, and the compose
files default DB_IMAGE to the stock image and pass the settings to the
server instead of the database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 20:09:38 +01:00

47 lines
1.5 KiB
Bash

#!/bin/sh
# Regenerates Server/internal/pbschema/schema.json from pb_migrations.
#
# docwell-server applies that snapshot to PocketBase on every start, so after
# adding or changing a migration here, run this and commit the new JSON:
#
# sh Database/export-schema.sh
#
# Needs Docker and Go. Starts a throwaway PocketBase (the same base image the
# stack runs), lets it apply the migrations to an empty database, exports the
# collections, and removes the container.
set -eu
cd "$(dirname "$0")/.."
ROOT=$(pwd)
# Docker Desktop on Windows wants E:/..., not Git Bash's /e/...
MOUNT_ROOT=$(pwd -W 2>/dev/null || pwd)
IMAGE="${PB_IMAGE:-tajniak81/pocketbase-docker-root:0.40.6}"
NAME=docwell-schema-export
PORT=18070
EMAIL=export@docwell.localhost
PASSWORD=export-only-password
docker rm -f "$NAME" >/dev/null 2>&1 || true
trap 'docker rm -f "$NAME" >/dev/null 2>&1 || true' EXIT
# Git Bash on Windows rewrites /pb/... paths unless told not to.
MSYS_NO_PATHCONV=1 docker run -d --name "$NAME" -p "127.0.0.1:$PORT:8070" \
-e PB_ADMIN_EMAIL="$EMAIL" -e PB_ADMIN_PASSWORD="$PASSWORD" \
-v "$MOUNT_ROOT/Database/pb_migrations:/pb/pb_migrations:ro" \
"$IMAGE" >/dev/null
i=0
until docker exec "$NAME" wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1; do
i=$((i + 1))
if [ "$i" -gt 60 ]; then
docker logs "$NAME"
echo "PocketBase did not start" >&2
exit 1
fi
sleep 1
done
cd "$ROOT/Server"
go run ./cmd/pbschema-export -url "http://127.0.0.1:$PORT" -email "$EMAIL" -password "$PASSWORD" \
-out internal/pbschema/schema.json