根据文档,alembic 的模板可以指定为alembic init --template pylons ./scripts
. python_path/lib/python2.7/site-packages/alembic/templates
但 alembic 仅在其根目录 ( )的一个文件夹中搜索模板。
有没有办法运行自定义模板?问题的想法 - 项目设置的自动化,例如避免任何手工更改(如编辑env.py
文件)。
根据文档,alembic 的模板可以指定为alembic init --template pylons ./scripts
. python_path/lib/python2.7/site-packages/alembic/templates
但 alembic 仅在其根目录 ( )的一个文件夹中搜索模板。
有没有办法运行自定义模板?问题的想法 - 项目设置的自动化,例如避免任何手工更改(如编辑env.py
文件)。
正如我在 Alembic 源代码中看到的,无法自定义模板目录位置。模板目录由Config.get_template_directory()获取并由list_templates()使用。
虽然您可以尝试使用猴子补丁:
from alembic.config import Config
def get_template_directory(self):
return "my/custom/template/directory"
Config.get_template_directory = get_template_directory
# Invoke Alembic code
PS 我想知道为什么 Alembic 不使用入口点来收集可用模板。