Skip to main content

Database migration tool for asyncpg

Project description

Pogo migrate - asyncpg migration tooling

image image image style tests codecov

pogo-migrate assists with maintaining your database schema (and data if required) as it evolves. Pogo supports migrations written in raw sql, as well as python files (useful when data needs to be migrated).

A migration can be as simple as:

-- a descriptive message
-- depends: 20210101_01_abcdef-previous-migration

-- migrate: apply
CREATE TABLE foo (id INT, bar VARCHAR(20), PRIMARY KEY (id));

-- migrate: rollback
DROP TABLE foo;

Pogo manages these migration scripts and provides command line tools to apply, rollback and show migration history.

Configuration

Add pogo to pyproject.toml

[tool.pogo]
migrations_location = "./migrations"
database_config = "{POSTGRES_DSN}"

If you have an existing environment with separate configuration values for postgres, you can build the DSN in config.

[tool.pogo]
migrations_location = "./migrations"
database_config = "postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{PORTGRES_DATABASE}"

New migrations

To create a new migration use pogo new. This will template out the migration file and open the file in your configured text editor (vi by default).

Supported flags:

  • --sql generate a sql migration (defaults to .py)
  • --no-interactive skip the editor step and just write the migration template to the migrations directory.
$ pogo new -m "a descriptive message"

Testing

To assist in testing, pogo-migrate provides the pogo_migrate.testing module. The apply/rollback methods in the testing module will pick up your configuration and connect to the configured test database based on environment variables, or you can provide a database connection directly.

import asyncpg
import pogo_migrate.testing

@pytest.fixture(scope="session")
async def _engine(config):  # noqa: PT005
    db = await asyncpg.connect(config.my_postgres_dsn)

    await pogo_migrate.testing.apply(db)

    yield

    await pogo_migrate.testing.rollback(db)

Alternatively add pytest-pogo to your test dependencies and use the provided fixture pogo_engine which will apply and rollback your migrations for your test session, like the above example.

Thanks and Credit

Inspiration for this tool is drawn from yoyo and dbmate.

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

pogo_migrate-0.0.12rc0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

pogo_migrate-0.0.12rc0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file pogo_migrate-0.0.12rc0.tar.gz.

File metadata

  • Download URL: pogo_migrate-0.0.12rc0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1017-azure

File hashes

Hashes for pogo_migrate-0.0.12rc0.tar.gz
Algorithm Hash digest
SHA256 3a4a59cc5dabf7dc62fa6dc006d43fe32dc9bc7746532b6f0f904d7d67113364
MD5 7e3763c1c6db4a51b40a50d236af36b3
BLAKE2b-256 c798a88b7298c8a025ab5a0ae9dbd813b7c0794b725349cd5a96715f097edf72

See more details on using hashes here.

Provenance

File details

Details for the file pogo_migrate-0.0.12rc0-py3-none-any.whl.

File metadata

  • Download URL: pogo_migrate-0.0.12rc0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1017-azure

File hashes

Hashes for pogo_migrate-0.0.12rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a31a0b9c454018c3d5dfe7e6e7457a1424f36a6b2ae3c3eee702beaf6a556cb
MD5 7959189ecb82a3ed5efebe5d2add800b
BLAKE2b-256 6e8c93728db378d822be15a36d8d6b9ca87dddb7d45f14b60c7b908fbff9383d

See more details on using hashes here.

Provenance

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