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.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560ee90f69e1d8487865afe64a85f9cbfb28061ebb685866b079a455621fd100 |
|
MD5 | 91af24a038a736c440197aadd42cf430 |
|
BLAKE2b-256 | 99ad9ca2c2537a806752cbe7a1bdcfeb9cf6cfe136a9a789714fade82e1f9b0e |