我正在尝试将 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/