diff --git a/00-overview/postgres-migration-roadmap.md b/00-overview/postgres-migration-roadmap.md index 98bb3bf..67c3070 100644 --- a/00-overview/postgres-migration-roadmap.md +++ b/00-overview/postgres-migration-roadmap.md @@ -505,6 +505,8 @@ | 2026-11-19 | Phase 8: health/monitoring | Healthcheck script, public `/health` contract, Synapse alert plumbing; hard-panel registration and Synapse source remain owner actions | | 2026-11-19 | Phase 8: deploy/docs | `deploy.sh` applies migrations and refreshes units; operations and decommission runbooks; service page updated | | 2026-11-19 | Phase 8: decommission | Blocked on production cutover and owner sign-off; file backend retained for rollback | +| 2026-11-20 | Data ownership | `documents.owner_user_id` and `inventory_items.owner_user_id`; `assign-owner`/`ownership` CLI; current 33 documents and 84 inventory items assigned to the first user (`sub=1`, superadmin); historical import authorship preserved | +| 2026-11-20 | Rollout state | Local database/auth rollout verified; production deployment target not available on the development machine and remains pending | Notes: @@ -548,3 +550,8 @@ repository remain until the production cutover has run for the agreed stability window and the owner signs off [decommission-file-backend.md](../30-runbooks/decommission-file-backend.md). +- Current data ownership is assigned locally to the first user (`sub=1`, superadmin): + 33 documents and 84 inventory items, 0 unowned. Production assignment should use + `GNEXUS_BOOK_OWNER_JSON` during cutover or the `assign-owner` CLI afterwards. +- Production rollout is pending a deployment target: the development machine has no + `/home/ubuntu/gnexus-book`, `/var/www/gnexus-book`, or running Gnexus Book services. diff --git a/30-runbooks/cutover-postgres.md b/30-runbooks/cutover-postgres.md index 02c0ebd..4f86b8f 100644 --- a/30-runbooks/cutover-postgres.md +++ b/30-runbooks/cutover-postgres.md @@ -49,16 +49,31 @@ ./scripts/cutover-db.sh --replace ``` -4. Set the service environment: +4. Assign imported data to the first admin (recommended). Either set + `GNEXUS_BOOK_OWNER_JSON=/path/to/owner.json` before step 3 (then + `cutover-db.sh` assigns it after import), or run after import: + + ```bash + cd server + GNEXUS_BOOK_DATABASE_URL=postgresql+psycopg://... \ + .venv/bin/python -m app.storage.cli assign-owner \ + --user-json /path/to/owner.json + .venv/bin/python -m app.storage.cli ownership + ``` + + The owner JSON contains `sub`, `email`, `system_role`, `status` and `profile` + (`display_name`, `locale`, `timezone`, avatar URL). + +5. Set the service environment: ```text GNEXUS_BOOK_STORAGE_BACKEND=db GNEXUS_BOOK_DATABASE_URL=postgresql+psycopg://... ``` -5. Restart `gnexus-book-backend` and `gnexus-book-mcp`. -6. Run the post-cutover checks below. -7. Unfreeze writes and announce completion. +6. Restart `gnexus-book-backend` and `gnexus-book-mcp`. +7. Run the post-cutover checks below. +8. Unfreeze writes and announce completion. ## Post-cutover checks diff --git a/30-runbooks/postgres-operations.md b/30-runbooks/postgres-operations.md index c3c85d6..848fa52 100644 --- a/30-runbooks/postgres-operations.md +++ b/30-runbooks/postgres-operations.md @@ -71,6 +71,27 @@ - Register the probe in hard-panel and create the alert route in Synapse. The book service does not own notification channels; Synapse routing decides recipients. +## Data ownership + +Imported documents and inventory can be assigned to the first admin user: + +```bash +set -a; . server/.env; set +a +cd server +.venv/bin/python -m app.storage.cli assign-owner --user-json /path/to/owner.json +.venv/bin/python -m app.storage.cli ownership +``` + +The owner JSON contains `sub`, `email`, `system_role`, `status` and `profile` +(display name, locale, timezone, avatar URL). The command creates or updates the local +user mirror, assigns only rows with no owner by default, and writes an +`ownership.assigned` audit record. `--all` transfers every document and inventory item +to the new owner. + +Ownership is separate from historical authorship: imported versions and the import +changeset retain their `system`/`importer` authorship, while `owner_user_id` records +who the data belongs to. + ## Migrations and deploys `scripts/deploy.sh` sources `server/.env`; when diff --git a/CLAUDE.md b/CLAUDE.md index e137e85..f313263 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -63,6 +63,8 @@ .venv/bin/python -m app.storage.cli import --replace .venv/bin/python -m app.storage.cli parity # exits 1 on a file/DB difference .venv/bin/python -m app.storage.cli migrate --replace --manifest /tmp/report.json +.venv/bin/python -m app.storage.cli assign-owner --user-json /tmp/owner.json +.venv/bin/python -m app.storage.cli ownership # Rehearsed/real cutover and rollback verification ../scripts/cutover-db.sh --replace diff --git a/server/README.md b/server/README.md index 52f49ad..6614069 100644 --- a/server/README.md +++ b/server/README.md @@ -53,6 +53,12 @@ documents, search, inventory, relationships, validation and freshness. It exits non-zero on any discrepancy. +`python -m app.storage.cli assign-owner --user-json /path/to/owner.json` creates or +updates the owner mirror, assigns unowned documents and inventory items, and writes an +`ownership.assigned` audit entry. `ownership` prints owned/unowned counts. Historical +import authorship is preserved; ownership is stored separately in +`documents.owner_user_id` and `inventory_items.owner_user_id`. + For a rehearsed or real cutover use the scripts: ```bash