Skip to main content

Database migration system for Python/SQLAlchemy projects

Project description

DBWarden

A database migration system for Python/SQLAlchemy projects.

Documentation Ask DeepWiki

Installation

pip install dbwarden

Configuration

⚠️ Warning

This is an experimental package. Your fuckups are not mine to fix. You have been warned.

Even though this is an experimental package, I added lots of failsafes to protect the connected DB as to avoid issues.

Create warden.toml in your project:

# Default database
default = "primary"

# Database configurations
[database.primary]
database_type = "sqlite"
sqlalchemy_url = "sqlite:///./development.db"
dev_database_type = "sqlite"
dev_database_url = "sqlite:///./dev.db"

[database.analytics]
database_type = "postgresql"
sqlalchemy_url = "postgresql://user:password@localhost:5432/analytics"

Basic Commands

Command Description
dbwarden init Initialize migrations directory
dbwarden database list List all configured databases
dbwarden database add <name> Add a new database
dbwarden make-migrations "name" Generate SQL from SQLAlchemy models
dbwarden migrate Apply pending migrations
dbwarden migrate -d <name> Migrate specific database
dbwarden --dev migrate -d <name> Migrate using development DB URL
dbwarden migrate --all Migrate all databases
dbwarden rollback Revert the last migration
dbwarden history Show migration history
dbwarden status Show current status

Multi-Database Support

Manage multiple databases from a single configuration:

# Add databases
dbwarden database add analytics --url "postgresql://user:pass@localhost:5432/analytics"
dbwarden database add legacy --url "mysql://user:pass@localhost:3306/legacy"

# List all databases
dbwarden database list

# Migrate specific database
dbwarden migrate -d analytics

# Migrate all databases (sequentially)
dbwarden migrate --all

Development Recommendation

Use SQLite as your development database (dev_database_url) when working with --dev. DBWarden translates unsupported backend-specific model types/defaults to SQLite-compatible SQL during migration generation. If a type cannot be translated, DBWarden falls back to TEXT and logs a warning.

Use strict mode to fail on unsupported conversions:

dbwarden --dev --strict-translation make-migrations "sync models" -d primary

SQLAlchemy Models

DBWarden automatically detects models in models/:

# models/user.py
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base

Base = declarative_base()

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    name = Column(String(100))
    email = Column(String(255), unique=True)

Complete Example

# 1. Initialize
dbwarden init

# 2. Create models in models/

# 3. Add more databases
dbwarden database add analytics --url "postgresql://user:pass@localhost:5432/analytics"

# 4. Generate migration from models
dbwarden make-migrations "create users table"

# 5. Apply
dbwarden migrate --verbose

# 6. Migrate all databases
dbwarden migrate --all

# 7. View history
dbwarden history

Supported Databases

Database Type Value Features
PostgreSQL postgresql SERIAL, TIMESTAMP, BYTEA
MySQL mysql AUTO_INCREMENT, ENUM
SQLite sqlite Built-in, zero config
ClickHouse clickhouse Analytics, MergeTree
MariaDB mariadb MySQL-compatible

Docs

For more information, see DBWarden Docs or DBWarden DeepWiki page

License

This Project is Licensed under the MIT License. See LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbwarden-0.4.tar.gz (468.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbwarden-0.4-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file dbwarden-0.4.tar.gz.

File metadata

  • Download URL: dbwarden-0.4.tar.gz
  • Upload date:
  • Size: 468.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dbwarden-0.4.tar.gz
Algorithm Hash digest
SHA256 9a44a65014cdbd2eb1535009d8b1c2a4fb10c32f2fc0630cf1c2ac9c6e77ce7f
MD5 3d813b568441f6af98d116bfd33a8d1f
BLAKE2b-256 646ddf9f930cbb4d0679c9199cfb0a9e016dd93a7da7e808471e430cadeb4d84

See more details on using hashes here.

File details

Details for the file dbwarden-0.4-py3-none-any.whl.

File metadata

  • Download URL: dbwarden-0.4-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dbwarden-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9891891682e9464db676466a5ac0644ac5c3f8f034533e1d6679fc0094a82a0c
MD5 d018f88d1bffd9f7a59765a29fbfec14
BLAKE2b-256 c5fe104bda092ee1e268dcfe1baf1b5d2a271ef7731aea0cb1f5105bfc2202a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page