01Database 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
Latest repository commit

Loading latest commits…

DB backends

5

Official plugins

7

Test files

166

Release

v0.20.10

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

Capabilities

Impact analysis

dbwarden check-impact scans the codebase with AST analysis and a grep fallback, then reports every reference to a column or table a migration changes before deploy.

Offline generation

Export model state once, then generate migrations in CI or on a machine with no database using make-migrations --offline.

Schema snapshots

Every migration writes a checksummed JSON snapshot. Snapshots power rename detection, offline diffs and column-level comparisons.

Typed Meta

A metaclass validates every class Meta attribute at import time; typos that would produce wrong DDL raise DBWardenConfigError immediately.

Reverse engineering

Generate SQLAlchemy models from a live database with generate-models, including backend metadata and a custom --base import.

Multi-database

One project can target several databases with isolated configs, per-database table ownership and optional databases that skip when missing.

04

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.

05

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.

06

Safety model

Migration generation classifies every operation, splits type changes into expand-contract steps, and assigns severity. The CLI adds execution ceilings, pending-plan checks and structured impact reports, so a destructive change can be stopped before it reaches production.

History stays auditable: checksummed snapshots, repeatable migrations, merge reconciliation and rebase support. Rollbacks are generated where safe; irreversible changes require an explicit declaration instead of a placeholder.

07

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
08

Supported databases

Supported databases
DatabaseRound-tripNotes
PostgreSQLFullIdentity and generated columns, partitioning, inheritance, exclusion constraints, enum types and advanced indexes.
MySQLFullDDL parity, engine/charset/collation options, unsigned and on-update columns.
ClickHouseFullMergeTree family, replicated engines, projections, dictionaries, materialized views and skip indexes.
SQLiteFullWITHOUT ROWID/STRICT, generated columns, table rebuilds for unsupported ALTERs.
MariaDBPartialSchema layer complete; snapshot and reverse-engineering gaps remain.

Round-trip means model → SQL → live database → model validation.

09

Status

Stable Alpha: pre-1.0 but production-ready. No breaking change ships without a 3-month deprecation window.

10

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 installationPASS
CLI contractPASS
5 DB providersPASS
Migration applicationPASS
Constraint enforcementPASS
Regeneration silencePASS
Rollback / recoveryPASS
Plugin discoveryPASS
11

Ecosystem

The compiler is the centre of a set of independently versioned tools.

wlite

CLI + bindings

Declarative SQLite schema management without the Python overhead. The same philosophy as DBWarden, stripped to what SQLite and C can do alone.

C++RustPythonGoC#Zig
Source ↗

libwlite

C library

DBWarden's SQLite engine extracted as a standalone C library. Parses .wlite model files, manages databases, compares schemas, and generates migrations.

C11SQLite3
Source ↗

dbwarden-harness

Release certification

Standalone black-box validation across five real databases: PyPI install, CLI contract, migration application, rollback, and plugin discovery.

PythonDockerTestcontainers
Source ↗

dbwarden-redis

Migration locking

Redis-backed distributed migration locking for concurrent deployers.

PythonRedis
Source ↗

dbwarden-fastapi

Web integration

FastAPI session dependencies, health endpoints and migration routes.

PythonFastAPI
Source ↗

dbwarden-ch-rbac

ClickHouse RBAC

Roles, users, grants, row policies, quotas and settings profiles for ClickHouse.

PythonClickHouse
Source ↗

dbwarden-pgsql-types

Postgres types

Custom ENUMs, domains, composite types and sequences.

PythonPostgreSQL
Source ↗

dbwarden-pgsql-rbac

Postgres RBAC

Roles, grants, default privileges and row-level security policies.

PythonPostgreSQL
Source ↗

dbwarden-pgsql-extensions

Postgres extensions

Extensions, event triggers, functions, triggers and storage parameters.

PythonPostgreSQL
Source ↗

dbwarden-plugin-template

Plugin template

Scaffolding for building and testing new DBWarden plugins.

Python
Source ↗

dbwarden-seeds

Seed data

Code and file-based seed management with apply and rollback.

Python
Source ↗

dbwarden-sandbox

Sandbox testing

Testcontainers sandbox providers for safe migration replay.

PythonDocker
Source ↗
12

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