Skip to main content

Universal migration CLI for Python apps

Project description

Migrator

The Universal Migration CLI for Python Apps

A lightweight, framework-agnostic database migration tool for Python projects using SQLAlchemy. Migrator automates what Alembic requires developers to set up manually — making migrations as simple as Django's makemigrations and migrate, but flexible enough for Python any project.

✨ Features

  • Zero boilerplate — one command to init and start migrating
  • Auto-detect models — finds SQLAlchemy Base classes automatically
  • Smart config — no need to manually edit alembic.ini or env.py
  • Framework agnostic — works with FastAPI, Flask, or standalone SQLAlchemy

📦 Installation

# SQLite / no extras needed
uv add migrator-cli

# PostgreSQL
uv add migrator-cli[postgres]

# MySQL
uv add migrator-cli[mysql]

# All database drivers
uv add migrator-cli[all]

Requires Python 3.11+.

🚀 Quick Start

Note: If you have an existing database with tables, see MIGRATION_GUIDE.md first.

1. Set up your database URL

Create a .env file:

DATABASE_URL=postgresql://user:password@localhost:5432/dbname

2. Initialize migrations

migrator init

3. Create your first migration

migrator makemigrations "create user table"

4. Apply migrations

migrator migrate

📖 Commands

# Initialize migration environment
migrator init

# Create new migration
migrator makemigrations "add email to users"

# Create migration and show SQL
migrator makemigrations "add email to users" --show-sql

# Apply migrations
migrator migrate

# Apply migrations without confirmation
migrator migrate --yes

# Preview migration SQL without applying
migrator migrate --dry-run

# Rollback migrations
migrator downgrade

# Show migration history
migrator history

# Show current revision
migrator current

# Mark database as migrated (for existing databases)
migrator stamp head

# Show migration status
migrator status

🏗️ Advanced Usage

Nested Project Structures

migrator init --base app.core.database:Base
migrator makemigrations "initial" --base app.core.database:Base

Async SQLAlchemy

# Your .env
DATABASE_URL=postgresql+asyncpg://user:pass@localhost/db
# Migrator auto-converts to: postgresql://user:pass@localhost/db

Custom Config

migrator init --config backend/settings.py

Verbose Mode

migrator init --verbose

🔧 Troubleshooting

Base not found? Use --base flag:

migrator init --base app.core.database:Base

Existing database? Use stamp:

migrator stamp head

🤝 Contributing

Contributions welcome! Submit a Pull Request.

📄 License

MIT License - see LICENSE file.

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

migrator_cli-0.5.0.tar.gz (91.1 kB view details)

Uploaded Source

Built Distribution

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

migrator_cli-0.5.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file migrator_cli-0.5.0.tar.gz.

File metadata

  • Download URL: migrator_cli-0.5.0.tar.gz
  • Upload date:
  • Size: 91.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for migrator_cli-0.5.0.tar.gz
Algorithm Hash digest
SHA256 dc5b59cb52d9de76dab1c1f6d2a04d44c70b92cd46b00ea4ac7a7f9cf95aba70
MD5 3e15eb832bef49cccfe41f3e83d1006c
BLAKE2b-256 5965912b55c44acf03e9cc6eb5141681e044cf9c41a45d3001c86c31df7e9f9a

See more details on using hashes here.

File details

Details for the file migrator_cli-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for migrator_cli-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d6c426cf971d4fca8bd1e35f2d63904fd8f3ad2ed3e692146e810f85ed01893
MD5 f3a31b771e4816437bfe4de8d98e70b7
BLAKE2b-256 ce60fed2964802ff572814232a6207d0c3a5b257c4bbc0eda53fa4dd3aafbb57

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