asyncpg-trek: simple migrations for asyncpg
A simple library for managing migrations.
Target audience
Me. But maybe if you use [asyncpg] and prefer to write migrations as raw SQL (i.e. you're not using SQLAlchemy/Alembic) then you as well.
Features
- async: migrations usually don't benefit from being async, but you benefit from using the same database driver in as your application uses (only [asyncpg] is supported).
- simple: you just create
.sqlor Python files in a folder of your choosing and point this tool at that folder. No need to fight a new API to write migrations in. - API centric: there is no CLI to figure out, you decide how migrations get called, you control how the database connection gets created. This makes it trivial to run migrations in tests, wrap them in a CLI or run them via an exposed HTTP endpoint.
- declarative: just specify the version you want and the library figures out if it needs an upgrade, downgrade or no action.
Example usage
from pathlib import Path
import asyncpg
from asyncpg_trek import plan, execute, Direction
from asyncpg_trek.asyncpg import AsyncpgBackend
MIGRATIONS_DIR = Path(__file__).parent / "migrations"
async def migrate(
conn: asyncpg.Connection,
target_revision: str,
) -> None:
backend = AsyncpgBackend(conn)
async with backend.connect() as conn:
planned = await plan(conn, backend, MIGRATIONS_DIR, target_revision=target_revision, direction=Direction.up)
await execute(conn, backend, planned)
You could make this an entrypoint in a docker image, an admin endpoint in your API or a helper function in your tests (or all of the above). How you run your migrations depends on the complexity of your system. For example, for simple systems it may be easy to run migrations on app startup based on a hardcoded revision. For more complex systems you may want to run migrations manually or via an admin API.
See this release on GitHub: v0.4.0
Metadata
Release files for asyncpg-trek 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asyncpg_trek-0.4.0.tar.gz | 7.8 kB | Without provenance | Details for asyncpg_trek-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncpg_trek-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for asyncpg_trek-0.4.0-py3-none-any.whl |
Total release size: 17.3 kB
Release files / asyncpg_trek-0.4.0.tar.gz
| Download URL | asyncpg_trek-0.4.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a04c096ae896913d369329a96253b309bf095b1d4cd029ecad43c19dc5cf4da
|
|
BLAKE2b-256 checksum How to use checksums |
15df3dbad74b63ca14a47083849842a5ad6964a2b78d91ae09ae28e0f35f4971
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1023-azure
|
Release files / asyncpg_trek-0.4.0-py3-none-any.whl
| Download URL | asyncpg_trek-0.4.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31348799d67704ffd0e4c0a0ab419b0687449271796214ca7a08c5e1ef68925e
|
|
BLAKE2b-256 checksum How to use checksums |
b081d79224c679505e5224f921aaec09a6d667959b04fb35cd94d942e032c638
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1023-azure
|
Security for asyncpg-trek 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.