Schema migration made easy
Project description
# 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`
```bash
pip3 install dbschema
```
### Create a config file
Create the file `~/.dbschema.yml` and add your databases configuration. [See example](dbschema_sample.yml)
### 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](schema/mysql.sql) or [PostgreSQL](schema/postgresql.sql).
## 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.
```
/path/to/migrations/db1/
|-- migration1/
| |-- up.sql
|-- migration2/
| |-- up.sql
|...
/path/to/migrations/db2/
|-- migration1/
| |-- up.sql
|-- migration2/
| |-- up.sql
|...
```
## Usage
```bash
dbschema
# or
dbschema --config /path/to/config.yml
```
`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`
```bash
pip3 install dbschema
```
### Create a config file
Create the file `~/.dbschema.yml` and add your databases configuration. [See example](dbschema_sample.yml)
### 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](schema/mysql.sql) or [PostgreSQL](schema/postgresql.sql).
## 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.
```
/path/to/migrations/db1/
|-- migration1/
| |-- up.sql
|-- migration2/
| |-- up.sql
|...
/path/to/migrations/db2/
|-- migration1/
| |-- up.sql
|-- migration2/
| |-- up.sql
|...
```
## Usage
```bash
dbschema
# or
dbschema --config /path/to/config.yml
```
Project details
Release history Release notifications | RSS feed
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.0.0.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for dbschema-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90aaecf6af477e64d14b792c9d3e5664fe465e0b8a5ea29e118082b386767327 |
|
MD5 | 4c593670b884713c36a20e7421480706 |
|
BLAKE2b-256 | 214e49e3a88d82f37931d8b60c1f3e59896765087ad26ef5be089faa1fdf36ca |