A database migrations tool for Tortoise-ORM.
Project description
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
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file aerich-0.1.7.tar.gz
.
File metadata
- Download URL: aerich-0.1.7.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83cf1afc587c92e7811a708bdf637dad38d013d39890c9cc4069d1590dec15b8 |
|
MD5 | 0d47eb7f63df8e7b3a5c7e75efd3d545 |
|
BLAKE2b-256 | bd0cad26dafc1a198903669cc8be82b9554e1782e01cd1b8d810b0d5206924c7 |