Skip to main content

a database migration tool for usage with the peewee ORM

Project description

Miggy

A simple migration engine for peewee.

CI workflow PyPi Version

Why Fork?

This project is a fork of the original https://github.com/klen/peewee_migrate by klen — many thanks to them for the initial work!

Since the original project has not been actively maintained for some time, this fork was created to fix critical issues and continue development.

Requirements

  • python >= 3.10
  • peewee>=3.17.9

Installation

pip install miggy

Usage

From shell

Getting help:

$ miggy --help

Usage: miggy [OPTIONS] COMMAND [ARGS]...

Options:
    --help  Show this message and exit.

Commands:
    create   Create migration.
    migrate  Run migrations.
    rollback Rollback migration.

Create migration:

$ miggy create --help

Usage: miggy create [OPTIONS] NAME

    Create migration.

Options:
    --auto                  FLAG  Scan sources and create db migrations automatically. Supports autodiscovery.
    --auto-source           TEXT  Set to python module path for changes autoscan (e.g. 'package.models'). Current directory will be recursively scanned by default.
    --database              TEXT  Database connection
    --directory             TEXT  Directory where migrations are stored
    --schema                TEXT  Database schema
    -v, --verbose
    --help                        Show this message and exit.

Run migrations:

$ miggy migrate --help

Usage: miggy migrate [OPTIONS]

    Run migrations.

Options:
    --name                  TEXT  Select migration
    --database              TEXT  Database connection
    --directory             TEXT  Directory where migrations are stored
    --schema                TEXT  Database schema
    -v, --verbose
    --help                        Show this message and exit.

Auto create migration:

$ miggy makemigrations --help

Usage: miggy makemigrations [OPTIONS]

  Create a migration automatically

  Similar to `create` command, but `auto` is True by default, and `name` not
  required

Options:
    --name TEXT         Migration file name. By default will be
                      'auto_YYYYmmdd_HHMM'
    --auto              Scan sources and create db migrations automatically.
                      Supports autodiscovery.
    --auto-source TEXT  Set to python module path for changes autoscan (e.g.
                      'package.models'). Current directory will be recursively
                      scanned by default.
    --database TEXT     Database connection
    --directory TEXT    Directory where migrations are stored
    --schema                TEXT  Database schema
    -v, --verbose
    --help              Show this message and exit.

From python

from miggy import Router
from peewee import SqliteDatabase

router = Router(SqliteDatabase('test.db'))

# Create migration
router.create('migration_name')

# Run migration/migrations
router.run('migration_name')

# Run all unapplied migrations
router.run()

Migration files

By default, migration files are looked up in os.getcwd()/migrations directory, but custom directory can be given.

Migration files are sorted and applied in ascending order per their filename.

Each migration file must specify migrate() function and may specify rollback() function:

def migrate(migrator, database, fake=False, **kwargs):
    pass

def rollback(migrator, database, fake=False, **kwargs):
    pass

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/kalombos/miggy/issues

Developing

Install dependencies using pip:

pip install -e .[dev]

Run databases:

docker-compose up -d

Run checks and tests:

poe check

Contributors

See AUTHORS.md

License

Licensed under a BSD 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

miggy-2.0.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

miggy-2.0.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file miggy-2.0.0.tar.gz.

File metadata

  • Download URL: miggy-2.0.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.0

File hashes

Hashes for miggy-2.0.0.tar.gz
Algorithm Hash digest
SHA256 cbc485c2da4e1bb5c6833858320a11cd0b894039fc844e845d4c7d4075542c1b
MD5 7613323c42908828768e7162367d81e1
BLAKE2b-256 94d9387d989dea07ca4147361fbf5083fe532c3355f823f27c8b2fcb7aba5734

See more details on using hashes here.

File details

Details for the file miggy-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: miggy-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.0

File hashes

Hashes for miggy-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72091d6b2f2b3c709f3d16a57e3214e6a27bfab914dbe83e8c6ce42262587539
MD5 296ed921628560f80ac1a0a1009ca2a1
BLAKE2b-256 f715f396158e2fd2e20753f80e39e981a358fd5314b86560637e349e71bf287b

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