01 Database infrastructure

DBWarden

Declarative schema compiler that derives deterministic database migrations from SQLAlchemy models.

Your models are the source code. SQL is the output.

Python 3.12+SQLAlchemy 2.0PostgreSQLMySQLMariaDBSQLiteClickHouse

DB backends

5

CLI commands

14

Official plugins

7

Release harness

FULL

01

Problem

Schema management tools fall into two camps. Imperative tools have you author changes: revision scripts that describe how to get from one schema version to the next. Declarative tools have you author the desired state and derive the changes for you. Most imperative tools ask you to maintain two representations of your schema: your ORM models and your migration files. When they drift, you find out at deploy time.

02

Why it's hard

Schema drift is the core enemy. Making this deterministic requires a diff engine that handles renames, type changes, constraint changes, and ordering across five database backends with different DDL dialects. Every migration must carry both upgrade and rollback SQL, and the rollback must be tested against the actual database.

03

Workflow

  1. 01

    Point at existing models

    DBWarden reads your SQLAlchemy models as the single source of truth.

  2. 02

    make-migrations

    Generates a baseline schema or diffs against the current database state.

  3. 03

    Commit generated SQL

    Plain SQL files: reviewable, committable, executable anywhere.

  4. 04

    migrate

    Applies pending migrations with convergence verification.

  5. 05

    Optional: impact analysis, offline mode, plugins

    AST-based breaking change detection, CI without a database, seeds/RBAC/FastAPI integration.

04

Key decisions

SQL-first output

Migrations are plain SQL files. No runtime, no generated Python. Reviewable, committable, executable anywhere.

Deterministic diff

Same models + same snapshot = same migration. Always. No hidden state, no ordering dependencies.

Strict rollback contract

Every migration carries upgrade + rollback SQL. Placeholder rollback refused by default.

Plugin architecture

7 official plugins for seeds, RBAC, FastAPI, sandbox testing, and PostgreSQL/ClickHouse extensions.

05

Constraints

  • No migration runtime to install or version
  • No generated Python scripts that quietly do the wrong thing
  • No schema drift discovered in production
  • Migrations that can be generated in CI without a database connection
06

Test harness

dbwarden Test Harness is a standalone black-box validation suite. It installs DBWarden as a consumer, invokes its public CLI, creates disposable real database instances via Testcontainers, and verifies the compiled SQL produces the correct schema. This is not a unit test suite; it is a release certification boundary.

Harness coverage
PyPI installation PASS
CLI contract PASS
5 DB providers PASS
Migration application PASS
Constraint enforcement PASS
Regeneration silence PASS
Rollback / recovery PASS
Plugin discovery PASS
07

Ecosystem

08

Tradeoffs

  • Requires SQLAlchemy 2.0+ (not compatible with legacy models)
  • Schema compilation adds a build step vs. runtime migration
  • Declarative approach means less control over migration ordering