A database migration utility for Postgres
Project description
postcar
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file postcar-0.0.7.tar.gz.
File metadata
- Download URL: postcar-0.0.7.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff17a551ae517717c7250bedaeed0c48460c98beb3a20b5e07a2181a5aac08f1
|
|
| MD5 |
d70fb48eff4894d264b81596b9365b6e
|
|
| BLAKE2b-256 |
f4cb768172899c9aed9bff275145355a0f66e9ab40286e3c9e8eced891662456
|
Provenance
The following attestation bundles were made for postcar-0.0.7.tar.gz:
Publisher:
release.yml on tunnelworks/postcar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
postcar-0.0.7.tar.gz -
Subject digest:
ff17a551ae517717c7250bedaeed0c48460c98beb3a20b5e07a2181a5aac08f1 - Sigstore transparency entry: 153679272
- Sigstore integration time:
-
Permalink:
tunnelworks/postcar@ac68096a461ad7303a7a379b94680dd6ffc9ef1b -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/tunnelworks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ac68096a461ad7303a7a379b94680dd6ffc9ef1b -
Trigger Event:
push
-
Statement type:
File details
Details for the file postcar-0.0.7-py3-none-any.whl.
File metadata
- Download URL: postcar-0.0.7-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c562a22988a949e1701258040e83e3e8b33f7abef1f594ab166c9909c4226ec5
|
|
| MD5 |
3b6a8338d01e51cdc64b8c9fe2fc6ffe
|
|
| BLAKE2b-256 |
de66a40f17eb23de58fd1a04bfc9edb200c2e87c6a355db8eaa31d873c2c0ae1
|
Provenance
The following attestation bundles were made for postcar-0.0.7-py3-none-any.whl:
Publisher:
release.yml on tunnelworks/postcar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
postcar-0.0.7-py3-none-any.whl -
Subject digest:
c562a22988a949e1701258040e83e3e8b33f7abef1f594ab166c9909c4226ec5 - Sigstore transparency entry: 153679273
- Sigstore integration time:
-
Permalink:
tunnelworks/postcar@ac68096a461ad7303a7a379b94680dd6ffc9ef1b -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/tunnelworks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ac68096a461ad7303a7a379b94680dd6ffc9ef1b -
Trigger Event:
push
-
Statement type: