fix pb migration
This commit is contained in:
@@ -192,6 +192,30 @@
|
||||
- Verified: proxy build + frontend build + `svelte-check` all clean for `@shared/*` (svelte-check still reports pre-existing `qrcode` types + CSS warnings).
|
||||
- Docker note: runtime image only copies `frontend/build` + `proxy/dist` (both already bundle `shared/`), so `shared/` needn't be copied into the image.
|
||||
|
||||
### 2026-08-10 — Dev runtime cleanup (PB instances / containers)
|
||||
- **Removed** test container `31e74178b3f0` (`famdone-service-app-1`, host :3010 + :8092). It ran **PB 0.39.10** and bound the **same host `pb_data`** as pb-dev → two PBs (v0.25 + v0.39) writing one SQLite DB = corruption/lock risk (likely source of dev instability/login lag).
|
||||
- **Killed** 7 stale host `tsx watch` dev-proxy processes (Jul 28–Aug 5) + my throwaway 0.39 PBs.
|
||||
- **Reset pb_data**: stopped pb-dev, wiped `/home/threejjjs/development/famchamp/pb_data`, **recreated** pb-dev container (fresh v0.25 store) with `--automigrate=false`, recreated dev superuser `debug@famchamp.dev`/`debug123`.
|
||||
- **Why recreate pb-dev**: v0.25 automigrate had baked stale `pb_migrations` into the old container's writable layer; on a fresh store they failed (`Failed to apply migration ...: no rows in result set`).
|
||||
- **Desired end state (confirmed)**: `8090` = pb-dev (v0.25, single instance, automigrate off); `3001`+`8091` = PROD app `cffd636cc772` (kept, not live); PROD pb_data at `/data/coolify/.../pb_data` (separate from dev).
|
||||
|
||||
### 2026-08-10 — PB 0.25 → 0.39 migration (branch `feature/migrate-pocketbase`)
|
||||
- **Decision**: keep our own `migrate.ts` schema-as-code (API-driven, does data migrations + rule locking), NOT PocketBase's built-in automigrate (schema-only, generates version-specific migration files, and generates conflicting snapshots on upgraded stores). Disable PB automigrate in the runtime.
|
||||
- **Verified against 0.39.10** (throwaway binaries on `127.0.0.1:8098/8099`, temp data dirs):
|
||||
1. Fresh store: `migrate()` bootstraps all 14 `SCHEMA_PLAN` collections + every field migration cleanly (schema field builders are 0.39-compatible).
|
||||
2. Existing 0.25 `pb_data` → 0.39: opens & serves with **`--automigrate=false`** and no stale `pb_migrations` dir. (Without this, automigrate writes a snapshot to `./pb_migrations` relative to CWD that conflicts with existing collections → "Collection name must be unique".)
|
||||
3. JS SDK `pocketbase@^0.27.0`: `authWithPassword` + public reads OK; realtime SSE endpoint serves `PB_CONNECT`.
|
||||
- **Code changes on branch**:
|
||||
- `docker/Dockerfile` `POCKETBASE_VERSION` → `0.39.10`.
|
||||
- `docker/Dockerfile.dev` → `0.39.10` + `CMD ... --automigrate=false`.
|
||||
- `docker/entrypoint.sh` → `pocketbase serve ... --automigrate=false`.
|
||||
- `proxy/src/env.ts` → added non-breaking `PB_ENDPOINT` env override (used to point migrate at a throwaway PB on another port; default dev/prod split unchanged).
|
||||
- **⚠️ 0.39 schema breaking change**: PB 0.39 does **NOT** auto-add `createdAt`/`updatedAt` to **API-created** collections (0.25 did). The chat store filters/sorts on a custom `messages.createdAt`, so a fresh 0.39 store is missing it → raw PB 400. Fixed two ways:
|
||||
- `shared/pb/schema.ts`: `messages` now declares `date("createdAt")` explicitly (source of truth → `ensureSchema`).
|
||||
- `proxy/src/migrate.ts`: the "messages already exists" branch now adds `createdAt` if missing (idempotent hardening for drifted/upgraded stores).
|
||||
- **Dev now on 0.39.10**: pb-dev rebuilt from branch `Dockerfile.dev` (0.39.10 + `--automigrate=false`), fresh store on :8090, superuser `debug@famchamp.dev` re-verified, `migrate()` bootstraps schema + applies `messages.createdAt` fix cleanly.
|
||||
- **Prod upgrade steps**: backup `pb_data` → run the 0.39 image (automigrate off) → run `migrate()` → verify no drift (`messages.createdAt`, `id.autogeneratePattern`).
|
||||
|
||||
### 2026-08-10 — Revert PB to 0.25.8 (backtrack from 0.39)
|
||||
- **Decision**: backtrack off the PocketBase 0.39 bump (introduced in commit `3725c54` via `ARG POCKETBASE_VERSION=0.39.10`) and work from a **0.25.8 baseline** in BOTH dev and prod, then migrate to 0.39 deliberately later.
|
||||
- Reverted `docker/Dockerfile` `POCKETBASE_VERSION` back to `0.25.8` (matches `docker/Dockerfile.dev`). Dev `pb-dev` and the docker app internal PB `:8091` share host `./pb_data`.
|
||||
|
||||
Reference in New Issue
Block a user