Skip to main content

A database migrations tool for Tortoise-ORM.

Project description

https://img.shields.io/pypi/v/aerich.svg?style=flat https://img.shields.io/github/license/long2ice/aerich https://github.com/long2ice/aerich/workflows/pypi/badge.svg

Introduction

Tortoise-ORM is the best asyncio ORM now, but it lacks a database migrations tool like alembic for SQLAlchemy, or Django ORM with it’s own migrations tool.

This project aim to be a best migrations tool for Tortoise-ORM and which written by one of contributors of Tortoise-ORM.

Install

Just install from pypi:

$ pip install aerich

Quick Start

$ aerich -h

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

Options:
  --config TEXT        Tortoise-ORM config module, will auto read config dict variable
                       from it.  [default: settings]
  --tortoise-orm TEXT  Tortoise-ORM config dict variable.  [default:
                       TORTOISE_ORM]
  --location TEXT      Migrate store location.  [default: ./migrations]
  --app TEXT           Tortoise-ORM app name.  [default: models]
  -h, --help           Show this message and exit.

Commands:
  downgrade  Downgrade to previous version.
  heads      Show current available heads in migrate location.
  history    List all migrate items.
  init       Init migrate location and generate schema, you must exec first.
  migrate    Generate migrate changes file.
  upgrade    Upgrade to latest version.

Usage

Init schema and migrate location

$ aerich --config tests.backends.mysql init

Success create migrate location ./migrations/models
Success init for app "models"

Update models and make migrate

$ aerich --config tests.backends.mysql migrate --name drop_column

Success migrate 1_202029051520102929_drop_column.json

Format of migrate filename is {version}_{datetime}_{name|update}.json

Upgrade to latest version

$ aerich --config tests.backends.mysql upgrade

Success upgrade 1_202029051520102929_drop_column.json

Now your db is migrated to latest.

Downgrade to previous version

$ aerich --config tests.backends.mysql downgrade

Success downgrade 1_202029051520102929_drop_column.json

Now your db rollback to previous version.

Show history

$ aerich --config tests.backends.mysql history

1_202029051520102929_drop_column.json

Show heads to be migrated

$ aerich --config tests.backends.mysql heads

1_202029051520102929_drop_column.json

License

This project is licensed under the MIT 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

aerich-0.1.1.tar.gz (10.4 kB view hashes)

Uploaded Source

Supported by

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