Skip to main content

A database migration utility for Postgres

Project description

postcar

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install postcar

License

postcar is distributed under the terms of the Apache-2.0 license.

Usage

Migrations

Migration packages

Each migration package needs to be importable. Migration modules must be named starting with a four digit sequence number, followed by an underscore, and a (short) description.

Here's a sample structure of a migration directory:

migrations
├── __init__.py
├── 0001_init.py
├── 0002_authorization.py
└── 0003_create_extensions.py

Migration modules

The migration modules must contain a class named Migration, which must inherit from postcar.Migration.

A minimal migration file might look as follows:

import postcar


class Migration(postcar.Migration):
    def get_forward(self) -> str:
        return """
            create extension pg_trgm;
        """

    def get_rollback(self) -> str:
        return """
            drop extension pg_trgm;
        """

CLI

The package comes with a minimal CLI.

See postcar --help for available commands.

Configuration

NOTE: this isn't implemented yet, so use the CLI for the time being

Sample configuration file:

# postcar.conf.py

import os
from postcar import config


connection = config.ConnectionInfo(
    host="127.0.0.1",
    port=5432,
    dbname="mydb",
    username="postcar",
    password=os.getenv("POSTGRES_PASSWORD"),
)

namespace = "_bookkeeping"

packages = ["myapp.migrations"]

Configuration parameters

The below table is an exhaustive list of the available parameters. More detailed descriptions below the table.

Name CLI Type Default
-c/--conf Optional[str] None
connection.host -H/--host Optional[str] None
connection.port -p/--port Optional[int] None
connection.dbname -D/--dbname Optional[str] None
connection.username -U/--user Optional[str] None
connection.password -P/--password Optional[str] None
namespace -s/--namespace str "_postcar"
packages Sequence[str] ()

connection.[x]

Connection info parameters, very similar to the Postgres defaults.

namespace

The database schema to use for bookkeeping.

packages

The migration packages to run migrations for by default.

Development

Internal migrations

For the sake of consistency, and keeping things "simple", internal schema migrations are designated by minor versions. In short, a bump from 1.2.3 to 1.2.4 must never migrate the internal schema, whereas 1.2.3 to 1.3.0 or 2.0.0 may.

Ultimately, the goal is to enable effortless upgrades between versions, without unnecessarily complicated manual intervention.

Regardless: this is a rather experimental package, at least until version 1.0.0. Until then: expect things to break, without any guarantees.

TODO

  • Implement rollback
  • Migration dependencies
  • CLI command for generating a new migration skeleton

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

postcar-0.0.5.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postcar-0.0.5-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file postcar-0.0.5.tar.gz.

File metadata

  • Download URL: postcar-0.0.5.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for postcar-0.0.5.tar.gz
Algorithm Hash digest
SHA256 5f3733b58e920324e956b0c76608e0c059e21a9c4dc3df2916fe8051ef2b43b1
MD5 fab55f18528a8c658800e4808d55b4fc
BLAKE2b-256 aee3ec7b4b2243e756a5969ffc9935b0920c35242f81209200f404c5f388b071

See more details on using hashes here.

Provenance

The following attestation bundles were made for postcar-0.0.5.tar.gz:

Publisher: release.yml on tunnelworks/postcar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file postcar-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: postcar-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for postcar-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e46bb9330647c3369c6d5567f3470e7b4e3a567e8caf4f3a2fc016b12708aa33
MD5 ab34c807223a0f52a18c315d97b15df3
BLAKE2b-256 3041d0127db59125a7163b7f9d10165b881209d815ff74d032a5745c4f931bed

See more details on using hashes here.

Provenance

The following attestation bundles were made for postcar-0.0.5-py3-none-any.whl:

Publisher: release.yml on tunnelworks/postcar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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