Simple, cross-database migration tool for Python applications. Inspired by node migrations.
Status
The project is in alpha now. Bugs and breaking changes will occur.
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 [-h] [NAME|COUNT] (default) perform COUNT migrations or till given NAME
(by default perform all available)
down [-h] [NAME|COUNT] revert COUNT migrations or till given NAME
(by default revert one)
create [-h] 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'"
)
Metadata
Release files for migrations 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| migrations-0.0.3.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| migrations-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / migrations-0.0.3.tar.gz
| Download URL | migrations-0.0.3.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
606d7c44543065f5e3bbb9981765a842d0f2d9edc999c0fd26354f40e1fa7f08
|
|
BLAKE2b-256 checksum How to use checksums |
ad8a9f9956fb8dfd61d2480ee1d3e3685c06364b914a5a3cd2d761ae31518944
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / migrations-0.0.3-py3-none-any.whl
| Download URL | migrations-0.0.3-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b720a484187d26fdb2ac42f186e1e7c6ff38ae214f93cb5717108b9cefa94d3a
|
|
BLAKE2b-256 checksum How to use checksums |
0e4bf47bdf20476ab1100d46991e5ae0552b528c4c67964000d7ceea515f52b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |