Migration tool for asyncpg inspired by knex.js
Go to file
Michal Szczepanski 762ce873ca
Update README.md
Signed-off-by: Michal Szczepanski <michal@vane.pl>
2020-11-10 01:34:47 +01:00
asyncpg_migrate Update asyncpg_migrate with pep8 compatible template 2020-11-10 01:34:10 +01:00
.gitignore Init repository for asyncpg migration tool 2020-11-10 00:35:06 +01:00
LICENSE Fix LICENSE with proper repository name 2020-11-10 01:29:19 +01:00
MANIFEST.in Init repository for asyncpg migration tool 2020-11-10 00:35:06 +01:00
README.md Update README.md 2020-11-10 01:34:47 +01:00
requirements.txt Init repository for asyncpg migration tool 2020-11-10 00:35:06 +01:00
setup.cfg Init repository for asyncpg migration tool 2020-11-10 00:35:06 +01:00
setup.py Init repository for asyncpg migration tool 2020-11-10 00:35:06 +01:00

asyncpg-migrate

Description

Simple database migration tool inspired by knex.js.
Migrations are by default applied in order of timestamp inside migrations directory

Install

pip install https://github.com/vane/asyncpg-migrate/archive/0.0.1.tar.gz

Usage

Display help

asyncpg-migrate -h

Add migration

asyncpg-migrate -a 'test migration'

migration will be added to migrations/${timestamp}_test_migration.py with following template

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncpg


async def up(config):
    conn: asyncpg.Connection = await asyncpg.connect(**config)
    pass


async def down(config):
    conn: asyncpg.Connection = await asyncpg.connect(**config)
    pass

List migrations

asyncpg-migrate -l

Apply all migrations

asyncpg-migrate -m

Apply specific migration

asyncpg-migrate -m migrations/migration_file.py

Rollback migration

asyncpg-migrate -r migrations/migration_file.py

Custom config -- different then conf/db.yaml (optional)

asyncpg-migrate -c conf/some.config.yaml

example config

db:
  host: 127.0.0.1
  port: 5432
  user: postgres
  password: postgres
  database: asyncpg-migate-test

Custom migration directory (optional)

asyncpg-migrate -d /opt/my-migrations

Using environment variables instead of configuration file

PG_USER
PG_PASSWORD
PG_DBNAME
PG_HOST
PG_PORT