Skip to main content

Schema migration made easy

Project description

dbschema is a tool to run MySQL or PostgreSQL migrations automatically. Using a table, it keeps a state of previous migrations to avoid duplicates.


  • 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.


Install dbschema

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 needs to contain a file called up.sql with the SQL queries.

|-- migration1/
|   |-- up.sql
|-- migration2/
|   |-- up.sql
|-- migration1/
|   |-- up.sql
|-- migration2/
|   |-- up.sql



# or
dbschema --config /path/to/config.yml

Project details

Download files

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

Files for dbschema, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size dbschema-1.0.2-py2.py3-none-any.whl (6.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size dbschema-1.0.2.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page