Repository navigation
Conversation
This was referenced Oct 16, 2026
ditadi
force-pushed
the
stack/database-dev-flow/04-db-introspect
branch
from
October 19, 2026 15:02
a2522e5 to
c3e1172
Compare
ditadi
force-pushed
the
stack/database-dev-flow/05-db-init
branch
from
October 19, 2026 20:35
960b211 to
c56de21
Compare
`appkit db init` gives a checkout its own Lakebase branch, forked from the project's default branch: your dev branch, or with --session a branch for this checkout that expires after 7 days (or --ttl). It asks nothing. It refuses the default branch, protected branches and branches databricks.yml deploys to before any change, and when the project is at its branch limit it lists your branches to delete. It makes sure the branch has a read-write endpoint that suspends after 5 idle minutes and a Postgres role for you, points .env at it with an atomic 0600 write, hands you the app schema when the fork copied it owned by another Lakebase role, installs drizzle-kit when the app lacks it, then starts the schema by migrating, introspecting or cleaning. `appkit db clean` drops the app schema (only your objects in public) and lists what outside it went along; --delete-branch deletes this checkout's session branch instead. `appkit db seed` runs config/database/seed.sql in one transaction with the app schema on the search_path. Both run only on a branch created for you or this checkout. Signed-off-by: ditadi <victordperd@gmail.com>
ditadi
force-pushed
the
stack/database-dev-flow/05-db-init
branch
from
October 20, 2026 12:22
c56de21 to
98ef27b
Compare
ditadi
force-pushed
the
stack/database-dev-flow/04-db-introspect
branch
from
October 20, 2026 12:23
c3e1172 to
a45e7df
Compare
Contributor
🤖 AppKit PR bot🔬 Run evalsStart an eval for this PR from the evals-monitor app: Go to Evals Monitor → 📦 Try this PR's app templateScaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh run download 45822394412 -R databricks/appkit -n appkit-template-0.105.0-pr.8cabeb5-stack-database-dev-flow-05-db-init-672 -D appkit-pr-672 \
&& unzip -o "appkit-pr-672/appkit-template-0.105.0-pr.8cabeb5-stack-database-dev-flow-05-db-init-672.zip" -d "appkit-pr-672" \
&& databricks apps init --template "appkit-pr-672"The template pins |
This was referenced Oct 20, 2026
Draft
Contributor
📦 Bundle size reportCompared against
|
| dist | raw | gzip |
|---|---|---|
| JS (runtime) | 1.6 MB (+388 B) | 576 KB (+159 B) |
| Type declarations | 498 KB (+64 B) | 181 KB (+21 B) |
| Source maps | 3.1 MB (+1.2 KB) | 1.0 MB (+436 B) |
| Other | 11 KB | 3.7 KB |
| Total | 5.2 MB (+1.6 KB) | 1.8 MB (+616 B) |
Per-entry composition (own code — deps external (as shipped))
| Entry | Initial (gz) | Lazy (gz) | Total (gz) | node_modules (min) | Own code (min) |
|---|---|---|---|---|---|
. |
118 KB (+22 B) | 2.4 KB | 121 KB (+22 B) | external | 378 KB (+30 B) |
./beta |
127 KB (+18 B) | 4.6 KB (+25 B) | 131 KB (+43 B) | external | 381 KB (+63 B) |
./beta/database-tooling |
56 KB (+60 B) | 0 B | 56 KB (+60 B) | external | 167 KB (+174 B) |
./testing |
47 KB (-2 B) | 38 KB (+21 B) | 85 KB (+19 B) | external | 246 KB (+30 B) |
./tsdown |
630 B | 0 B | 630 B | external | 1.0 KB |
./type-generator |
31 KB (+25 B) | 0 B | 31 KB (+25 B) | external | 89 KB (+30 B) |
Chunks:
| Entry | Chunk | Load | Size (gz) |
|---|---|---|---|
. |
index.js |
initial | 114 KB |
. |
utils.js |
initial | 4.6 KB |
. |
remote-tunnel-manager.js |
lazy | 2.4 KB |
./beta |
beta.js |
initial | 101 KB |
./beta |
stream-manager.js |
initial | 5.9 KB |
./beta |
define-schema.js |
initial | 5.9 KB |
./beta |
service-context.js |
initial | 4.3 KB |
./beta |
modular.js |
initial | 3.6 KB |
./beta |
databricks.js |
initial | 3.3 KB |
./beta |
wide-event-emitter.js |
initial | 2.8 KB |
./beta |
client.js |
initial | 645 B |
./beta |
index.js |
initial | 20 B |
./beta |
index.js |
lazy | 4.1 KB |
./beta |
supervisor-api.js |
lazy | 201 B |
./beta |
databricks.js |
lazy | 188 B |
./beta |
index.js |
lazy | 124 B |
./beta/database-tooling |
index.js |
initial | 56 KB |
./testing |
manifest.js |
initial | 33 KB |
./testing |
index.js |
initial | 10 KB |
./testing |
wide-event-emitter.js |
initial | 2.9 KB |
./testing |
index.js |
lazy | 34 KB |
./testing |
remote-tunnel-manager.js |
lazy | 2.4 KB |
./testing |
utils.js |
lazy | 1.8 KB |
./tsdown |
index.js |
initial | 630 B |
./type-generator |
index.js |
initial | 31 KB |
@databricks/appkit-ui
npm tarball (packed): 393 KB — gzipped download (dist + bin; excludes release-only docs/NOTICE).
| dist | raw | gzip |
|---|---|---|
| JS (runtime) | 430 KB | 146 KB |
| Type declarations | 250 KB | 93 KB |
| Source maps | 837 KB | 281 KB |
| CSS | 16 KB | 3.2 KB |
| Total | 1.5 MB | 522 KB |
Per-entry composition (consumer bundle — deps bundled, peerDeps external)
| Entry | Initial (gz) | Lazy (gz) | Total (gz) | node_modules (min) | Own code (min) |
|---|---|---|---|---|---|
./js |
5.3 KB | 49 KB | 55 KB | 208 KB | 14 KB |
./js/beta |
2.4 KB | 0 B | 2.4 KB | 0 B | 5.3 KB |
./react |
441 KB | 49 KB | 489 KB | 1.4 MB | 180 KB |
./react/beta |
13 KB | 0 B | 13 KB | 25 KB | 13 KB |
Chunks:
| Entry | Chunk | Load | Size (gz) |
|---|---|---|---|
./js |
index.js |
initial | 5.2 KB |
./js |
chunk |
initial | 120 B |
./js |
apache-arrow |
lazy | 49 KB |
./js/beta |
beta.js |
initial | 2.4 KB |
./react |
index.js |
initial | 439 KB |
./react |
tslib |
initial | 2.1 KB |
./react |
apache-arrow |
lazy | 49 KB |
./react/beta |
beta.js |
initial | 13 KB |
Signed-off-by: ditadi <victordperd@gmail.com> # Conflicts: # packages/appkit/src/database/tooling/migrate.ts # packages/appkit/src/database/tooling/naming.ts # packages/appkit/src/database/tooling/tests/guard.test.ts # packages/appkit/src/database/tooling/tests/naming.test.ts # packages/appkit/src/database/tooling/tests/targets.test.ts
init still checked its planned branch against the readDeployBranches list that the deploy boundary replaced. It now asks deployRefusal, like every other guard, so a binding the checkout's files cannot resolve refuses init before any API call or .env write. readDeployTarget reads the default target from the same bundle model: its first resolved app binding, else its postgres_branch and postgres_database variables. The shared CLI test mocks the beta tooling path. Signed-off-by: ditadi <victordperd@gmail.com>
Signed-off-by: ditadi <victordperd@gmail.com>
clean drops the branch's migration journal, and init runs clean, migrate or introspect after its own checks, so another appkit db command could run in between. runClean now holds the checkout's history lock, and init holds one lock for its whole run and hands it to cleanHolding, migrateHolding and introspectHolding. init --schema none changes no history, so it takes no lock and creates no config/database. Signed-off-by: ditadi <victordperd@gmail.com>
init --schema none still handed the app schema to the developer, which deletes the branch copy of the role that owns it, in apps that may have no database schema contract at all. It now leaves the schema and its owner as the fork copied them. Schema public is never handed off either: it belongs to the database (pg_database_owner on PostgreSQL 15 and later, the bootstrap superuser before), so AppKit never deletes its owner or reassigns its objects. Signed-off-by: ditadi <victordperd@gmail.com>
Regenerated with pnpm clean && pnpm build && pnpm size:baseline. Against the previous baseline the @databricks/appkit packed tarball grows from 1364290 to 1448119 bytes (+83829, +6.14%), over the 5% budget. The growth is the CLI-only @databricks/appkit/beta/database-tooling entry (45 KB gzipped, from 28 KB) with the introspect fixes and init, clean and history lock code it ships. @databricks/appkit-ui is unchanged at 406741 bytes. Signed-off-by: ditadi <victordperd@gmail.com>
The re-run test ran with --schema none, which skips the hand-off, so no test reached the check that keeps init from deleting your own role. It now runs the default migrate start and asserts that the owner query ran for schema app and no role was deleted. Signed-off-by: ditadi <victordperd@gmail.com>
init --schema none hands off no schema and starts none, but it still loaded schema.ts for the schema name, so a half-edited file stopped a branch-only init. It now loads schema.ts only when the hand-off and the start use it. Signed-off-by: ditadi <victordperd@gmail.com>
…e lock withHistoryLock creates config/database for its lock file, and init and clean checked for schema.ts only after taking it, so a refused init or clean left an empty config/database behind. Both now check first, as runMigrate does. Signed-off-by: ditadi <victordperd@gmail.com>
dotenv 16.6.1 reads `KEY: value` (a colon followed by whitespace) as an entry, and a later entry wins. updateEnvFile's parser only knows `KEY=`, so a later `PGHOST: old` outlives the rewrite and dotenv reads the old host. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
updateEnvFile only recognized `KEY=`. dotenv 16.6.1 also reads `KEY: value` when whitespace follows the colon, and its last entry wins, so a later `PGHOST: old` outlived the rewrite. The parser now treats that form as an entry too and writes it back as `KEY=`. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…nv through updateEnvFile writes `..env.<pid>.<hex>.tmp` and renames it over .env. A run killed between the two leaves the file, which holds the .env contents, and nothing ignored it. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
init kept any existing PGSSLMODE. The Lakebase pool maps prefer to rejectUnauthorized: false, disable to no TLS, and rejects every other value, so only require gives a checked TLS connection. init now writes require over anything else and says what it replaced. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…spects, then rebuilds Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…specting first The design rebuilds a copy from the baseline introspect writes when there is no schema.ts. A tagged copy now takes that path too instead of refusing. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…thout "keeps them" Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…s the copied rows After the rebuild the rows are gone, so the flag cannot keep them on this branch. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…mes init Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…ing init Another role owns that schema, so the drop failed with Postgres's raw "must be owner". clean and its preview now refuse first and say that init takes the copy over and rebuilds it. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…d of replaced Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
.env read an invalid id as unset, so init generated a new one and overwrote the hand-set value. Every command now refuses it with naming.ts's message. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
A failed session run also names --session in its rerun advice. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…me --session in its advice A --session run writes APPKIT_DB_SESSION before the fork and points .env at the branch last. When it stopped in between, the next plain init went to the dev branch. It now picks the session when .env does not point at your dev branch and the session's branch exists, and a session run's rerun advice says `appkit db init --session`. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
… and its win over .env Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…and let it win over .env init read the database databricks.yml binds only after the fork, so a missing one left a new branch with copied rows behind, and a PGDATABASE already in .env skipped the check. The create path now reads the binding on the source branch before createBranch. A reused branch is still checked after. The bound database replaces a different PGDATABASE, and init says so. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…e other databases first The blocker count mixed privileges in with what the role owns, so the failure message called grants blocking objects. What the owner holds is now split: objects in other databases or shared ones, and privileges, each reported apart. Objects in another database of the branch, which the reassign cannot reach, are refused before the delete. An extension the owner has stays a refusal that names it and the manual delete-role command; a test pins it. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…utput Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…rint A quoted Postgres name can hold control characters that rewrite the terminal. The labels clean and the hand-off read, the owners their refusals name, and the copy's owner in migrate, introspect and seed refusals now go through introspect's shown(), so the CLI's output prints them escaped too. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…left .env short of Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…tabase-dev-flow/05-db-init # Conflicts: # packages/appkit/src/database/tooling/migrate.ts # packages/appkit/src/database/tooling/naming.ts # packages/appkit/src/database/tooling/tests/naming.test.ts Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
Layer 03 made the databricks.yml reader take the command's environment, so a BUNDLE_VAR_ value counts the way a deploy from the shell counts it. init passed no environment to readDeployBoundary or to readDeployTarget, the reader of the branch it forks and the database it binds. Both now get ctx.env, and readDeployTarget applies the BUNDLE_VAR_ view ahead of variable-overrides.json. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…tabase-dev-flow/05-db-init # Conflicts: # bundle-size-baseline.json # packages/appkit/src/database/tooling/migrate.ts # packages/appkit/src/database/tooling/tests/migrate.test.ts Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
The 03 merge removed the CLI option of the runtime loader, so init, clean and seed now load schema.ts through loadDatabaseSchema. The init test reports carry the operation types file migrate and introspect now return. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…anges Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…tabase-dev-flow/05-db-init Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…tabase-dev-flow/05-db-init # Conflicts: # packages/appkit/src/database/tooling/migrate.ts Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…d seed loadDatabaseSchema now keeps the import error only for a caller that asks, so the commands that read the app schema from schema.ts ask for it. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
The warning about the bound database, the step that points .env at the branch, the hand-off messages and the report the CLI prints carried the Postgres database name raw, so a name with a control character reached the terminal. Pass them through shown(); .env and the connections keep the raw name. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
…ed tests Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
CI sets CI, so picocolors colors the warning marker and the assertion on "! Could not mark ..." failed there while it passed in a local shell. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: ditadi <victordperd@gmail.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🥞 Stacked PR (generated by Stack)
Use this link to review incremental changes.
Stacked on #670. The design is #677.
What did you change, and why?
Each checkout needs its own Lakebase branch for local development, set up without prompts so an agent or a script can run it. This PR adds
appkit db init,appkit db cleanandappkit db seed.appkit db inituses yourdev-<you>-<hash>branch, or with--sessionasession-<user hash>-<id>branch that expires after 7 days (--ttlchanges that). It forks a new branch from the branch the defaultdatabricks.ymltarget binds, or from the project's default branch when that target does not resolve, and says which. It makes sure the branch has a read-write endpoint that suspends after 5 idle minutes and your Postgres role withDATABRICKS_SUPERUSER, and points.envat the branch. It hands you the app schema when the fork copied it owned by another Lakebase role, such as the app's service principal.Then init starts the schema, which it decides from the branch (see the fix round below).
--schema migrate,introspect,cleanandnonechoose a start explicitly. init installs the pinned drizzle-kit for every start exceptnonewhen the app lacks it. init refuses the project's default branch, protected branches and any branch the deploy boundary covers, before it changes anything.cleandrops the app schema, migration journal included, in one transaction. Onpublicit drops only what your role owns.clean --delete-branchdeletes this checkout's session branch.seedrunsconfig/database/seed.sqlin one transaction.cleanandseedrun only on your dev or session branch..envis written with mode 0600 through a temporary file, and a symlinked.envis refused.This revision changes these behaviors:
databricks.ymlreference the checkout's files cannot resolve refuses init before any API call or.envwrite.cleanholds the lock too.clean, and init with--schema migrateor--schema clean, refuse a missingschema.tsbefore taking the lock, so a refused run leaves no emptyconfig/database.init --schema nonereads noschema.ts, takes no lock, and hands off nothing. The schema and its owner stay as the fork copied them.publicis never handed off. It belongs to the database, so AppKit never deletes its owner or reassigns its objects.bundle-size-baseline.jsonis regenerated. The packed tarball grows from 1,364,290 to 1,448,119 bytes (+6.14%), over the 5% budget, because./beta/database-toolinggrows from 28 KB to 45 KB gzipped.Session branch names carry a hash of your user name (#666). init treats
.envas this checkout's session branch only when the name matches your hash, so a.envcopied from another developer never leads init to their branch.appkit dbstays hidden fromappkit --help.Review round, 2026-11-09:
initforks starts without the rows the fork copied:cleanwithschema.ts, orintrospectand then a rebuild from the baseline.--schema migrateor--schema introspectkeeps them; a reused branch is migrated as before. Inpublic, the report lists what other roles own and keep.initrefuses a databasedatabricks.ymlbinds that the fork lacks, reads the deploy target throughvariable-overrides.json, resumes an interrupted session rotation, reconciles with a concurrent run that created the endpoint or role first, writesPGSSLMODE=requireover weaker values, and hands off and introspects the schemaschema.tsdeclares.cleanpreviews the full CASCADE closure; drizzle-kit's installer uses shared's package-manager detection;.envrewrites recogniseKEY: valueand go throughtooling/files.ts; the.envtemp file is git-ignored in the template.Fix round for fjakobs's review of #677, 2026-11-15:
APPKIT_DB_NEW_BRANCHmarker is gone (L236, L690). init reads the branch. An app schema still owned by another role is an untouched copy, and init rebuilds it. Before the hand-off, init tags the copied journal with one row, only in a journal the migrator trusts, so a rerun from any checkout finishes an interrupted rebuild. A branch this run created is rebuilt even when you already owned the source schema. When the copy cannot be tagged, init warns first.--schema nonetouches nothing, so the next plain init still rebuilds a copy. Explicit--schema migrateorintrospectkeep the rows and say that--schema cleanremoves them.migrate,introspectandseedrefuse an untouched or tagged copy.none(L541), and forks the branch the defaultdatabricks.ymltarget binds when it resolves (L633). The hand-off error stops suggestingALTER ... OWNER TO.How do you know it works?
init.test.tsrunsrunInitagainst an in-memory Lakebase. It covers branch creation and reuse, session TTLs, a 403, a 409, the branch limit, and deploy-target and unresolved refusals before any API call. It also covers the hand-off and its failures,--schema none,public, and one lock across init's clean and migrate.env-file.test.ts,clean-seed.test.tsand the CLI'sinit-clean-seed.test.tscover the.envwriter, the clean and seed refusals, the confirmations and the exit codes.clean.pg.test.tsandhand-off.pg.test.tsrun against Postgres. They check what CASCADE takes outside the app schema, apublicclean, and the objects and grants that block a role delete.dbtests passed against a local PostgreSQL 14, typecheck passed, and a clean build matched the new size baseline. The full vitest suite passed at an earlier revision of this PR and at the top of the stack (feat(appkit): add appkit db check #678). The packed tarballs export the same root and./betanames as main, and./beta/database-toolingadds only init, clean, seed and session-branch deletion. CI runs the full suite on this PR.publicon a real Lakebase branch was not observed.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 knipandpnpm docs:buildpass.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 buildandpnpm docs:buildpass, and oxlint and oxfmt are clean on every changed file.