A database migrations tool for Tortoise ORM.
Project description
Aerich
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"
::: {.note} ::: {.title} Note :::
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
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 columnnow. SqliteandPostgresmay not work as expected because I don't use those in my work.
Support this project
- Just give a star!
- Donation.
AliPay
WeChat Pay
PayPal
Donate money by paypal to my account long2ice.
License
This project is licensed under the Apache-2.0 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aerich-0.2.2.tar.gz.
File metadata
- Download URL: aerich-0.2.2.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47d2a7c0114f86b6971d0b6e7ea4b4cdb1ae17d73bc5660f903216f6e4ed4a69
|
|
| MD5 |
7613a3f26a5ad98284213b8348c6f5fc
|
|
| BLAKE2b-256 |
3a83ada2fe61b5239773aa902ff41c3ac5a779574a586126f2114de28bd1ce75
|
File details
Details for the file aerich-0.2.2-py3-none-any.whl.
File metadata
- Download URL: aerich-0.2.2-py3-none-any.whl
- Upload date:
- Size: 24.1 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/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f6c5e78de5add1aacae9dcf64f4129d03562b3358f211385a0f86d22c45ac2b
|
|
| MD5 |
0e3f8667aa05c8766bf57fb84160f28b
|
|
| BLAKE2b-256 |
3bfbbf0be9ea1e25374588b8cee19b0ceab5c9c326355223587ca32e004f5245
|