Skip to main content

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

PyPI Python

Shape: Federation sibling of mgf-common. The current mgf-common pin window is shown in this package's PyPI metadata — sourced from pyproject.toml at release time, so this README can't go stale. (Per v2.6 DOC-01 / project-shape taxonomy. PAPER-38.)

Sibling of mgf-common + mgf-sqlalchemy under the mgf.* namespace. Houses the async-aware alembic env.py helper that previously lived under mgf.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

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.

Conformance: L2 per mgf-common/docs/standards/. Per-rule audit ledger: docs/inprogress/MGF_STANDARDS_CONFORMANCE.md. L2 means every federation MUST rule applies, evidenced by the tracker.

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

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

mgf_alembic-0.4.4.tar.gz (162.1 kB view details)

Uploaded Source

Built Distribution

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

mgf_alembic-0.4.4-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file mgf_alembic-0.4.4.tar.gz.

File metadata

  • Download URL: mgf_alembic-0.4.4.tar.gz
  • Upload date:
  • Size: 162.1 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

Hashes for mgf_alembic-0.4.4.tar.gz
Algorithm Hash digest
SHA256 54f90016559fca8673efe9d3e48d3dc1f679d88cf81f2c095cef3c84b9d3ea6f
MD5 9b7c848e7cc6e17df16fbe49ee186f8c
BLAKE2b-256 5d372c9dbc2d6f9a19ee65673e6b8efcc0926d50668c673218496c1c2bcf5096

See more details on using hashes here.

File details

Details for the file mgf_alembic-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: mgf_alembic-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 17.2 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

Hashes for mgf_alembic-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f60b0bd6779cea98cba2ff9cba28f3e7cb55facd32b808d1812a596b3de2e6
MD5 f0b270243be87ee6ea71bc9a2c77f3a1
BLAKE2b-256 7e7524f710af81b6880c12920fe4bf4c35e6859c1b3d5f9aef23e02afdbd797d

See more details on using hashes here.

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