Files
Docwell/Server/cmd/pbschema-export/main.go
T
tajniak81andClaude Opus 5.5 cad42fbe89
CI / desktop (ubuntu-latest) (push) Successful in 2h34m54s
CI / mobile (push) Failing after 4m52s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / docker (push) Successful in 53m34s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / go (Media) (push) Successful in 13m0s
CI / go (Server) (push) Successful in 24m4s
CI / go (Web-App) (push) Successful in 12m35s
CI / frontend (push) Failing after 11m51s
Prepare the 0.3.0 release
CHANGELOG.md gets the 0.3.0 notes: everything since 0.2.0 by area, and
the steps for upgrading a 0.2.0 install (new compose files with a stock
PocketBase on 8070, pb_data at /pb/pb_data, the media service, and the
SMTP password to enter once more). The release workflow now uses the
tag's CHANGELOG section as the Gitea release text. A v0.2.0 compose stack
with data was upgraded in place to this commit and kept its data.

Also fixes what CI would have failed on:
- Server lint (golangci-lint v2.14): errors.Is/As for sentinel errors,
  the bbolt/errors package instead of the deprecated bolt error, one
  needless conversion, and commented nolints for gosec false positives.
- SPDX headers on Database/export-schema.sh and Server/entrypoint.sh.
- Prettier on two files; the generated pbschema/schema.json is ignored.
- The editor-bridge dist page rebuilt to match the phone app's copy.

PLAN.md and the upgrade guide point to the release notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 10:21:57 +01:00

76 lines
2.1 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
// Command pbschema-export writes internal/pbschema/schema.json from a running
// PocketBase that has applied Database/pb_migrations. Database/export-schema.sh
// starts that PocketBase and runs this; there is no need to call it directly.
//
// pbschema-export -url http://127.0.0.1:18070 -email ... -password ... -out internal/pbschema/schema.json
package main
import (
"bytes"
"context"
"encoding/json"
"flag"
"fmt"
"net/http"
"os"
"strings"
"docwell/server/internal/store/pocketbase"
)
func main() {
url := flag.String("url", "http://127.0.0.1:18070", "PocketBase URL")
email := flag.String("email", "", "superuser email")
password := flag.String("password", "", "superuser password")
out := flag.String("out", "internal/pbschema/schema.json", "output file")
flag.Parse()
if err := run(*url, *email, *password, *out); err != nil {
fmt.Fprintln(os.Stderr, "pbschema-export:", err)
os.Exit(1)
}
}
func run(url, email, password, out string) error {
pb := pocketbase.New(url, email, password)
var res struct {
Items []map[string]any `json:"items"`
}
if err := pb.Do(context.Background(), http.MethodGet, "/api/collections?perPage=1000&skipTotal=1&sort=created", nil, &res); err != nil {
return err
}
var cols []map[string]any
for _, c := range res.Items {
name, _ := c["name"].(string)
// PocketBase's own system collections (_superusers, _otps, ...).
if strings.HasPrefix(name, "_") {
continue
}
delete(c, "created")
delete(c, "updated")
if name == "users" {
// Managed in the admin panel; the import keeps whatever is set.
delete(c, "oauth2")
if otp, ok := c["otp"].(map[string]any); ok {
delete(otp, "enabled")
}
}
cols = append(cols, c)
}
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false) // keep the email templates readable in diffs
enc.SetIndent("", " ")
if err := enc.Encode(cols); err != nil {
return err
}
if err := os.WriteFile(out, buf.Bytes(), 0o644); err != nil { //nolint:gosec // a checked-in source file, readable like the others
return err
}
fmt.Printf("wrote %d collections to %s\n", len(cols), out)
return nil
}