SQL migrations for projects using PostgreSQL
Project description
pgmigrations
SQL migrations for projects using PostgreSQL
Example Usage
Initialise the migrations
pgmigrations init --dsn <dsn> [--base-directory <base directory>]
or
export PGMIGRATIONS_DSN=<dsn>
export PGMIGRATIONS_BASE_DIRECTORY=<base directory>
pgmigrations init
This will create a directory called migrations
and will create a table called pgmigrations
in the database
to store the migration history.
Create a migration
pgmigrations create --dsn <dsn> [--base-directory <base directory>] <tag>
or
export PGMIGRATIONS_DSN=<dsn>
export PGMIGRATIONS_BASE_DIRECTORY=<base directory>
pgmigrations create <tag>
This will create a skeleton migration in the migrations
directory. The migration will consist of a directory with
the name <timestamp>_tag
, for example 20200701_1030_first_migration
, which contains two files;
apply.sql
and rollback.sql
.
As the names suggests, apply.sql
will be executed when the migration is applied and rollback.sql
will be
executed if the migraiton is rollbacked.
Apply migrations
pgmigrations apply --dsn=<dsn> [--base-directory <base directory>]
or
export PGMIGRATIONS_DSN=<dsn>
export PGMIGRATIONS_BASE_DIRECTORY=<base directory>
pgmigrations apply
This will apply any unapplied migrations. Each migration is applied in an atomic transaction.
Rollback a migration
pgmigrations rollback --dsn=<dsn> [--base-directory <base directory>] <name>
or
export PGMIGRATIONS_DSN=<dsn>
export PGMIGRATIONS_BASE_DIRECTORY=<base directory>
pgmigrations rollback <name>
This will rollback an already applied migration.
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
Built Distribution
Hashes for pgmigrations-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd5a5efce4266cb93432cc94a9df709a72a8873729ab4b65c75a18c8f6eb771f |
|
MD5 | d1d71805ae3839a54b0f2f88a9a35ba3 |
|
BLAKE2b-256 | 93515f1bcb50c1e2ae46aef6beb23016c29c3d0c2680f544907809d25d8dc0a2 |