Giter Site home page Giter Site logo

mbeacom / aerich Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tortoise/aerich

0.0 2.0 0.0 392 KB

A database migrations tool for Tortoise-ORM.

Home Page: https://github.com/long2ice/aerich

License: Apache License 2.0

Python 97.10% Makefile 2.90%

aerich's Introduction

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:[email protected]: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 column now.
  • Sqlite and Postgres may 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.

aerich's People

Contributors

long2ice avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.