feat: replace pb-init-v3.sh with PocketBase Go migrations
Adds a custom PocketBase binary (cmd/pocketbase) that embeds PocketBase as a Go framework with version-controlled migrations, replacing the fragile 419-line shell script. Migrations apply automatically on every `serve` startup. Migration 1 (20260414000001): full baseline schema — all 21 collections, both indexes on chapters_idx, and initial superuser creation from env vars. Migration 2 (20260414000002): adds three fields found in code but missing from the old script — books.rating, app_users.notify_new_chapters_push, book_comments.chapter. docker-compose: pocketbase service now uses the custom kalekber/libnovel-pocketbase image; pb-init one-shot container removed (migrations replace it entirely). Existing installs: run `migrate history-sync` once to mark migration 1 as done, then restart — migration 2 will apply the three previously missing fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
backend/cmd/pocketbase/main.go
Normal file
47
backend/cmd/pocketbase/main.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Command pocketbase is a thin wrapper that runs PocketBase as a Go framework
|
||||
// with version-controlled Go migrations.
|
||||
//
|
||||
// On every `serve`, PocketBase automatically applies any pending migrations from
|
||||
// the migrations/ package before accepting traffic.
|
||||
//
|
||||
// Usage (Docker):
|
||||
//
|
||||
// ./pocketbase serve --dir /pb_data --http 0.0.0.0:8090
|
||||
//
|
||||
// Migration workflow:
|
||||
//
|
||||
// # Generate a timestamped stub:
|
||||
// go run ./cmd/pocketbase migrate create "description"
|
||||
// # Apply manually (also runs automatically on serve):
|
||||
// go run ./cmd/pocketbase migrate up
|
||||
// # Revert last migration:
|
||||
// go run ./cmd/pocketbase migrate down 1
|
||||
// # After migrating an existing install, mark existing schema as done:
|
||||
// go run ./cmd/pocketbase migrate history-sync
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
|
||||
// Register all migrations via init().
|
||||
_ "github.com/libnovel/backend/migrations"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := pocketbase.New()
|
||||
|
||||
// Register the migrate sub-command.
|
||||
// Automigrate: false — migrations are written by hand, never auto-generated
|
||||
// from Admin UI changes. Pending migrations still apply automatically on
|
||||
// every `serve` regardless of this flag.
|
||||
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
|
||||
Automigrate: false,
|
||||
})
|
||||
|
||||
if err := app.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user