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

# Quick install
curl -sSL https://raw.githubusercontent.com/db-toolkit/migrator/main/install.sh | bash

# Or using pip
pip install migrator-cli

🚀 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.4.2.tar.gz (103.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.4.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: migrator_cli-0.4.2.tar.gz
  • Upload date:
  • Size: 103.1 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.4.2.tar.gz
Algorithm Hash digest
SHA256 62dec370b32caff5e53d61f002ed2429b9d0d5e272312c428b64c381d84fca8b
MD5 b584cb9caad547c9e875f86fc71bc275
BLAKE2b-256 8edcff51a6ddd0205e169966d21c06c52deb1a283a790f1345f7484ce4ce293a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: migrator_cli-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 18.4 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.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5577d999f9885d6d9a569ed89c89dbad827338131c5f4b339eb40a9f97e8f4ca
MD5 b8dda9d0666eb95966d949138f51c846
BLAKE2b-256 8360684cdc214e7f37e56262e825b3eb055c48afa02a66ef27ae218aa651ea08

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