add rev_id generator function feature to environment.configure(), will apply to revision, merge
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 55/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python, sqlalchemy
调研方向
从 alembic/command.py 开始,将第 194-320 行附近的 revision() 与第 382-439 行附近的 merge() 进行比较。跟踪 merge() 如何构造其 RevisionContext,以及 alembic/autogenerate/api.py 如何处理 process_revision_directives。完成标准是 merge API 一致地接受并转发可选回调,为新参数提供覆盖,并保留现有行为。
由索引模型根据 Issue 内容生成。
描述
Describe the use case
The merge command should support the process_revision_directives parameter in its programmatic API, consistent with the revision command.
Currently, while both commands support revision_environment (which runs env.py), only the revision command accepts a programmatic process_revision_directives parameter. This creates an API
inconsistency when using Alembic programmatically to customize revision generation logic for merge operations.
Databases / Backends / Drivers targeted
All databases - this is a general Alembic API feature request.
Example Use
Current behavior - revision command (works):
from alembic import command
from alembic.config import Config
config = Config("alembic.ini")
def my_process_revision_directives(context, revision, directives):
"""Custom revision ID generation logic"""
for directive in directives:
directive.rev_id = generate_custom_id() # Custom logic
This works - process_revision_directives parameter is supported
command.revision(
config,
message="Add new feature",
process_revision_directives=my_process_revision_directives
)
Desired behavior - merge command (currently doesn't work):
# This fails with TypeError - process_revision_directives is not accepted
command.merge(
config,
revisions=("head1", "head2"),
message="Merge branches",
process_revision_directives=my_process_revision_directives # ❌ Not supported
)
Current workaround:
Users must configure the hook in env.py, which affects all operations:
# env.py
def process_revision_directives(context, revision, directives):
# This applies to ALL revision/merge commands
for directive in directives:
directive.rev_id = generate_custom_id()
context.configure(
process_revision_directives=process_revision_directives
)
This workaround doesn't allow per-command customization when using the programmatic API.
Proposed API:
def merge(
config: Config,
revisions: _RevIdType,
message: Optional[str] = None,
branch_label: Optional[_RevIdType] = None,
rev_id: Optional[str] = None,
process_revision_directives: Optional[ProcessRevisionDirectiveFn] = None, # NEW
) -> Optional[Script]:
"""
:param process_revision_directives: optional callable that allows
programmatic customization of the revision directives. Same signature
as the callable described at
:paramref:`.EnvironmentContext.configure.process_revision_directives`
"""
# Implementation already uses RevisionContext internally,
# just need to accept and pass through the parameter
Use cases:
- Different logic for merges vs regular revisions: Apply special revision ID schemes or metadata only to merge commits
- CI/CD automation: Programmatic scripts that customize merge behavior without modifying env.py
- Multi-tenant environments: Different revision ID generation based on runtime context
Additional context
- The merge command already uses RevisionContext internally (since 1.12.0 when revision_environment support was added via #1299)
- The implementation would be minimal - just accepting and passing through the parameter
- This would make the API consistent between revision and merge commands
- The parameter would be optional and backward-compatible
Reference:
- alembic/command.py::revision() - Lines 194-320 (already supports this parameter)
- alembic/command.py::merge() - Lines 382-439 (should support this parameter)
- alembic/autogenerate/api.py::RevisionContext - Already supports process_revision_directives
Versions.
- OS: macOS (but applies to all platforms)
- Python: 3.9+
- Alembic: 1.16.5 (latest)
- SQLAlchemy: 1.4+/2.0+
- Database: All
- DBAPI: All
- 主要语言
- Python
- 星标
- 4.5k
- 派生
- 391
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sqlalchemy/alembic 的其他 Issue
-
on_version_apply is typed as a positional callable, but alembic calls it with keyword arguments可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
sqlalchemy/alembic#1883 · 1 条评论 ·
-
Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated script可能重新可做 @ApparentlyTejas 于 21 天前认领,目前没有进行中的 PR。 未关闭bug command interface
难度 2/5 1-3 小时 新手友好度 70/100
sqlalchemy/alembic#1879 · 3 条评论 ·
-
bug pep 484
难度 2/5 1-3 小时 新手友好度 74/100
sqlalchemy/alembic#1341 · 2 条评论 ·
-
autogenerate - detection bug
难度 2/5 1-3 小时 新手友好度 74/100
sqlalchemy/alembic#1121 · 3 条评论 ·
-
Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0可能重新可做 关联的 PR 已关闭且未合并。 未关闭autogenerate - defaults bug regression
难度 3/5 1-2 天 新手友好度 50/100
sqlalchemy/alembic#1877 · 1 条评论 ·
查看 sqlalchemy/alembic 的全部 Issue
相似的 Issue
-
SslLibrary crashes with unhandled OSError: port/proto not found on non-standard SSL ports可能已有人在做 @himanchalkaushale 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
OWASP/Nettacker#1884 · 1 条评论 ·
维护者通常 1 天内回复
-
A-connection-core C-enhancement
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
aws-samples/sample-per-model-bedrock#869 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 82/100
fzn0x/watchtower#17 ·