All Projects → tortoise → Aerich

tortoise / Aerich

Licence: apache-2.0
A database migrations tool for TortoiseORM, ready to production.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Aerich

Dbmate
🚀 A lightweight, framework-agnostic database migration tool.
Stars: ✭ 2,228 (+828.33%)
Mutual labels:  database-migrations, mysql, postgresql
Shmig
Database migration tool written in BASH.
Stars: ✭ 408 (+70%)
Mutual labels:  database-migrations, mysql, postgresql
Pg chameleon
MySQL to PostgreSQL replica system
Stars: ✭ 274 (+14.17%)
Mutual labels:  database-migrations, mysql, postgresql
Yuniql
Free and open source schema versioning and database migration made natively with .NET Core.
Stars: ✭ 156 (-35%)
Mutual labels:  database-migrations, mysql, postgresql
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+1080%)
Mutual labels:  mysql, postgresql
Notadd
A microservice development architecture based on nest.js. —— 基于 Nest.js 的微服务开发架构。
Stars: ✭ 2,556 (+965%)
Mutual labels:  mysql, postgresql
Gorm Bulk Insert
implement BulkInsert using gorm, just pass a Slice of Struct. Simple and compatible.
Stars: ✭ 241 (+0.42%)
Mutual labels:  mysql, postgresql
Pony
Pony Object Relational Mapper
Stars: ✭ 2,762 (+1050.83%)
Mutual labels:  mysql, postgresql
Dolibarr
Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). It is open source software (written in PHP) and designed for small and medium businesses, foundations and freelancers. You can freely install, use and distribute it as a standalon…
Stars: ✭ 2,877 (+1098.75%)
Mutual labels:  mysql, postgresql
Knex
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
Stars: ✭ 15,083 (+6184.58%)
Mutual labels:  mysql, postgresql
Redaxscript
A modern, ultra lightweight and rocket fast Content Management System
Stars: ✭ 241 (+0.42%)
Mutual labels:  mysql, postgresql
Heidisql
A lightweight client for managing MariaDB, MySQL, SQL Server, PostgreSQL and SQLite, written in Delphi
Stars: ✭ 2,864 (+1093.33%)
Mutual labels:  mysql, postgresql
Chartbrew
Open-source web platform for creating charts out of different data sources (databases and APIs) 📈📊
Stars: ✭ 199 (-17.08%)
Mutual labels:  mysql, postgresql
Liquibase
Main Liquibase Source
Stars: ✭ 2,910 (+1112.5%)
Mutual labels:  database-migrations, mysql
Helicalinsight
Helical Insight software is world’s first Open Source Business Intelligence framework which helps you to make sense out of your data and make well informed decisions.
Stars: ✭ 214 (-10.83%)
Mutual labels:  mysql, postgresql
Scany
Library for scanning data from a database into Go structs and more
Stars: ✭ 228 (-5%)
Mutual labels:  mysql, postgresql
Storagetapper
StorageTapper is a scalable realtime MySQL change data streaming, logical backup and logical replication service
Stars: ✭ 232 (-3.33%)
Mutual labels:  mysql, postgresql
Devops Bash Tools
550+ DevOps Bash Scripts - AWS, GCP, Kubernetes, Kafka, Docker, APIs, Hadoop, SQL, PostgreSQL, MySQL, Hive, Impala, Travis CI, Jenkins, Concourse, GitHub, GitLab, BitBucket, Azure DevOps, TeamCity, Spotify, MP3, LDAP, Code/Build Linting, pkg mgmt for Linux, Mac, Python, Perl, Ruby, NodeJS, Golang, Advanced dotfiles: .bashrc, .vimrc, .gitconfig, .screenrc, .tmux.conf, .psqlrc ...
Stars: ✭ 226 (-5.83%)
Mutual labels:  mysql, postgresql
Sequelize Auto Migrations
Migration generator && runner for sequelize
Stars: ✭ 233 (-2.92%)
Mutual labels:  mysql, postgresql
Sqlfiddle3
New version based on vert.x and docker
Stars: ✭ 242 (+0.83%)
Mutual labels:  mysql, postgresql

Aerich

image image image image

Introduction

Aerich is a database migrations tool for Tortoise-ORM, which is like alembic for SQLAlchemy, or like Django ORM with it's own migrations solution.

Important: You can only use absolutely import in your models.py to make aerich work.

From version v0.5.0, there is no such limitation now.

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 specified 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.
  inspectdb  Introspects the database tables to standard output as...
  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.

Initialize the config file and migrations 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 the default models, you must specify the correct app via --app, e.g. aerich --app other_models init-db.

Update models and make migrate

> aerich migrate --name drop_column

Success migrate 1_202029051520102929_drop_column.sql

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

If aerich guesses you are renaming a column, it will ask Rename {old_column} to {new_column} [True]. You can choose True to rename column without column drop, or choose False to drop the column then create. Note that the latter may lose data.

Upgrade to latest version

> aerich upgrade

Success upgrade 1_202029051520102929_drop_column.sql

Now your db is migrated to latest.

Downgrade to specified version

> aerich init -h

Usage: aerich downgrade [OPTIONS]

  Downgrade to specified version.

Options:
  -v, --version INTEGER  Specified version, default to last.  [default: -1]
  -d, --delete           Delete version files at the same time.  [default:
                         False]

  --yes                  Confirm the action without prompting.
  -h, --help             Show this message and exit.
> aerich downgrade

Success downgrade 1_202029051520102929_drop_column.sql

Now your db is rolled back to the specified version.

Show history

> aerich history

1_202029051520102929_drop_column.sql

Show heads to be migrated

> aerich heads

1_202029051520102929_drop_column.sql

Inspect db tables to TortoiseORM model

Currently inspectdb only supports MySQL.

Usage: aerich inspectdb [OPTIONS]

  Introspects the database tables to standard output as TortoiseORM model.

Options:
  -t, --table TEXT  Which tables to inspect.
  -h, --help        Show this message and exit.

Inspect all tables and print to console:

aerich --app models inspectdb

Inspect a specified table in the default app and redirect to models.py:

aerich inspectdb -t user > models.py

Note that this command is limited and cannot infer some fields, such as IntEnumField, ForeignKeyField, and others.

Multiple databases

tortoise_orm = {
    "connections": {
        "default": expand_db_url(db_url, True),
        "second": expand_db_url(db_url_second, True),
    },
    "apps": {
        "models": {"models": ["tests.models", "aerich.models"], "default_connection": "default"},
        "models_second": {"models": ["tests.models_second"], "default_connection": "second", },
    },
}

You only need to specify aerich.models in one app, and must specify --app when running aerich migrate and so on.

Support this project

AliPay WeChatPay PayPal
PayPal to my account long2ice.

License

This project is licensed under the Apache-2.0 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].