alembic-autoseq 🛡️
Alembic AutoSeq is a lightweight, zero-overhead, production-ready Python package that eliminates migration collisions, duplicate sequence numbers (0001, 0002), and multi-head branch conflicts in Alembic.
Designed specifically for engineering teams developing features in parallel on shared or local databases.
⚡ The Real-World Problem
When multiple developers branch off the same base migration:
- Duplicate Sequence Numbers: Dev A creates
0004_add_users.pyand Dev B creates0004_add_orders.py. - Multi-Head Crash: Running
alembic upgrade headcrashes with:alembic.util.exc.CommandError: Multiple head revisions are present for given argument 'head'; please specify a revision or 'heads'
- Database Drift: When testing on a shared dev database, the database gets stamped with a revision from another branch, breaking migrations for everyone else on the team.
- Production Safety Constraint: You cannot rewrite or renumber historical migrations because production already has historical revision hashes stored in
alembic_version.
alembic-autoseq solves this non-destructively: it auto-reconciles branch revisions in a single line without breaking past migrations or production state.
🚀 Installation
pip install alembic-autoseq
💡 Quick Start (1-Line Integration)
In your alembic/env.py:
import alembic_autoseq
# Automatically heals multi-heads and re-sequences branch revisions before Alembic runs
alembic_autoseq.guard()
That's it! Now when any developer runs alembic upgrade head, conflicting branch revisions are automatically rebased and re-linked in place.
🛠️ CLI Usage
alembic-autoseq includes a command-line interface for local workflows and CI/CD pipelines:
1. Pre-Merge Validation (check)
Checks if your migration history is clean and linear. Exits with code 1 if conflicts or multi-heads exist.
alembic-autoseq check
2. Auto-Rebase (rebase)
Automatically re-links branch migrations onto the latest upstream head and increments sequence numbers:
alembic-autoseq rebase
3. ASCII History Visualizer (tree)
Prints an ASCII tree of the migration DAG directly in your terminal:
alembic-autoseq tree
Example output:
📂 Versions Directory: /path/to/alembic/versions
Total Migrations: 5 | Heads: 1
└── [0001] 0001 -> 0001_init.py
└── [0002] 0002 -> 0002_accounts.py
└── [0003] 0003 -> 0003_profiles.py
└── [0004] 0004 -> 0004_users.py
└── [0005] 0005 -> 0005_orders.py (HEAD)
✨ DAG is clean and linear.
⚙️ Advanced Configuration
Python API Options
from alembic_autoseq import guard
guard(
directory=None, # Optional path to versions/ (auto-detected by default)
auto_heal=True, # Auto-rebase branch revisions (set False for strict check)
strict=False, # Raise AlembicConflictError if conflicts remain
quiet=False, # Suppress informative console messages
digits=4, # Number of digits for prefix padding (e.g. 4 -> '0001', 3 -> '001')
)
Pre-Commit Hook Integration
Add to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/jagadeesh88705/alembic_autoseq
rev: v0.1.0
hooks:
- id: alembic-autoseq-check
🏗️ How It Works Behind the Scenes
📖 Deep Dive: For a full technical walkthrough of how
alembic-autoseqhandles shared database drift and parallel branch collisions, see UNDER_THE_HOOD.md.
alembic_autoseq.guard()
│
┌───────────────────────┴───────────────────────┐
▼ ▼
1. Scan Migration Files 2. Auto-Discover Layout
• Python AST metadata parsing • Inspects alembic.ini & versions/
• Sequence number & digit width detection • Zero runtime code execution
│ │
└───────────────────────┬───────────────────────┘
▼
3. DAG Conflict Detection
┌──────────────────────────────┐
│ Are there multiple heads? │
│ Are sequence IDs duplicated? │
│ Are down_revisions broken? │
└──────────────┬───────────────┘
│
┌───────────────────┴───────────────────┐
No Conflicts Conflicts Found
│ │
▼ ▼
Proceed normally 4. Automatic Rebase Engine
• Detects active branch migration
• Auto-increments sequence ID (0004 -> 0005)
• Updates down_revision to upstream head
• Atomically updates file & in-memory map
│
▼
Proceed with Alembic Upgrade!
🧪 Running the Test Suite
git clone https://github.com/jagadeesh88705/alembic_autoseq.git
cd alembic_autoseq
python -m venv .venv
source .venv/bin/activate # or .\.venv\Scripts\activate on Windows
pip install -e .[dev]
pytest -v
📄 License
This project is licensed under the MIT License.
Metadata
Release files for alembic-autoseq 0.1.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 |
|---|---|---|---|---|
| alembic_autoseq-0.1.0.tar.gz | 20.4 kB | With provenance | Details for alembic_autoseq-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alembic_autoseq-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for alembic_autoseq-0.1.0-py3-none-any.whl |
Total release size: 37.8 kB
Release files / alembic_autoseq-0.1.0.tar.gz
| Download URL | alembic_autoseq-0.1.0.tar.gz |
|---|---|
| Size | 20.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c443b74082cc53db2c97512ffe55b7bb41c6f156f71af4a10150c1eaeb0c4813
|
|
BLAKE2b-256 checksum How to use checksums |
191b30ffe4a55881a692faab67490dd2db594f0f88722d09f67ba967995be639
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / alembic_autoseq-0.1.0-py3-none-any.whl
| Download URL | alembic_autoseq-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ec3c2e372d480896a3949d3bcf35d06e25c906a106d07f16734b105172c4b2f
|
|
BLAKE2b-256 checksum How to use checksums |
b3fc550b11fabb768adbd9f37efcbf2052c99bc8df68af353335d440050559f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for alembic-autoseq 0.1.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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for alembic_autoseq-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA 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.