Repository navigation
Description
Guiding rule for this phase: every capability ships as an open-source interface with a working zero-configuration default. Hosted infrastructure is a different implementation behind that same interface — never the only implementation, and never a different API.
The schema editor writes TypeScript into collectionsDir, and is disabled under NODE_ENV=production for a good reason: a deployed server's files are rebuilt from the repository on every deploy, so an edit made there would be discarded (packages/server/src/init.ts:1495).
That means creating or altering a collection against a running backend is not possible today. This is the phase that makes it possible — and it belongs in @rebasepro/server, so that one implementation serves an admin panel wherever it runs.
Work
- A schema service in
@rebasepro/serverthat takes a collection diff, generates a migration, applies it in a transaction, and re-derives row-level security through the existing hashed-name contract - Decide where a collection definition lives in production — the database, the bundle, or both. Recommendation: the database, with a mechanical export back to source so a repository-first workflow loses nothing
- Preserve the existing contracts: policy names are hashed and injected, derived identifiers are frozen once shipped, and row-level security is migration-applied
- Guard against the known traps — the collection-key allowlist silently dropping unrecognised keys, and a stale generated schema
- One code path, used by every admin surface
Guards to add alongside it
CI already proves that the backend never reaches React, using scripts/headless-guard/check.mjs and contracts/derived-names.txt. Two checks in the same shape keep this phase honest:
- Every published API has an open-source implementation. Everything in
api-surface/server.api.txtmust be reachable from a plain boot with no hosted infrastructure - Configuration parity. Hosted deployments configure the runtime through the same environment-derived names any deployment uses
Activity
fgatti675 commentedon Aug 22, 2026
Design written and up for review in #14 —
docs/live-schema-editing-plan-2026-08.md. No code yet, deliberately.What it decides
Making the database authoritative was the obvious answer and it's wrong.
serializeCollectionsalready defines a collection's serializable subset, andwithoutAdminBlockdrops theadminblock wholesale while the walk drops every function —callbacks,dynamicProps,conditions. What survives is slug, table, properties, relations,securityRules. A panel that can only edit that is a SQL editor with row-level security.So the repository stays the source of truth and the panel writes to it: commit first, then apply the DDL live. Immediate feedback, one source of truth, and no ceiling on what the panel can eventually edit.
Two things the doc pins down
The order is load-bearing. Apply-then-commit leaves a column in the database the repo doesn't describe — and the ensure path is strictly additive, so the next deploy neither removes it nor mentions it. Commit-then-apply fails into "repo ahead of database", the ordinary state between an edit and a deploy, which boot already reconciles.
The commit is the work. Not the collection file — also
backend/src/schema.generated.ts, a migration with a correctly mintedwhen(Drizzle skips out-of-order ones), and the regeneratedpolicies.sql/schema.sql/search.sql. Without all of it, a deploy against a fresh database produces something other than what was clicked.What blocks implementation
A project's
gitRepoUrlis metadata only. Deploys work by the CLI packaging a source tarball and uploading it, so nothing in the pipeline can write to that repository. A credential path — GitHub App or per-project token, stored in aSecretStore, with scope and rotation — has to exist before any of this can be enabled in production. That gates the ship date more than the DDL work does.Where to start
Stages 1 and 2 of the plan — classify a change as safe/unsafe, and generate the complete commit as a set of file contents — have no dependency on the credential work and carry most of the risk. Both are pure logic and fully testable: assert that a fresh database built from the generated commit matches the schema the change describes.
Needs an answer before stage 3 means anything
feat(schema): classify, generate and apply a live schema change
fgatti675 commentedon Aug 23, 2026
Shipped in #21 (merged) and #23 (open).
Working, verified against a real Postgres and a real repository, and driven in a browser end to end:
GET/POST /api/admin/schema/{status,plan,apply}— plan has no side effects, apply commits then applieswithheldConstraintsfor a change that applies and still leaves something unenforcedFixed along the way, each of which made the feature or the boot path report something untrue:
/applycould never succeed: the dirty-tree guard ran after the write it was guarding and refused every change on its own editrequiredleft the constraint — all three read as successadditiveStatementsplanned against an empty database, emittingADD COLUMN … NOT NULLthat a live table would rejectNot done, and the reason:
Rebase Cloud is not wired.
createGitHubRepository— the Git Data API backend — is written and tested, including against a real repository, but nothing constructs it, so a Cloud tenant gets the sameSCHEMA_EDITING_NO_REPOSITORYrefusal as any bundle. The docs say this.It is not a config gap. The AST editor rewrites the collection file on disk, and a bundle deployment has none, so the cloud path needs fetch-from-GitHub → edit → commit-back. That is the remaining design work and it is worth its own issue rather than being hidden inside this one.
Leaving this open for that reason.
fgatti675 commentedon Aug 23, 2026
Cloud is wired. Correcting my earlier comment, which said it was design work left to do — it was, and it is done.
The blocker was never authentication or the Git Data API; both worked and were tested. It was that the AST editor rewrites a collection file on disk, and a bundle deployment ships compiled output, so there was nothing for it to open.
rewriteRemoteCollectionreads the source from the repository, puts it in a scratch directory shaped the way the editor expects, runs the unchanged editor, and reads the result back. Reusing it rather than reimplementing matters: it is the part that preserves a collection file's imports, comments and formatting.Configured as
liveSchema.repository:Token for a single project committing to a repository its owner already has. App for a control plane holding one key across many projects — one App, an installation per project, no per-customer secret to rotate.
Verified against a real repository with no local source: creates a collection that did not exist, rewrites one that did, and the rewritten file still carries the comment that was above it.
Four things that decide whether it is safe, each covered by a test:
The deployment table in the docs now reads:
rebase devyes, self-host with the project mounted yes, self-host from a bundle yes withliveSchema.repository, Rebase Cloud yes with the same.fgatti675 commentedon Aug 25, 2026
Bookkeeping pass — four of the five items are done and the checkboxes now say so. Nothing new was built here tonight; this is the audit.
Done, across #21, #23 and #24: the schema service, the decision about where a collection definition lives in production (the repository, via
liveSchema.repository, with the AST editor reading source from GitHub and committing back), the existing contracts preserved, and one code path used by every admin surface."Guard against the known traps" is left unticked, but it is much closer to done than the item reads. Both named traps already have a guard; each has a gap beside it:
COLLECTION_KEY_LISTinpackages/server/src/collections/validate-config.tsis anas consttuple, andAssertNever<MissingCollectionKeys>fails the build if a key on any engine's config type is missing from it — so adding a key and forgetting the list is a compile error rather than a block that silently does nothing in someone's project. The gap is the sibling list:PROPERTY_KEYS_BY_TYPE, in the same file, is hand-maintained with no equivalent assertion. A new property option is still dropped in silence, which is the same failure one level down.rebase schema stale, whichrebase devruns with--fix. It is deliberately narrow — it answers "does this name a foreign key the way the previous rule did", not "is this what we would generate now", because the wide question reports every generator whitespace change as fatal and a check that cries wolf gets switched off. The gap is that nothing runs it in CI on this repository's ownapp/backend/src/schema.generated.ts, which is the file whose staleness broke every deploy once already.So: two small, well-shaped additions rather than two absent guards.
The two CI guards at the bottom of this issue are still open, and I want to flag a risk in one rather than write it badly. "Every published API has an open-source implementation" is the right property, but the cheap implementation — grepping
packages/server/srcfor hosted-only hostnames and control-plane variable names — needs an allowlist on day one (EMAIL_LOGO_URLalone points at a hosted asset), and an allowlisted grep is a gate that passes because it was taught to. A real version compares what a plain boot mounts against what the published surface promises. I would rather leave it open than land a check that reports green for the wrong reason.fgatti675 commentedon Aug 25, 2026
Both gaps from the comment above are closed, so "guard against the known traps" is now done — and each one turned out to be hiding something.
The property-key allowlist has the assertion its collection-level sibling had.
AssertNeverover every key of every member of thePropertyunion, withADMIN_PROPERTY_KEYSexcluded rather than listed — listing those here is its own known bug, because this allowlist is consulted first, so a listed key is accepted and the migration hint telling the author to move it intoadminis never reached.PROPERTY_KEYS_BY_TYPEbecomesas const satisfies Record<Property["type"], readonly string[]>for it, which makes the runtime lookup narrow too.Verified by mutation in both directions: dropping
"dimensions"from the vector list, and adding a new optional key toVectorProperty, each fail the build naming the key.CI now checks this repository's own generated schema (
pnpm check:schema-fresh, wired intoverify.ymlbeside the derived-names step, reading source so a stale dist cannot make it pass).Two things worth recording from writing it:
findMissingGeneratedNamesis what gives the gate content: does the module declare every table and every derived foreign-key column the collections name? That is the ordinary way a generated schema goes stale — a collection added, the generator not re-run — and it caught both mutations I threw at the real file.tableBlockmatched onlypgTable("x", and a collection withschema: "rebase"— the auth users collection, in every scaffold — is emitted asrebaseSchema.table("x", …). The block came back empty, an empty block reads as "a table the generator was not asked about", and so the rename check had never inspected a single table outsidepublic. Both forms match now, which also widens the checkrebase dev --fixruns on every developer's machine.Still open on this issue: the two CI guards at the bottom, with the caveat about the first one in the comment above.
Landed on
mainlocally and not pushed.fix(server): the property-key allowlist cannot drift from the types e…
feat(ci): gate the checked-in generated schema, and fix what the gate…