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 https://github.com/long2ice/aerich/workflows/test/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:
  -c, --config TEXT  Config file.  [default: aerich.ini]
  --app TEXT         Tortoise-ORM app name.  [default: models]
  -n, --name TEXT    Name of section in .ini file to use for aerich config.
                     [default: aerich]
  -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 config file and generate root migrate location.
  init-db    Generate schema and generate app migrate location.
  migrate    Generate migrate changes file.
  upgrade    Upgrade to latest version.

Usage

You need add aerich.models to your Tortoise-ORM config first, example:

TORTOISE_ORM = {
    "connections": {"default": "mysql://root:123456@127.0.0.1:3306/test"},
    "apps": {
        "models": {
            "models": ["tests.models", "aerich.models"],
            "default_connection": "default",
        },
    },
}

Initialization

$ aerich init -h

Usage: aerich init [OPTIONS]

  Init config file and generate root migrate location.

Options:
  -t, --tortoise-orm TEXT  Tortoise-ORM config module dict variable, like settings.TORTOISE_ORM.
                           [required]
  --location TEXT          Migrate store location.  [default: ./migrations]
  -h, --help               Show this message and exit.

Init config file and location:

$ aerich init -t tests.backends.mysql.TORTOISE_ORM

Success create migrate location ./migrations
Success generate config file aerich.ini

Init db

$ aerich init-db

Success create app migrate location ./migrations/models
Success generate schema for app "models"

Update models and make migrate

$ aerich migrate --name drop_column

Success migrate 1_202029051520102929_drop_column.json

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

Upgrade to latest version

$ aerich upgrade

Success upgrade 1_202029051520102929_drop_column.json

Now your db is migrated to latest.

Downgrade to previous version

$ aerich downgrade

Success downgrade 1_202029051520102929_drop_column.json

Now your db rollback to previous version.

Show history

$ aerich history

1_202029051520102929_drop_column.json

Show heads to be migrated

$ aerich heads

1_202029051520102929_drop_column.json

Limitations

  • Not support rename column now.

  • Sqlite and Postgres may not work as expected because I don’t use those in my work.

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.2.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

aerich-0.2.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file aerich-0.2.0.tar.gz.

File metadata

  • Download URL: aerich-0.2.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.8 CPython/3.8.2 Darwin/19.5.0

File hashes

Hashes for aerich-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0f655b09e30c720c998bf7205b8e5ab67b5a8ca0c6d04889e9a0ff15e70c65b6
MD5 1a76efbdf353f6967216a7a44e3fbac4
BLAKE2b-256 6b19eba15f33d2ba2ef88aef1edc3d3080b52171e5833ddf87abd72a5d5287f0

See more details on using hashes here.

File details

Details for the file aerich-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aerich-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.8 CPython/3.8.2 Darwin/19.5.0

File hashes

Hashes for aerich-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f78e2083e7314b73c25ce2f7c7de602b343ebdcc11987d2e3dd24ce3edd2ef86
MD5 50044aa4e994044986e8105e6e51c919
BLAKE2b-256 e31234fa68724545f8dba796b8a2a95bf850a44f9612097ba6e7ac218245fde4

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