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>
2.3 KiB
Database schema
docwell-db is a stock PocketBase: the stack runs
tajniak81/pocketbase-docker-root
(source) as it is. There is no Docwell image for it any more.
docwell-server brings PocketBase up to Docwell's schema itself, every time it starts
(Server/internal/pbschema): missing collections and fields are created,
existing ones keep their data. It also writes the DOCWELL_* settings (app name and URL, mail, file storage) and
sends Docwell's own emails, so PocketBase needs no hooks either.
This folder is where that schema is written:
pb_migrations/holds the JS migrations, the source of truth for the schema.export-schema.shturns them intoServer/internal/pbschema/schema.json, the snapshot docwell-server embeds and applies.- All collection API rules are
null, so only superusers have access. Never expose PocketBase publicly; only docwell-server talks to it.
Changing the schema
-
Add a migration to
pb_migrations/(pocketbase migrate create "add_comments" --migrationsDir ./pb_migrations, or copy an existing file). Leave earlier migrations alone. -
Regenerate the snapshot (needs Docker and Go):
sh Database/export-schema.sh -
Commit the migration and the new
schema.jsontogether.go test ./internal/pbschemachecks the snapshot.
Removing a collection or a field is not done by the snapshot: it only adds and updates. Do that by hand, once, in the PocketBase dashboard of each install, after the release that stops using it.
The admin panel manages two parts of the users collection itself, the OAuth2 providers and the magic link switch
(otp.enabled), so the snapshot leaves them out and they keep whatever is set.
Run locally
Download PocketBase v0.40.6 for your OS into Database/bin/, then:
./bin/pocketbase superuser upsert admin@docwell.test devpassword123 --dir ./pb_data
./bin/pocketbase serve --dir ./pb_data --http 127.0.0.1:8070
Start docwell-server against it (DOCWELL_PB_EMAIL and DOCWELL_PB_PASSWORD set to that superuser) and it creates
the collections. The PocketBase dashboard is at http://127.0.0.1:8070/_/.