Skip to content

docs: design 001, database development flow - #677

Merged
ditadi merged 18 commits into
mainfrom
stack/database-dev-flow/00-design
Nov 25, 2026
Merged

ditadi merged 18 commits into
mainfrom
stack/database-dev-flow/00-design

Conversation

@ditadi

@ditadi ditadi commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🥞 Stacked PR (generated by Stack)

Use this link to review incremental changes.


What did you change, and why?

Design 001 (designs/001_DatabaseDevelopmentFlow.md) describes database branch ownership, committed migrations, and deployment. This revision updates the application development flow to match the named-operation design and experience fixes in #687–#692.

  • Replaces the current API description based on generated CRUD routes with authored, authorized operations. Table declarations alone expose no HTTP endpoint.
  • Documents the three route configurations: conventional database() discovery, routes: false, and an explicit custom registry. Covers committed registry/contracts, development reloads for shared schemas and policies, first/last route changes, and source-less production builds.
  • Defines omitted input as no parameters, with no placeholder object or inferred input. Explicit schemas determine caller input. Method-based output defaults remain unchanged; input shape never determines result cardinality.
  • Explains query/mutation hooks, typed skipToken, operation/session-scoped state, late responses, refresh after writes, and safe field feedback that preserves failed drafts.
  • Records the distinction between policy-resource snapshots and atomic business rules: transactional rechecks, constraints, database-generated IDs, and audit writes.
  • Updates the scaffold-to-deploy walkthrough, API changes, compatibility guidance and links to the owning operation PRs.

The migration decisions remain: opt-in startup migrations, per-migration transactions, bounded advisory/history locks, branch guards, ownership handoff, private-column preservation, deployed verification and offline history checks. The tooling remains internal at @databricks/appkit/beta/database-tooling, and revealing the hidden plugin/commands remains a separate change.

