dbschema
dbschema is a tool to run MySQL or PostgreSQL migrations automatically. Using a table, it keeps a state of previous migrations to avoid duplicates.
Features:
Support for MySQL and PostgreSQL
Optional pre and post-migration queries (for example to update privileges)
Multiple migrations in multiple databases can be processed as one.
Installation
Install dbschema
# Install required packages
apt-get update
apt-get install --yes libpq-dev gcc python3-dev
pip3 install dbschema
Create a config file
Create the file ~/.dbschema.yml and add your databases configuration. See example
Create migrations table
dbschema uses a table called migrations_applied to keep track of migrations already applied to avoid duplication. See the schema for MySQL or PostgreSQL.
Migrations folder structure
For each database, you need to have a migration path (setting path in the migration file).
Within that path you need to create one folder per migration. This folder must contain a file called up.sql with the SQL queries and optionally a file called down.sql for rollbacks.
/path/to/migrations/db1/ |-- migration1/ | |-- up.sql | |-- down.sql |-- migration2/ | |-- up.sql |... /path/to/migrations/db2/ |-- migration1/ | |-- up.sql |-- migration2/ | |-- up.sql | |-- down.sql |...
Usage
Apply pending migrations
dbschema
# or to specify a config file path
dbschema --config /path/to/config.yml
# or to migrate only a specific database
dbschema --tag db1
Rollback
dbschema --tag db1 --rollback migration1
Example
$ dbschema
* Applying migrations for db1 (`test` on postgresql)
-> Migration `migration1` applied
-> Migration `migration2` applied
-> Migration `migration3` applied
* Migrations applied
* Applying migrations for db2 (`test` on mysql)
-> Migration `migration1` applied
-> Migration `migration2` applied
-> Migration `migration3` applied
* Migrations applied
$
$ dbschema --tag db2 --rollback migration1
* Rolling back mysql -> `migration1`
-> Migration `migration1` has been rolled back
$
Metadata
Release files for dbschema 1.4.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 | Provenance | |
|---|---|---|---|---|
| dbschema-1.4.3.tar.gz | 6.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbschema-1.4.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 13.2 kB
Release files / dbschema-1.4.3.tar.gz
| Download URL | dbschema-1.4.3.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee984c4e2dfd56c49b7ac444cc20ca80b38a4f62d5b3117c29b9f45ec46bf761
|
|
BLAKE2b-256 checksum How to use checksums |
31a9de084490940fb2a532bf9f662a1d31553d92ed532143083e8d74193fa3b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / dbschema-1.4.3-py2.py3-none-any.whl
| Download URL | dbschema-1.4.3-py2.py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f35333580c28db9cdec26de2696978786974e587c2d261a401549de4303bccd1
|
|
BLAKE2b-256 checksum How to use checksums |
8a19ed13c3f12e873f84be54220e57a6890ce3253885a42123c84f5ac4c600a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Security for dbschema 1.4.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.