Skip to main content

A database migrations tool for Tortoise ORM.

Project description

Aerich

image image image image

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"

If your Tortoise-ORM app is not default models, you must specify --app like aerich --app other_models init-db.

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.

And if aerich guess you are renaming a column, it will ask Rename {old_column} to {new_column} [True], you can choice True to rename column without column drop, or choice False to drop column then create.

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

Support this project

  • Just give a star!
  • Donation.
AliPay WeChatPay PayPal
PayPal to my account long2ice.

License

This project is licensed under the Apache-2.0 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.4.tar.gz (17.9 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.4-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aerich-0.2.4.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.6

File hashes

Hashes for aerich-0.2.4.tar.gz
Algorithm Hash digest
SHA256 e1e817b4091da0572fbbaee0816450f2f8e46880dfd9042933220f965a87943f
MD5 c4f2d06eaa6b2ae5b8f6797f33f6f001
BLAKE2b-256 d3ba24b279af3ca991636803664e8241f120103c20aec88c762aef2b7c33d63e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aerich-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.6

File hashes

Hashes for aerich-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8cafdb3122424ef2b79cd34439166a5f417bab9fcf92ea862e6beeb07236d46a
MD5 a7e85a4436c57d23be07a93620514c7b
BLAKE2b-256 a09fc3ced605d2df44313c7e22d8dfce39d9c1f0431f5fcf05a0d4c12a3a6106

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