Skip to content

feat: expose the parsed migration view - #48

Merged
mergify[bot] merged 1 commit into
Mergifyio:mainfrom
RizhongLin:expose-parsed-migration-view
Aug 11, 2026
Merged

feat: expose the parsed migration view#48
mergify[bot] merged 1 commit into
Mergifyio:mainfrom
RizhongLin:expose-parsed-migration-view

Conversation

@RizhongLin

@RizhongLin RizhongLin commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Tooling built around this library has to re-implement parsing and ordering, or reach into private helpers, to answer questions the library already answers internally: which migrations are dynamic, what order git puts them in, and what the generated artifact is called.

This exports the pieces that answer those questions without building a chain:

  • parse_versions_dir(versions_dir) returns the migrations as MigrationFile objects in git add order. A thin wrapper over the existing git-order and parse steps.
  • MigrationFile is already a public class, it simply was not exported.
  • CHAIN_FILENAME so callers locating or cleaning up the generated file do not hardcode "revision_chain.json". The private _CHAIN_FILENAME is removed rather than aliased: its only two references were internal to _chain.py, both updated here, and a leading-underscore name carries no compatibility guarantee.

Concretely, this is what I needed to write the --check reporting in #47: it wants classification and git order, but not a chain. It is useful on its own for anything that inspects a versions directory, such as a CI lint or a migration linter.

Notes for review

  • Purely additive. No existing behavior changes and all pre-existing tests pass unmodified.
  • parse_versions_dir raises RuntimeError when git history is unavailable, rather than returning None as the private helper does, because ordering cannot be recovered from the directory alone and a silent wrong order is worse than an error. Note this differs from build_chain, which first falls back to a chain file.
  • Independent of fix: report migrations chained behind the deployed head #47; either can merge first. They touch neighbouring lines in __init__.py, the README API section and the end of the test file, so whichever lands second needs a trivial rebase.
  • Tested on 3.11 / 3.12 / 3.13 / 3.14.

Tooling built around the chain currently has to re-implement parsing and
ordering, or reach into private helpers, to answer questions the library
already answers internally: which migrations are dynamic, what order git
puts them in, and what the generated artifact is called.

Export the pieces that answer those questions without building a chain:
MigrationFile, parse_versions_dir() and CHAIN_FILENAME (promoted from
_CHAIN_FILENAME, whose only two references were internal).

parse_versions_dir() returns raw git add order, which is deliberately not
the order the built chain walks, since a hybrid is re-parented to sit
after the revision it hardcodes. It also does not fall back to a chain
file the way build_chain does: that file records only the mapping, not
classification or ordering, so there would be nothing to reconstruct
from. Both are documented, along with git_sequence being a position
within one parse rather than a property of the file.
Copilot AI lite review requested due to automatic review settings August 8, 2026 20:01
@mergify
mergify Bot deployed to Mergify Merge Protections August 8, 2026 20:01 Active
@mergify

mergify Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 6 merge protections satisfied — ready to merge.

Show 6 satisfied protections

🟢 🤖 Continuous Integration

  • all of:
    • check-success=all-greens

🟢 👀 Review Requirements

  • any of:
    • #approved-reviews-by>=1
    • author = dependabot[bot]
    • author = mergify-ci-bot

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|internal|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?!?:

🟢 🔎 Reviews

  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

  • body ~= (?ms:.{48,})

🟢 🚦 Auto-queue

When all merge protections are satisfied, this pull request will be queued automatically.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes a “parsed migration view” as part of the public API, so external tooling can inspect migration classification and git add-order without building a revision chain.

Changes:

  • Add parse_versions_dir(versions_dir) returning ordered MigrationFile objects (git add-order, not traversal order).
  • Export MigrationFile and a public CHAIN_FILENAME constant for consumers.
  • Add README API documentation and unit tests covering ordering, classification, and error behavior without git history.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
alembic_git_revisions/_chain.py Introduces parse_versions_dir, promotes CHAIN_FILENAME, and updates chain file usage to the public constant.
alembic_git_revisions/__init__.py Re-exports parse_versions_dir, MigrationFile, and CHAIN_FILENAME from the package root.
README.md Documents the new public API surface (parse_versions_dir, MigrationFile, CHAIN_FILENAME) and clarifies ordering semantics.
tests/test_chain.py Adds tests validating classification, deterministic ordering (including uncommitted files), and erroring when git history is unavailable.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread alembic_git_revisions/_chain.py
@RizhongLin

Copy link
Copy Markdown
Contributor Author

One open question, kept out of the description since that becomes the commit message on merge:

  • parse_versions_dir raises where build_chain falls back. build_chain prefers revision_chain.json and only raises when both it and git are missing; parse_versions_dir raises as soon as git is unavailable. The reason is that the chain file records only {revision: down_revision}, so it carries neither the classification nor the ordering this returns, and there is nothing to reconstruct from. I would rather raise than hand back a plausible wrong order, but if you would prefer the two to behave alike I am happy to change it.
  • _CHAIN_FILENAME. Removed rather than aliased, since its only two references were internal. If you would rather keep an alias for anyone who reached into the private module, say so and I will restore it.

@mergify

mergify Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-08-11 12:52 UTC · Rule: default · triggered by merge protections
  • Checks skipped · PR is already up-to-date
  • Merged2026-08-11 12:53 UTC · at a39bbc854f8a3ca0a460945be386ef5921e7cf90 · squash

This pull request spent 28 seconds in the queue, including 6 seconds running CI.

Required conditions to merge

@mergify mergify Bot added the queued label Aug 11, 2026
@mergify
mergify Bot merged commit 6e88648 into Mergifyio:main Aug 11, 2026
8 checks passed
@mergify mergify Bot removed the queued label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants