python - alembic - 使用包资源作为 script_location 的示例

标签 python sqlalchemy alembic

我正在尝试将 Alembic 迁移作为 python 包分发的一部分。由于将安装此发行版,Alembic 脚本目录(包含迁移)最终将被复制到 python 包文件夹。在这种情况下,我如何告诉 Alembic 在哪里可以找到这个目录?

在 Alembic 文档中,它说 migration 目录可以在 config.ini 文件中指定为包引用:

  • script_location - this is the location of the Alembic environment. It is normally specified as a filesystem location, either relative or absolute. If the location is a relative path, it’s interpreted as relative to the current directory.

(剪断)

For support of applications that package themselves into .egg files, the value can also be specified as a package resource, in which case resource_filename() is used to find the file (new in 0.2.2). Any non-absolute URI which contains colons is interpreted here as a resource name, rather than a straight filename.

文档没有提供更多信息或示例。

有没有人成功实现过这个?您究竟如何将 migration scripting_folder 转换为“包资源”?那么您如何告诉 alembic 在哪里可以找到它?

最佳答案

例如:

script_location = mypackage:somewhere/inside/it

这要求您将迁移包含在您的发行版中:您应该查看您的 MANIFEST.in 文件等。

关于python - alembic - 使用包资源作为 script_location 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25798447/

相关文章:

python - 艰难地学习 Python,练习 35 : placing a regular expression

Python 操作系统错误 : [Errno 98] Address already in use but no port is used

python - Gtk3:设置固定的窗口大小(小于子部件请求的大小)

python - 属性错误 : 'list' object has no attribute '_sa_instance_state'

python - 如何从 SQLAlchemy 中的多对多(辅助)表中删除记录?

python - 如何将 Mixins 与 SQLAlchemy 结合使用来简化查询和过滤操作?

python - `alembic revision --autogenerate` 产生冗余外键迁移

python - 在Python中的正则表达式中使用变量

python - 如何通过代码使用 Python Alembic 运行迁移?

sqlalchemy - Alembic:自动生成迁移时如何忽略其他产品的数据库表