Skip to content

feat(database): brownfield support — introspector, drift detection, db CLI#356

Draft
ditadi wants to merge 13 commits into
stack/database/serverfrom
stack/database/brownfield
Draft

feat(database): brownfield support — introspector, drift detection, db CLI#356
ditadi wants to merge 13 commits into
stack/database/serverfrom
stack/database/brownfield

Conversation

@ditadi
Copy link
Copy Markdown
Contributor

@ditadi ditadi commented May 6, 2026

🥞 Stacked PR

Use this link to review incremental changes.


Brownfield support for existing Lakebase/Postgres schemas. This layer lets AppKit inspect a live database, render schema files, detect drift, and manage migrations from the CLI.

Introspection + rendering

Adds the introspector engine, Drizzle adapter, schema-to-introspection bridge, SQL rendering, type mapping, and roundtrip tests.

Drift detection

Adds boot-time drift detection with fatal/warn classifications, production fail-closed behavior for unsafe drift, live-only warnings, healthz saturation, and pg-to-http error mapping.

Database CLI

Adds appkit db introspect, generate, migrate, verify, setup:dev, seed, and migration helpers.

Test plan

  • Introspector adapter tests
  • Render and roundtrip tests
  • Drift tests
  • CLI command tests
  • Full stack verification run locally before push

PR Stack

  1. Database foundation: schema builder, plugin skeleton, runtime base — feat(database): foundation — schema builder, plugin skeleton, connectors #354
  2. Server runtime: Drizzle pool, OBO, transactions, hooks — feat(database): server runtime — drizzle pool, OBO, transactions, hooks #355
  3. Brownfield support: introspector, drift detection, db CLI (this PR)
  4. appkit db init onboarding — feat(cli): appkit db init — one-command lakebase onboarding #357
  5. Typed browser db client + dev playground demo — feat(database): typed browser db client + dev playground demo #358
  6. React entity UI + columns metadata — feat(database): React entity UI components + columns metadata route #359
  7. RLS scaffolder + connection pool tuning — feat(database): RLS scaffolder + connection pool tuning #360
  8. Database plugin guide + release polish — docs(database): plugin guide + CLAUDE.md polish + small public-API tweaks #361

ditadi added 13 commits May 15, 2026 00:27
Signed-off-by: ditadi <victordperd@gmail.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…ope verify to declared schema

* introspect: when the live DB has no FK constraints, infer relations
  by matching a column's name and pg_type to another table's PK.
  Inferred references are tagged so the renderer marks them with
  "inferred from naming convention; verify" for human review.
  Resolves .include() silently failing on schemas created without
  explicit REFERENCES clauses.
* render: keep .primaryKey() on columns that are both PK and FK
  (e.g. 1:1 mapping tables like ai_summaries(case_id)). The FK branch
  was emitting fk(...).notNull() and dropping the PK marker.
* verify: read $schemaName from the loaded defineSchema(...) and pass
  it to introspect, so drift only scans the Postgres schema this app
  owns. Eliminates false drift from sibling apps' tables in the same
  Lakebase database.
@ditadi ditadi force-pushed the stack/database/brownfield branch from 0bcf90a to 7e78b62 Compare May 15, 2026 11:03
@ditadi ditadi force-pushed the stack/database/server branch from caa5080 to 1c4c286 Compare May 15, 2026 11:03
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