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 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
  • Pythonic CLI — clean, readable, extensible commands

📦 Installation

Quick Install (Recommended)

curl -sSL https://raw.githubusercontent.com/Adelodunpeter25/migrator/main/install.sh | bash

Using pip

pip install git+https://github.com/Adelodunpeter25/migrator.git

Using uv

uv add git+https://github.com/Adelodunpeter25/migrator.git

Uninstall

curl -sSL https://raw.githubusercontent.com/Adelodunpeter25/migrator/main/uninstall.sh | bash

🚀 Quick Start

1. Set up your database URL

Create a .env file:

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

Or use settings.py, config.py, config.yaml, or config.toml.

2. Initialize migrations

migrator init

This creates:

migrations/
├── versions/
├── env.py
├── script.py.mako
└── alembic.ini

3. Create your first migration

migrator makemigrations "create user table"

4. Apply migrations

migrator migrate

📖 Commands

migrator init

Initialize migration environment in your project.

migrator init
migrator init --dir custom_migrations

migrator makemigrations

Create a new migration with auto-detection.

migrator makemigrations "add email to users"
migrator makemigrations "initial" --manual  # Create empty migration

migrator migrate

Apply pending migrations.

migrator migrate
migrator migrate --revision abc123  # Migrate to specific revision

migrator downgrade

Rollback migrations.

migrator downgrade  # Rollback one migration
migrator downgrade --revision abc123  # Rollback to specific revision
migrator downgrade --revision base  # Rollback all migrations

migrator history

Show migration history.

migrator history

migrator current

Show current database revision.

migrator current

⚙️ Configuration

Migrator automatically detects your database URL from multiple sources (in order):

  1. .env file (DATABASE_URL or SQLALCHEMY_DATABASE_URI)
  2. Environment variables
  3. settings.py or config.py
  4. config.yaml or config.toml

Example configurations

.env

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

settings.py

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

config.yaml

database:
  url: postgresql://user:password@localhost:5432/dbname

config.toml

[database]
url = "postgresql://user:password@localhost:5432/dbname"

🔧 How It Works

Auto-Detection

Migrator automatically finds your SQLAlchemy Base class by:

  1. Checking common import paths (app.models, models, database, etc.)
  2. Scanning your project files for declarative base classes
  3. Injecting the correct import into Alembic's env.py

Alembic Integration

Migrator wraps Alembic's powerful migration engine with a simpler interface:

  • Uses alembic.command API internally
  • Customizes templates for auto-import
  • Provides Django-style command names
  • Adds beautiful terminal output

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT License - see LICENSE file for details.

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.1.0.tar.gz (70.9 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.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: migrator_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 70.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for migrator_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7391eea662c34ddba891ca8fc99467b494f5a3b18bdf211357de145ebf2d1f6
MD5 f88ed448217d4fd8d424e0976e9db333
BLAKE2b-256 35122232246ef99c49ca7d7321315f8c0ab0190738c0e26b1719b0eca8c3beb5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: migrator_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for migrator_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c03e5c1bd08c1fc657bfc9f9c51fe3ef5e168f6e9fb6310cfe6dd889dcb191dc
MD5 6a6f113428986d9fcceea6d71534f346
BLAKE2b-256 f8778209017c9e587c104bab42f525a7fd8088be14d0b02e0913da3fa6c84b3d

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