Skip to content

feat(appkit): offer the database plugin in databricks apps init - #675

Draft
ditadi wants to merge 1 commit into
stack/database-dev-flow/06-db-verifyfrom
stack/database-dev-flow/07-apps-init
Draft

ditadi wants to merge 1 commit into
stack/database-dev-flow/06-db-verifyfrom
stack/database-dev-flow/07-apps-init

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.


Stacked on #674.

Summary

Offers the DatabasePlugin in databricks apps init, and documents the development flow end to end. Past npx appkit db init, a scaffolded app with the plugin needs no manual step to develop and deploy:

  • appkit db init points .env at a Lakebase branch of your own and sets up its schema. It asks nothing.
  • appkit db migrate writes and applies migrations as you change config/database/schema.ts.
  • app.yaml sets APPKIT_DB_MIGRATE_ON_START=true, so the deployed app applies the committed migrations on start.
  • appkit db verify checks your branch, and with --deployed -t <target> the deployed app.
  • One owner per branch: the app's service principal owns the schema on the deploy branch.

Details

  • The plugin manifest is no longer hidden, and neither are the appkit db commands in the CLI. The database export moves from beta.ts to the generated beta exports.
  • Template changes:
    • app.yaml.tmpl sets APPKIT_DB_MIGRATE_ON_START=true when the plugin is selected. The CLI manifest renders only valueFrom entries, so the literal lives in the template. The block sits next to the .appEnv block, not inside it, because the template smoke test strips conditionals with regexes that do not nest.
    • server/server.ts exits 1 when startup fails, so a failed migration stops the app instead of leaving it up without routes.
    • config/database/schema.ts uses schema app.
    • appkit.plugins.json gets the database entry, with the postgres binding for branch and database.
    • README.md.tmpl gets a development-workflow section, a verify --deployed step after the production deploy, and config/database/ in the project structure.
    • _gitignore skips config/database/*.bak, the previous schema.ts that introspect keeps.
  • drizzle-kit is not a template dependency. appkit db init (feat(appkit): add appkit db init, clean and seed #672) installs the version AppKit pins when the app lacks it. Apps without the plugin don't get it, and the template lockfiles are unchanged.
  • appkit db verify warns when .env points at a branch appkit db init did not set up for you. Until databricks apps init runs db init itself, the scaffolded .env names the branch picked in its prompts, usually the deploy branch. This is a warning, not a finding, and the docs say to run npx appkit db init once after scaffolding. So this PR does not wait for that CLI change.
  • The owner-mismatch error covers an app recreated with a new service principal. The old one still owns the schema, and someone with CAN MANAGE on the Lakebase project runs databricks postgres delete-role <old role> --reassign-owned-to <new role>.
  • Plugin docs (database.md):
    • Set up your branch: no prompts, --dev, --session, --ttl, --schema and --yes, and the drizzle-kit install.
    • A caution: a new branch copies the default branch's rows, production data included. The developer role is a member of DATABRICKS_SUPERUSER, and CAN MANAGE on the project also allows deleting the deploy branch.
    • Migrations on deploy: the flag, one transaction per migration, the 5 s table-lock timeout with 3 tries, the 5 min migration-lock wait, and no migration on start against a developer branch.
    • Changing tables in use (two-step changes), existing apps, rolling back, the recreated-app recovery, verifying the deployed app, and CI.
  • Lakebase docs (lakebase.md): local development starts on a dev branch with npx appkit db init --schema none. Developing against the deployed branch is a subsection.

Tests

  • The verify tests cover the new warning: on the project's default branch, verify reports why the branch is not yours and still passes, and the CLI prints the warning.
  • The ownership test asserts the delete-role --reassign-owned-to hint.
  • I rendered app.yaml.tmpl with Go text/template for a database app, an analytics-only app and an app with no resources. Each output parses as YAML, and only the database app gets the flag. I rendered README.md.tmpl with and without the plugin.
  • I checked the doc claims against the code of feat(appkit): apply committed database migrations on deploy start #654–feat(appkit): add appkit db verify #674: the init flags and branch choice, the migrate, clean, seed and introspect refusals, the lock limits, the warning on start for migrations the code does not commit, and verify --deployed.
  • tools/check-template-deps.ts passes.
  • Build, typecheck, lint and format, knip, generate:types and sync:template (no diff), and the docs build pass. The docs build's one broken-anchor warning is in custom-plugins, which this PR does not touch.
  • The database tests pass against a local Postgres 14: 869 in appkit and 630 in the shared CLI.

@ditadi
ditadi force-pushed the stack/database-dev-flow/06-db-verify branch from 6dd2fd4 to 42df642 Compare October 20, 2026 08:44
@ditadi
ditadi force-pushed the stack/database-dev-flow/07-apps-init branch from 07b1748 to 7db9fa1 Compare October 20, 2026 09:20
The DatabasePlugin is no longer hidden from `databricks apps init`. The
template ships config/database/schema.ts in the app schema, and app.yaml
sets APPKIT_DB_MIGRATE_ON_START=true for apps that select the plugin, so
the deployed app applies its committed migrations on start. The CLI
manifest renders only valueFrom entries, so the literal lives in
app.yaml.tmpl.

drizzle-kit stays out of the template and its lockfiles: `appkit db init`
installs the pinned version when the app lacks it, so apps without the
plugin do not get it.

`appkit db verify` warns when .env points at a branch `appkit db init` did
not set up for you, such as the deploy branch the scaffolded .env names
until `db init` runs. The template's server exits 1 when startup fails, so
a failed migration stops the app instead of leaving it up without its
routes. The owner-mismatch error names the recovery for an app recreated
with a new service principal: `databricks postgres delete-role
--reassign-owned-to`.

The plugin docs and the template README describe the flow end to end:
`appkit db init` once after scaffolding, `appkit db migrate` while you
develop, migrations on deploy with their per-migration transactions and
lock limits, two-step changes for tables in use, rollback, existing apps,
`appkit db verify --deployed -t <target>` in CI, and one owner per branch.
The Lakebase docs start local development on a dev branch.

The template's .gitignore skips config/database/*.bak, the copy of
schema.ts that `appkit db introspect` keeps.

Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi force-pushed the stack/database-dev-flow/07-apps-init branch from 7db9fa1 to 81e2e8f Compare October 20, 2026 12:22
@ditadi
ditadi force-pushed the stack/database-dev-flow/06-db-verify branch from 42df642 to 1b3bde7 Compare October 20, 2026 12:23
@github-actions

github-actions Bot commented Oct 20, 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 39422038318 -R databricks/appkit -n appkit-template-0.89.0-pr.cd46b9a-stack-database-dev-flow-07-apps-init-675 -D appkit-pr-675 \
  && unzip -o "appkit-pr-675/appkit-template-0.89.0-pr.cd46b9a-stack-database-dev-flow-07-apps-init-675.zip" -d "appkit-pr-675" \
  && databricks apps init --template "appkit-pr-675"

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.

This branch has not been deployed

No deployments
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.

1 participant