Skip to main content

A CLI for managing postgres DB migrations

Project description

lonny_pg_migrate

A CLI for managing postgres DB migrations.

Installation

pip install lonny_pg_migrate

Usage

First, we must create a MigrationRunner object. We can do this like:

from lonny_pg_migrate import MigrationRunner

# Get a 'lonny_pg' DB connection.
db = get_lonny_pg_connection()

runner = MigrationRunner(db)

To define a migration, we can simply now do:

# N.B. sort_key is optional and defaults to the slug.
@runner.migrate("migration_0", sort_key = "0")
def migration_0(db):
    do_some_action(db)

To perform the migration, we can either invoke the runner directly using:

# This will wipe the database
runner.drop()
# This will run - in order of sort_key, all migrations which haven't yet run.
runner.migrate()

Or via the CLI using:

pg_migrate path.to.module:runner_var

As above, drop functionality is supported by passing in a --drop argument.

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

lonny_common_pg_migrate-0.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

lonny_common_pg_migrate-0.1.0-py3-none-any.whl (4.9 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