Skip to content

feat(selfhost): prepare Postgres cutover tooling#1986

Merged
JSONbored merged 6 commits into
mainfrom
codex/postgres-transition-readiness
Jul 1, 2026
Merged

feat(selfhost): prepare Postgres cutover tooling#1986
JSONbored merged 6 commits into
mainfrom
codex/postgres-transition-readiness

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

Prepare the self-host stack for a safe SQLite to Postgres cutover without changing the default runtime mode.

What changed

  • Added a dry-run-first SQLite to Postgres migration command for self-host state.
  • Added Postgres support to the Grafana reporting exporter while preserving the redacted SQLite reporting snapshot format.
  • Wired the reporting exporter container with the Postgres client and explicit Postgres reporting env knobs.
  • Updated self-host env/docs guidance so Postgres uses PgBouncer and keeps Qdrant as the preferred vector store.
  • Added exporter regressions for Postgres snapshots and Postgres metadata failure handling.

Why

Postgres is the safer backend for higher-concurrency self-host operation, queue claiming, and future multi-instance scaling. This keeps current SQLite deployments untouched until an operator explicitly sets DATABASE_URL and runs the one-time migration.

Validation

  • git diff --check
  • npm run db:migrations:check
  • npm run typecheck
  • npm run ui:typecheck
  • npm run ui:lint
  • npm run ui:openapi:check
  • npm run ui:build
  • npm run test:coverage
  • npx vitest run test/unit/selfhost-grafana-reporting.test.ts
  • npm run selfhost:postgres:migrate -- --help
  • Real Postgres smoke: dry-run rolled back schema, then --execute copied sample app and queue rows into pgvector/pg16.
  • Alpine sidecar smoke: confirmed sqlite, psql, and postgresql16-client are available in alpine:3.20.

Notes

  • SQLite remains the default.
  • No production deployment is changed by this PR.
  • The migration command refuses non-empty target tables by default and only commits with --execute.

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 1, 2026
@gittensory-orb

gittensory-orb Bot commented Jul 1, 2026

Copy link
Copy Markdown

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-01 06:04:32 UTC

7 files · 1 AI reviewer · no blockers · readiness 68/100 · CI pending · blocked

⏸️ Suggested Action - Manual Review

  • Touches a guarded path — held for manual review

Review summary
The PR adds the expected Postgres cutover pieces without changing SQLite defaults: a dry-run-first migrator, Postgres-backed Grafana snapshot export, compose wiring, docs, and focused exporter regressions. The migrator is conservative about non-empty targets and validates copied source rows after queue re-initialization; the failed automated concern about `--allow-non-empty` is not borne out by the visible code because conflicts are checked before `ON CONFLICT DO NOTHING` and validation counts matching source keys. I do not see a diff-proven correctness break in the provided files.

Nits — 7 non-blocking
  • nit: `scripts/migrate-selfhost-sqlite-to-postgres.ts:279` reports `rows` as the total source rows processed, which includes rows skipped by `ON CONFLICT DO NOTHING` during `--allow-non-empty`, so the summary can overstate newly inserted rows.
  • nit: `scripts/export-grafana-reporting-db.sh:55` leaves `$TMP_DB` behind on a Postgres COPY/import failure; the trap only removes the CSV directory, so failed exports can leave transient SQLite files next to the output path.
  • nit: `test/unit/selfhost-grafana-reporting.test.ts:39` fake `psql` only pattern-matches fragments of the SQL text and does not assert the exact COPY shape, so it can miss accidental query drift in the exporter.
  • In `scripts/migrate-selfhost-sqlite-to-postgres.ts:279`, rename `rows` to `sourceRows` or separately track inserted/skipped counts so operator output is precise for `--allow-non-empty`.
  • In `scripts/export-grafana-reporting-db.sh:9`, extend `cleanup()` to remove `$TMP_DB`, `$TMP_DB-wal`, and `$TMP_DB-shm` on failure while preserving the final `mv` success path.
  • Readiness score is below the configured threshold — Use the readiness panel as advisory maintainer context; the score does not block this PR.
  • Touches a guarded path — held for manual review — A maintainer must review and merge this change.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ⚠️ 1 scoped overlap Top overlaps are listed below; lower-confidence bulk is hidden.
Change scope ❌ 8/20 High review scope from cached public metadata (size label size:XL; no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 68 registered-repo PR(s), 58 merged, 209 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 68 PR(s), 209 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 68 PR(s), 209 issue(s).
  • Related work: Titles/paths share 7 meaningful terms. (PR #1922, PR #1945)
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Review top overlaps.
  • Add a concise scope and risk note.
  • Triage stale or unlinked PRs.
  • No action.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
  • Check active issues and PRs before submitting.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
gittensory-ui 3492a42 Commit Preview URL

Branch Preview URL
Jul 01 2026, 05:42 AM

@gittensory-orb gittensory-orb Bot added gittensor Gittensor contributor context gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 1.25x multiplier. labels Jul 1, 2026
@JSONbored JSONbored self-assigned this Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.62%. Comparing base (b68edef) to head (95d02f8).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1986   +/-   ##
=======================================
  Coverage   95.62%   95.62%           
=======================================
  Files         218      218           
  Lines       24317    24317           
  Branches     8819     8819           
=======================================
  Hits        23253    23253           
  Misses        436      436           
  Partials      628      628           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored merged commit 6f042a2 into main Jul 1, 2026
14 checks passed
@JSONbored JSONbored deleted the codex/postgres-transition-readiness branch July 1, 2026 06:11
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jul 1, 2026
JSONbored added a commit that referenced this pull request Jul 1, 2026
pg-queue.ts and sqlite-queue.ts call withOtelSpan for the admission-deferred
span (like server.ts does) but import only withReviewSpan, so tsc fails with
'Cannot find name withOtelSpan' on main — #1922 added the calls and #1986 landed
close behind, green separately but broken together. Add the missing import from
./otel. Behavior-preserving (the span was already intended); unblocks CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 1.25x multiplier. gittensor Gittensor contributor context size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant