mirror of
https://github.com/hanzoai/sql.git
synced 2026-11-15 19:38:30 +00:00
Replaces the shared multi-tenant Postgres (ghcr.io/hanzoai/sql:18) with the
per-tenant, SQLite-backed, provision-on-demand model — the relational analog of
docdb (FerretDB-on-SQLite). Builds under sql/managed/, never touches the
Postgres source tree.
Crux decided by real prisma output (evidence/):
- Option A (pglite pg-wire): the UNMODIFIED dataroom pg schema (62 tables, 18
enums, 11 array cols, @db.* native types) `prisma db push`es and runs a live
enum+text[] CRUD roundtrip → the pg-wire escape hatch for un-rewritable
schemas / external ManagedDatabase tenants.
- Option B/C (SQLite dialect): the same schema is rejected at Prisma validation
(P1012, 11 scalar-list + 6 native-type errors) before any backend — no
pg-wire-over-SQLite proxy can fix it. postlite rejected.
- Primary path stays file:SQLite (esign/Service.persistence): rewrite the schema
(arrays→JSON String) + one-time data ETL. esign already runs this in prod.
Deliverables:
- LLM.md: product spec — existing operator model (Service.persistence, SQL/
ManagedDatabase datastore Kinds), per-tenant layout, provisioning, DNS,
DATABASE_URL handoff (KMSSecret→env, mirrors docdb MONGO_URI), image
ghcr.io/hanzoai/sql-managed (semver only), blockers (DatastoreSpec fsGroup gap,
multi-tenant router, inert credentialsSecret).
- deploy/sql.yaml (path A, SQL Kind, sql-managed image) +
service-persistence.example.yaml (path C, esign pattern).
- etl/enum-array-parser.patch: fixes a real data-loss bug in esign's
backfill-pg-to-sqlite.ts — node-pg returns enum arrays (Role[]) as the raw
string {ADMIN,USER}, aborting the load (User.roles is set for every user).
Registers node-pg's text-array parser for enum-array OIDs. Validated pg→SQLite
on 4554 synthetic rows: full parity + byte-exact type fidelity + esign Prisma
read-back (evidence/etl-pg-to-sqlite-validation.log).
- pgwire/: tested pglite pg-wire prototype (server.mjs, provision.mjs, Dockerfile
FROM ghcr.io/hanzoai/nodejs:v24.18.0) — the Option-A follow-up.
Co-authored-by: Hanzo Dev <[email protected]>
53 lines
2.2 KiB
YAML
53 lines
2.2 KiB
YAML
# Hanzo SQL — PRIMARY path: a Prisma app on file:SQLite via the `Service` Kind's
|
|
# `persistence` block. This is how our own services get durable per-tenant SQL
|
|
# with zero pg-wire hop. It is the pattern the `esign` (Documenso) Service already
|
|
# runs in production (DATABASE_URL=file:/data/sign.db, prisma sqlite provider).
|
|
#
|
|
# `persistence` auto-wires: a durable `app-db` volume, a `replicate-restore`
|
|
# initContainer, and a `hanzoai/replicate` sidecar that streams the SQLite WAL to
|
|
# SeaweedFS/S3, age-encrypted client-side. `dir_mode` fans a single volume into
|
|
# many .db files (per-tenant / per-org) — the "one PVC, many files" layout.
|
|
#
|
|
# A consuming Prisma app takes TWO code changes to adopt this (see ../LLM.md):
|
|
# 1. datasource provider "postgresql" -> "sqlite"; url env("DATABASE_URL")=file:...
|
|
# 2. drop scalar arrays (-> String holding JSON) and pg @db.* native types.
|
|
# Existing data is moved once with the pg->SQLite ETL (see ../etl/).
|
|
apiVersion: hanzo.ai/v1
|
|
kind: Service
|
|
metadata:
|
|
name: esign
|
|
namespace: hanzo
|
|
spec:
|
|
image:
|
|
repository: ghcr.io/hanzoai/esign
|
|
tag: "2.7.1" # semver only
|
|
pullPolicy: IfNotPresent
|
|
replicas: 1 # single-writer SQLite file; scale reads via replicas of the WAL, not >1 writer
|
|
env:
|
|
- name: DATABASE_URL
|
|
value: file:/data/sign.db
|
|
# Run the Prisma migration before the app boots; the app opens an already-migrated file.
|
|
initContainers:
|
|
- name: migrate
|
|
command: ["npx", "prisma", "migrate", "deploy"]
|
|
ports:
|
|
- name: http
|
|
containerPort: 3000
|
|
servicePort: 80
|
|
fsGroup: 65532 # DO block PVC is root-owned; nonroot app needs this to write /data
|
|
# `persistence` = the operator's SQLite-durability block (PersistenceSpec).
|
|
persistence:
|
|
mountPath: /data
|
|
size: 10Gi
|
|
storageClassName: do-block-storage
|
|
# WAL -> S3, age-encrypted (backup + point-in-time restore on restart).
|
|
bucket: esign-db
|
|
s3Path: esign/sign
|
|
s3CredentialsSecret: s3-credentials
|
|
ageSecret: base-replicate-age
|
|
# dirMode fans the volume into many per-tenant .db files instead of one.
|
|
# dirMode: true
|
|
imagePullSecrets:
|
|
- name: ghcr-secret
|
|
partOf: apps
|