Add configurable revision_map_class option#1805
Open
jasonwbarnett wants to merge 1 commit intosqlalchemy:mainfrom
Open
Add configurable revision_map_class option#1805jasonwbarnett wants to merge 1 commit intosqlalchemy:mainfrom
jasonwbarnett wants to merge 1 commit intosqlalchemy:mainfrom
Conversation
Allow users to specify a custom RevisionMap subclass via the revision_map_class configuration option. This enables external packages to implement custom revision ordering logic (e.g. ordering based on git history) without changes to Alembic core. The option accepts a dotted Python path in "module:ClassName" format and can be set in alembic.ini or pyproject.toml. RevisionMap is now also exported from the alembic.script package for convenient subclassing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1804
Summary
revision_map_classconfiguration option toScriptDirectory, allowing a customRevisionMapsubclass to be specified viaalembic.iniorpyproject.tomlusing a dotted Python path (e.g.mypackage.custom:CustomRevisionMap)resolve_dotted_name()utility for resolving"module:ClassName"strings to Python objects, with clear error messages for import/attribute failuresRevisionMapfrom thealembic.scriptpackage for convenient subclassingMotivation
See #1804 for full context. In short: there is currently no way to customize how Alembic orders concurrent, unrelated migrations (multiple heads) without monkey-patching. This small change (one new keyword argument with a
Nonedefault, entirely opt-in) opens up an extension point for external packages to implement custom ordering — such as git-history-based ordering — by subclassingRevisionMapand overriding_topological_sort().Changes
alembic/util/pyfiles.py: Newresolve_dotted_name()utilityalembic/script/base.py: Newrevision_map_classparameter onScriptDirectory.__init__()andfrom_config(), with subclass validationalembic/script/__init__.py: ExportRevisionMapfor convenient subclassingrevision_map_classoption in all ini/toml templatesdocs/build/unreleased/revision_map_class.rstTest plan
resolve_dotted_name()tests (colon format, dot format, error cases)revision_map_classvia constructor and viafrom_config()RevisionMapproperly exported fromalembic.scripttest_config.pysuite passes (75 tests)