Skip to main content

SQL migrations for projects using PostgreSQL

Project description

pgmigrations

Build Status Coverage Status Code style: black

SQL migrations for projects using PostgreSQL

Example Usage

Initialise the migrations

pgmigrations init

This will create a directory called migrations in the current working directory

Create a migration

pgmigrations create <tag>

This will create a skeleton migration in the migrations directory. The migration will consist of a directory with the name <timestamp>_migrations_<tag>, for example 20200701_1030_migrations_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> [--path <colon separated list of migration locations>]

or

export PGMIGRATIONS_DSN=<dsn>
export PGMIGRATIONS_PATH=<colon separated list of migration locations>
pgmigrations apply

This will apply any unapplied migrations. Each migration is applied in an atomic transaction.

Rollback a migration

pgmigrations rollback --dsn=<dsn> [--path <colon separated list of migration locations>]

or

export PGMIGRATIONS_DSN=<dsn>
export PGMIGRATIONS_PATH=<colon separated list of migration locations>
pgmigrations rollback <name>

This will rollback an already applied migration.

Project details


Download files

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

Source Distribution

pgmigrations-0.0.13.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

pgmigrations-0.0.13-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page