Skip to main content

Pypi Build Status codecov MIT licensed

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
$

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbschema-1.4.3.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbschema-1.4.3-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dbschema-1.4.3.tar.gz.

File metadata

  • Download URL: dbschema-1.4.3.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for dbschema-1.4.3.tar.gz
Algorithm Hash digest
SHA256 ee984c4e2dfd56c49b7ac444cc20ca80b38a4f62d5b3117c29b9f45ec46bf761
MD5 9cbef720ee1ea9f839002a4bc2349787
BLAKE2b-256 31a9de084490940fb2a532bf9f662a1d31553d92ed532143083e8d74193fa3b5

See more details on using hashes here.

File details

Details for the file dbschema-1.4.3-py2.py3-none-any.whl.

File metadata

  • Download URL: dbschema-1.4.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for dbschema-1.4.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f35333580c28db9cdec26de2696978786974e587c2d261a401549de4303bccd1
MD5 2726718c6f703d4ec0d024f9b96c05e0
BLAKE2b-256 8a19ed13c3f12e873f84be54220e57a6890ce3253885a42123c84f5ac4c600a7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.3 This release

2 files

1.4.2

2 files

1.4

2 files

1.3

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2

2 files

1.1.2

2 files

1.1.1

2 files

1.1

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page