Repository navigation
Conversation
defineSchema() without a schemaName now places its tables in the Postgres schema "app" instead of "public". The deployed app's service principal can create and own a schema of its own, but has no CREATE on public, so tables in public could not be migrated on deploy without a manual grant. Signed-off-by: ditadi <victordperd@gmail.com>
`appkit db migrate` generates a migration from config/database/schema.ts with drizzle-kit, regenerates shared/appkit-types/database.d.ts, and applies pending migrations to the branch .env points at. It applies only to a branch created for this developer (dev-…) or this checkout (session-…); on any other branch, including the project default and any branch databricks.yml deploys to, it generates and says why nothing was applied. It connects only after the Lakebase API confirms that PGHOST is a host of LAKEBASE_ENDPOINT. The logic lives in a new @databricks/appkit/database-tooling entry point that the shared CLI loads lazily, so the runtime never imports drizzle-kit. drizzle-kit is an optional peer dependency: apps that generate migrations install it as a dev dependency, and the command says how when it is missing. `appkit db` stays hidden from --help until the database plugin is offered by `databricks apps init`. Signed-off-by: ditadi <victordperd@gmail.com>
`appkit db introspect` reads an existing Postgres schema (default: app) from pg_catalog and writes config/database/schema.ts from it, keeping the previous file as schema.ts.bak. It also writes the migration that brings history up to the database: a first 0000_baseline, which the deployed app adopts on start when its tables already exist, or the next migration on a branch created for this developer or checkout, where it is recorded as applied. What the schema builder cannot express is skipped and reported, and what it declares differently from the database (a timestamp precision, an index) is listed. With history, it runs only on a branch that has applied every committed migration, and it refuses a migration that would drop something it skipped, since that migration runs on deploy. If anything fails after schema.ts is written, schema.ts, its backup and the migrations are put back. Signed-off-by: ditadi <victordperd@gmail.com>
`appkit db init` gives a checkout its own Lakebase branch: a per-developer dev branch or a per-checkout session branch (7-day TTL), forked from the project's default branch. It makes sure the branch has a read-write endpoint and a Postgres role for the developer, hands the objects the fork copied from its parent to the developer (role delete with reassign_owned_to, only on that branch), points .env at it, and can start the schema by migrating, introspecting or cleaning. It refuses the project's default branch, protected branches and branches databricks.yml deploys to before changing anything: those belong to the deployed app. `appkit db clean` drops the app schema and `appkit db seed` runs config/database/seed.sql with the app schema on the search_path, both only on a branch created for this developer or checkout. Signed-off-by: ditadi <victordperd@gmail.com>
`appkit db verify` checks, read-only, that the branch .env points at matches config/database/schema.ts and has every committed migration, including the ones the migrator would never run there: merged out of order, or edited after they ran. With --prod it checks, through the Databricks API only, that the deployed app is set up to use the branch databricks.yml deploys to: the app exists, its postgres resource names that branch and database with CAN_CONNECT_AND_CREATE, its service principal has a role there, and it is running. It reads no database, so it needs no role on the deploy branch. Signed-off-by: ditadi <victordperd@gmail.com>
This was referenced Oct 19, 2026
ditadi
force-pushed
the
stack/database-dev-flow/05-db-init
branch
from
October 19, 2026 20:35
960b211 to
c56de21
Compare
This branch has not been deployed
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 on #672.
Summary
Adds
appkit db verify, a read-only check that answers "will my app work with its database?".appkit db verifychecks the branch.envpoints at, which is normally your dev or session branch:config/database/schema.tsdeclares exists (the same check the plugin runs on start);appkit db verify --prodchecks that the deployed app is set up to use the branchdatabricks.ymldeploys to, through the Databricks API only:postgresresource names that branch and database, withCAN_CONNECT_AND_CREATE;A running app has applied its migrations and checked its schema on start (feat(appkit): apply committed database migrations on deploy start #654).
--prodreads no database, so it needs no Postgres role on the deploy branch.Both exit 1 on any finding, and each finding names its fix.
Details
READ ONLYtransaction that is rolled back, then closes the connection.(created_at, hash)rows with the committed journal and files. The migrator itself is unchanged: it still runs only entries newer than the last recorded one.--prod, a crashed, stopped, failed or in-progress app is reported with the app's own status message and the command to run next (databricks apps logs,startordeploy).resources.appsoverride, else the top-level app. A name with${…}is reported as unresolvable rather than looked up.findSchemaProblemsis split out of the plugin's startup check, so verify reports the same problems the app would fail on.Tests
The local tests cover:
The
--prodtests use a faked Apps and Lakebase API where the developer has no role on the deploy branch. They cover:They also assert that no database connection and no write happens.
Checked live, read-only, against a workspace:
postgresresource format and a deleted app's 404;Checked against a local Postgres 14 with the real migrator: no false positives, and both stranded cases detected.