Async-aware alembic env.py helper for mgf-common consumers — one-call configure_env replaces ~40 lines of boilerplate. Sibling of mgf-common under the mgf.* namespace; pairs with mgf-sqlalchemy.
Project description
mgf-alembic — async-aware alembic env.py helper for mgf-common consumers
Sibling of
mgf-common+mgf-sqlalchemyunder themgf.*namespace. Houses the async-aware alembicenv.pyhelper that previously lived undermgf.common.alembic.*— extracted at mgf-common v0.30 / mgf-alembic v0.1 (paired with mgf-sqlalchemy v0.1) per the federation split plan.
What this provides
| Submodule | What |
|---|---|
mgf.alembic |
configure_env — one call replaces the ~40-line env.py boilerplate. Auto-detects sync vs async drivers from the URL prefix (postgresql+asyncpg://, sqlite+aiosqlite://, etc.). Plumbs compare_type, compare_server_default, naming_convention, include_object, include_schemas through to alembic.context.configure. |
include_object / include_schemas were added per
PAPER-22
in mgf-common v0.19; carried over to mgf-alembic v0.1 unchanged.
Install
pip install mgf-alembic
# Or with the test extra (aiosqlite for async-driver round-trip tests):
pip install 'mgf-alembic[test]'
Pulls in mgf-common, mgf-sqlalchemy, and alembic>=1.13
automatically.
Quick start — the entire env.py
# alembic/env.py
from mgf.alembic import configure_env
from myapp.config import MyAppSettings
from myapp.db.base import Base
settings = MyAppSettings()
configure_env(
database_url=settings.database_url,
target_metadata=Base.metadata,
)
That's the entire file. The helper detects offline vs online mode, runs the migration, disposes the engine cleanly. Async drivers (asyncpg, aiomysql, aiosqlite, asyncmy, async psycopg) are auto-detected; sync drivers fall through the synchronous path.
PostGIS / TimescaleDB: filter extension tables
def _exclude_extensions(obj, name, type_, reflected, compare_to):
return not (type_ == "table" and name in {"spatial_ref_sys"})
configure_env(
database_url=settings.database_url,
target_metadata=Base.metadata,
include_object=_exclude_extensions,
)
alembic revision --autogenerate no longer proposes phantom drops
for extension-managed tables (PostGIS spatial_ref_sys,
TimescaleDB _timescaledb_internal, pgvector housekeeping).
Naming-convention shape
Constraint names auto-generated by op.create_* are otherwise
anonymous and vary across DBs — pin them:
configure_env(
database_url=settings.database_url,
target_metadata=Base.metadata,
naming_convention={
"ix": "ix_%(column_0_label)s",
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s",
},
)
Documentation
docs/recipes/alembic.md— full async-alembic walkthrough.docs/cutover/v0.1.0.md— maiden voyage migration story (the v0.30 split).PUBLIC_API.md— full public surface contract.CHANGELOG.md— release history.
For the federation-wide engineering standards (DESIGN_PRINCIPLES,
ERROR_HANDLING, SECURITY, etc.) see
mgf-common/docs/standards/.
This sibling inherits them by reference; the standards
source-of-truth lives in mgf-common.
Status
🚧 Experimental — every public name is experimental per AP-09.
Promotion to stable happens release-by-release as consumer feedback
in mgf-common/FEEDBACK.md
converges. The 0.x window applies. Pin tightly:
mgf-alembic = ">=0.X.0,<0.Y".
Cross-references
- Filing process for sharp edges: open an entry on
mgf-common/FEEDBACK.mdwith[mgf-alembic]prefix, OR file directly on this repo's Issues → maintainer mirrors into the canonical FEEDBACK.md. - Federation pattern:
mgf-common/docs/design/federation.md. - The split that created this sibling:
mgf-common/docs/release/federation_roadmap.md. - Companion sibling:
mgf-sqlalchemy— async SQLAlchemy engine + sessionmaker + tenant-scoping (paired ship at v0.30; this sibling depends on it).
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 mgf_alembic-0.1.1.tar.gz.
File metadata
- Download URL: mgf_alembic-0.1.1.tar.gz
- Upload date:
- Size: 94.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72394437cd5a816270a9b7e248a4405ba0d5ed6b7daffae250defa5b09d15e51
|
|
| MD5 |
9c3f223894aa4cadc49bef3a257f17e4
|
|
| BLAKE2b-256 |
7e283bbae2054e21b594ca2d92eff62bfdcee436b21c354e0d144cca026afc50
|
File details
Details for the file mgf_alembic-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mgf_alembic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cd32b7856f61cd5148bc98298a43c0265f731a228e54cf358b10abe4b11f4e5
|
|
| MD5 |
d4036686f0438690daaa310ccdc93998
|
|
| BLAKE2b-256 |
da76b5c4e09a4102d4c684166e461e5c1a6e1aba7a49f121df21a3dc9aacaa6c
|