Yet another Python migration tool
Project description
Simple, cross-database migration tool for Python applications. Inspired by node migrations.
Requirements
Only Python 3 is supported for now.
Installation
$ pip install migrations
Notice, this distribution provides package and executable
script named migrate
, so check if it does not mess with
existing packages/scripts. Generally, you should neither install
this tool globally, nor install several migration tools for one project.
Features
TBD
Usage
usage: migrate [options] [action]
actions:
up [NAME|COUNT] (default) perform COUNT migrations or till given NAME
(by default performs all available)
down [NAME|COUNT] revert COUNT migrations or till given NAME
(by default reverts one)
create NAME create new migration file
options:
-h, --help show this help message and exit
-v, --version show version and exit
-d PATH, --migrations-dir PATH
directory where migrations are stored
-s PATH, --state-file PATH
location of file which stores database state
-t PATH, --template-file PATH
location of template file for new migrations
Each migration file must define functions up()
and down()
without required arguments.
Simple migration example:
import redis
db = redis.Redis(host='localhost', port=6379)
def up():
db.rpush('used_libraries', 'migrations')
def down():
db.rpop('used_libraries', 'migrations')
A bit more complex example. Let’s assume that in current
working directory we have module named db
, which contains
singleton object responsible for DB connection, for example
PyMySQL Connection object.
Current working directory is the first place to be scanned for
modules to import.
from db import connection
def manage_cursor(action):
def wrap():
with connection.cursor() as cursor:
action(cursor)
connection.commit()
return wrap
@manage_cursor
def up(cursor):
cursor.execute(
"INSERT INTO used_libraries (`name`) VALUES ('migrations')"
)
@manage_cursor
def down(cursor):
cursor.execute(
"DELETE FROM used_libraries WHERE `name`='migrations'"
)
Project details
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
Hashes for migrations-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baea376db0bb08bbdee899487be38af1deb68721cab3cc9c2e9f43296c7f62d1 |
|
MD5 | a984821cc67f3442b25060bac8d070e2 |
|
BLAKE2b-256 | ab9e686c72b9f3cb4fd3f93f442c733463e250cfc0b210439651462a5d310dde |