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
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>
48 lines
2.3 KiB
Markdown
48 lines
2.3 KiB
Markdown
# Database schema
|
|
|
|
docwell-db is a stock [PocketBase](https://pocketbase.io): the stack runs
|
|
[`tajniak81/pocketbase-docker-root`](https://hub.docker.com/r/tajniak81/pocketbase-docker-root)
|
|
([source](https://github.com/freefall-dev/PocketBase-docker)) 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`](../Server/internal/pbschema/pbschema.go)): 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.sh` turns them into `Server/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
|
|
|
|
1. Add a migration to `pb_migrations/` (`pocketbase migrate create "add_comments" --migrationsDir ./pb_migrations`,
|
|
or copy an existing file). Leave earlier migrations alone.
|
|
2. Regenerate the snapshot (needs Docker and Go):
|
|
|
|
```bash
|
|
sh Database/export-schema.sh
|
|
```
|
|
|
|
3. Commit the migration and the new `schema.json` together. `go test ./internal/pbschema` checks 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:
|
|
|
|
```bash
|
|
./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/_/.
|