The document explicitly distinguishes the migration chain (#654–#678) from the operation chain (#687–#692). Combined startup/deployment validation is a release integration step; the separate chains' checks do not establish that integration. PR #677 targets main independently, and the implementation chain begins at #654 on main.

The linked Google Doc remains available for comments and edits. This PR updates the Markdown design copy.

Review round, 2026-11-09:

  • Closes three open questions with the decisions taken in review: the app's service principal owns the deploy branch's objects, with manual recovery, and a shared owner role is rejected for now (Q1); a branch init forks starts with no copied app rows, and --schema migrate opts in to keeping them (Q5); the stack ships on drizzle-kit 0.31's journal v7 (Q9). The remaining questions are renumbered.
  • Adds a runbook for a migration that fails on deploy every time, and separates how long a migration waits for a lock (lock_timeout) from how long it holds one (unbounded), with the procedure for a stuck start.
  • Narrows security claims: branch guards are not an authorization boundary, a baseline does not prove the security setup matches, verify --deployed proves the deployed source rather than applied migrations, clean leaves SP-owned tables in public and cascades into dependents, and init's drizzle-kit install runs lifecycle scripts. Names the gap of a local start against the deploy branch before appkit db init runs, and spells out the branch-naming rules.

Fix round for fjakobs's review of #677, 2026-11-15:

  • The design now matches the fixes for fjakobs's review. The operation sections are a short summary that links to design 002.
  • appkit db init decides from the branch itself instead of an .env marker. Migrate on start is an identity check: PGUSER must be set and equal DATABRICKS_CLIENT_ID.
  • The deploy section describes what Apps does per compute type, with the 300 s health check. The failure runbook repairs data and never edits a merged migration, so edited and a diverged history refuse a deploy start.
  • Ownership recovery is delete-role --reassign-owned-to after a full inventory, and long backfills run as a batched DML job between an expand and a contract migration.
  • Open questions answered with evidence: client_connection_check_interval is allowed, no permission is narrower than CAN MANAGE, schema-only branches are not in the public API, and the facts about Genie App Builder.
  • Introspect keeps the .private() the old schema.ts declares, and every other column it writes is public. The private-by-default and the foreign key refusal existed only for the AutoCRUD routes, which the operation stack removes.

Review round for MarioCadenas's review, 2026-11-25:

  • The introspect section names the subset of the catalog introspect writes, and the three ways it reports what it leaves out: a skip comment and a Skipped line, a warning with no comment, and Approximated information. CHECK and EXCLUDE constraints and indexes get a warning (feat(appkit): add appkit db introspect #670), and a branch rebuilt from the migrations lacks them while the deploy branch keeps them.

How do you know it works?

Documentation only. Checked the changed contracts against the current #687–#692 implementation and plugin guidelines; validated the syntax of all three TypeScript/TSX examples, balanced fenced blocks, operation PR references, and git diff --check. The branch's pre-existing Knip findings (one unused CLI file and three dev dependencies) also occur with the unchanged design; they are unrelated to this Markdown-only edit. No runtime or app files are included.

Review round, 2026-11-09: each fix has a failing-then-passing test in its PR, and every layer's appkit and shared tests ran against Postgres 14 after the sync. At the top of the stack, pnpm build, pnpm test (6502 passed, 1 skipped), pnpm -r typecheck, pnpm check, pnpm knip and pnpm docs:build pass.

Fix round for fjakobs's review, 2026-11-15: each fix has a failing-then-passing test in its PR, and every layer's database, plugin and CLI tests ran against Postgres 17 after the sync. A throwaway Lakebase fork confirmed that the developer role can write the service principal's rows but cannot alter its tables. At the top of the stack, pnpm test (6602 passed, 1 skipped), pnpm -r typecheck, pnpm build and pnpm docs:build pass, and oxlint and oxfmt are clean on every changed file.

Signed-off-by: ditadi <victordperd@gmail.com>
… 001

Signed-off-by: ditadi <victordperd@gmail.com>
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 45620681805 -R databricks/appkit -n appkit-template-0.104.1-pr.64df09f-stack-database-dev-flow-00-design-677 -D appkit-pr-677 \
  && unzip -o "appkit-pr-677/appkit-template-0.104.1-pr.64df09f-stack-database-dev-flow-00-design-677.zip" -d "appkit-pr-677" \
  && databricks apps init --template "appkit-pr-677"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi requested a review from a team as a code owner October 26, 2026 02:04
@ditadi
ditadi requested a review from MarioCadenas October 26, 2026 02:04
ditadi and others added 4 commits October 30, 2026 10:44
The design doc promised behavior the corrected stack does not ship. It
now describes what the code does:

- The tooling export is @databricks/appkit/beta/database-tooling, beta
  and internal to the AppKit CLI.
- migrate, introspect, clean and init hold config/database/.appkit-db.lock.
  init holds one lock for its whole run, and init --schema none, seed,
  verify and clean --delete-branch take none. The doc says how to
  recover a stale lock file.
- init --schema none hands off nothing, and schema public is never
  handed off.
- Values in variable-overrides.json count for the deploy boundary, and
  an unresolved branch or database reference refuses every write.
- Introspect keeps .private() on declared columns, writes new columns
  private, and refuses a schema.ts that does not load or a foreign key
  it does not declare.
- verify --deployed compares the committed migrations with the source
  snapshot of the active deployment, and fails when it cannot read it.
- Migrations log one line per run. There is no span and no metric.
- #675 keeps the plugin and appkit db hidden. A reveal is a later,
  separate change.

The appkit db check section stays as it is until #678 settles.

Signed-off-by: ditadi <victordperd@gmail.com>
…he stack code

Signed-off-by: ditadi <victordperd@gmail.com>
… and prompts

Apply the review of the design doc. The pooler refusal belongs to migrate on start, the migrator reconciles without the lock before it takes it, the deploy guard reads each target with and without variable-overrides.json, and init asks only for --schema clean and an ambiguous rename. The reveal also moves the database export into the generated barrel, check refuses a file that is not a drizzle-kit snapshot, and the project is not a databricks.yml variable.

Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi requested a review from fjakobs November 1, 2026 23:27
Signed-off-by: ditadi <victordperd@gmail.com>
… database dev flow design

Record the review decisions: the app's service principal owns the deploy
branch's objects with manual recovery, a new fork starts without copied app
rows, and the stack ships on drizzle-kit 0.31's journal. Renumber the open
questions and point the doc at them by number.

Add a runbook for a migration that fails on deploy, separate lock
acquisition from lock holding, and give the procedure for a stuck start.
Narrow the claims about clean, branch guards, baselines and
verify --deployed, and describe the behavior this fix round adds across
the stack.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi requested a review from atilafassina November 9, 2026 17:04

@fjakobs fjakobs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review (Claude Code). Treat each comment as a lead to check, not a verdict.

This PR only adds the design doc, so each inline comment marks a place where the doc contradicts itself, design 002 on main, or the code at the top of the two stacks: stack/database-stable/06-serve-operations for operations and stack/database-dev-flow/08-db-check for migrations. Comments marked "checked" are backed by reading that code; the four marked "from reasoning" come from how Postgres and the platform behave and weren't reproduced. Nothing was run: no CLI, no deploy.

Two comments point at code bugs, not just doc drift:

  • init.ts installs drizzle-kit only for the migrate and introspect starts, but clean is now the default for a new fork, so a new app's first appkit db migrate fails.
  • --schema none on a new fork skips the rebuild but still clears APPKIT_DB_NEW_BRANCH, so the copied production rows stay on the branch.

Smaller items without inline comments:

  • databricks apps run-local with exported M2M credentials migrates as an identity other than the app.
  • The journal-ownership rule as written would refuse the service principal's own journal in public.
  • The production registry claims ignore the Jiti source fallback.
  • The v0.87/v0.88 references are stale; main is at v0.91.
  • The "preserves existing beta startup behavior" heading is wrong: an upgrade without schemaName fails the startup check.
  • The operation sections repeat design 002 and have already drifted from it; linking to design 002 would avoid that.
  • The listNotes example has no limit, and getNote lets any caller read any note.
  • The pg_cancel_backend runbook doesn't name a role with the rights it needs.
  • The branch-limit message lists only your own branches, so a new developer has nothing to delete.

Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
@ditadi

ditadi commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

This is an AI-generated review (Claude Code). Treat each comment as a lead to check, not a verdict.

This PR only adds the design doc, so each inline comment marks a place where the doc contradicts itself, design 002 on main, or the code at the top of the two stacks: stack/database-stable/06-serve-operations for operations and stack/database-dev-flow/08-db-check for migrations. Comments marked "checked" are backed by reading that code; the four marked "from reasoning" come from how Postgres and the platform behave and weren't reproduced. Nothing was run: no CLI, no deploy.

Two comments point at code bugs, not just doc drift:

  • init.ts installs drizzle-kit only for the migrate and introspect starts, but clean is now the default for a new fork, so a new app's first appkit db migrate fails.
  • --schema none on a new fork skips the rebuild but still clears APPKIT_DB_NEW_BRANCH, so the copied production rows stay on the branch.

Smaller items without inline comments:

  • databricks apps run-local with exported M2M credentials migrates as an identity other than the app.
  • The journal-ownership rule as written would refuse the service principal's own journal in public.
  • The production registry claims ignore the Jiti source fallback.
  • The v0.87/v0.88 references are stale; main is at v0.91.
  • The "preserves existing beta startup behavior" heading is wrong: an upgrade without schemaName fails the startup check.
  • The operation sections repeat design 002 and have already drifted from it; linking to design 002 would avoid that.
  • The listNotes example has no limit, and getNote lets any caller read any note.
  • The pg_cancel_backend runbook doesn't name a role with the rights it needs.
  • The branch-limit message lists only your own branches, so a new developer has nothing to delete.

Thanks for the review. Replies to the items in the summary:

  • "databricks apps run-local with exported M2M credentials migrates as an identity other than the app." Confirmed: run-local forwards the CLI's own M2M credentials and takes the flag from app.yaml. The L307 rule covers it, since a local PGUSER is the developer, not the app's client id.
  • "The journal-ownership rule as written would refuse the service principal's own journal in public." The code was right and the doc was stale. The migrator trusts a table owned by a role it has, or by the schema owner (apply.ts:424), so the service principal's journal in public passes. Doc fix in docs: design 001, database development flow #677. The security section will also say that any DATABRICKS_SUPERUSER role on the deploy branch can write journal rows (measured on a model of the roles).
  • "The production registry claims ignore the Jiti source fallback." Confirmed (load-routes.ts:60-62). It goes away with the link to design 002.
  • "The v0.87/v0.88 references are stale." Agreed. I'll drop them; main has moved past 0.91 since.
  • "The 'preserves existing beta startup behavior' heading is wrong." Right, an upgrade without schemaName fails the startup check. The section will be named for what it is: the upgrade path for apps without schemaName.
  • "The operation sections repeat design 002 and have already drifted from it." Agreed. They become a summary and a link.
  • "The listNotes example has no limit, and getNote lets any caller read any note." Agreed. Any example that stays uses .limit() and a per-note policy, as in design 002.
  • "The pg_cancel_backend runbook doesn't name a role with the rights it needs." Measured on Lakebase: databricks_superuser inherits pg_signal_backend, so a role with the DATABRICKS_SUPERUSER membership on the deploy branch can cancel or end the migrating session, because the service principal is not a superuser. Someone with CAN USE on the project can create that role. The runbook will name it, with a compute restart (CAN MANAGE) as the fallback.
  • "The branch-limit message lists only your own branches, so a new developer has nothing to delete." The code already handles it: when none of the project's branches are yours, it says to ask a project owner (init.ts:247). I'll fix the doc.

ditadi and others added 3 commits November 15, 2026 20:08
Replace the operation sections with a summary that links to design 002,
and describe the behavior the stack has after this fix round: init
decides from the branch instead of the APPKIT_DB_NEW_BRANCH marker,
forks the default target's branch and installs drizzle-kit for every
start except none; migrate on start runs only as the app's own service
principal and refuses dev- or session-shaped branches; a deploy start
refuses edited migrations and diverged histories; the failure runbook
repairs data with a DATABRICKS_SUPERUSER role instead of editing the
migration; and the deploy section states what Apps does with health
checks, classic and no-downtime compute, crashes and scale to zero.

Also drop the release numbers, rename the upgrade section, correct the
journal trust rule and the ownership recovery, name the role for a stuck
start, and record the answered open questions.

Signed-off-by: ditadi <victordperd@gmail.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…ll ownership inventory in design 001

Migrate on start now requires PGUSER to be set and equal to
DATABRICKS_CLIENT_ID, so the doc states it as an identity check rather
than deployment detection, and names the gap before init writes PGUSER.

The fork-copy rule adds a branch the same init run created, the tag
written only into a journal the migrator trusts with a warning when it
cannot be, migrate, introspect and seed refusing an untouched copy, and
--schema clean after keeping copied rows. The remaining windows are
listed as they stand.

The ownership recovery takes the hand-off's full inventory across
databases before delete-role, and says the delete drops the role's
memberships and grants. Clean lists what CASCADE drops before it asks;
init's rebuild reports it after.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…foreign key refusal

Introspect keeps the old schema.ts's .private() and writes every other
column and foreign key as the catalog has it.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi requested a review from fjakobs November 17, 2026 00:26

@MarioCadenas MarioCadenas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One gap inline. Reviewed at fde70db.

Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
ditadi and others added 2 commits November 20, 2026 09:52
Introspect leaves out what the builder cannot express, such as generated
columns, unsupported types and defaults, identity columns other than the
primary key, and composite, cross-schema, self-referencing or cycle-closing
foreign keys. The design said every column and foreign key was written as the
catalog has it.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
A foreign key on a column introspect cannot write goes with that column,
and the column's skip comment covers both.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi requested a review from MarioCadenas November 20, 2026 13:41
Comment thread designs/001_DatabaseDevelopmentFlow.md Resolved
CHECK and EXCLUDE constraints and indexes get a warning, not a skip
comment, and a branch rebuilt from the migrations lacks them.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi requested a review from MarioCadenas November 25, 2026 12:22
@ditadi
ditadi enabled auto-merge (squash) November 25, 2026 12:54
@ditadi
ditadi merged commit 1caa36a into main Nov 25, 2026
11 checks passed
@ditadi
ditadi deleted the stack/database-dev-flow/00-design branch November 25, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants