烧瓶迁移在生产中的使用

编程入门 行业动态 更新时间:2024-10-27 12:28:21
本文介绍了烧瓶迁移在生产中的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题是关于在进行部署时flask-migrate的使用模式.要使用您的应用程序设置服务器或Docker容器,您需要创建数据库.

This question is about the usage pattern of flask-migrate when it comes time to deploy. To set up a server or a docker container with your application, you need to create the databases.

通常在 github/miguelgrinberg/flasky 中,迁移文件夹是在项目的根目录中.这是有道理的,但这意味着在生产环境中,如果您将Flask应用程序作为已安装的软件包拉出,则migrations文件夹不可用.

Typically as in github/miguelgrinberg/flasky, the migrations folder is in the root of the project. This makes sense, but it means that in production, the migrations folder is not available if you are pulling the flask application as an installed package.

将迁移文件夹复制到容器中并在其中运行升级,还是完全执行其他操作,是否是正确的模式?这似乎很尴尬,因为我必须使迁移与我从python软件包回购中提取的应用程序版本保持同步.我知道可以完全放弃迁移,而只需执行 db.create_all(),但是如果答案是肯定的,那么我可能会对数据库迁移的目的感到困惑.

Is the correct pattern to copy the migrations folder to the container and run an upgrade there, or something else entirely? This seems awkward, because I would have to keep migrations in sync with the version of the app that I'm pulling from the python package repo. I am aware that it is possible to forego migrations entirely and just do db.create_all(), but if that is the answer, then I may be confused about the purpose of db migrations.

推荐答案

您可以通过两步将文件包含到包中:

You can include files into a package with two-step:

1.在 setup.py 中将 include_package_data 设置为 True :

from setuptools import find_packages, setup setup( name='myapp', version='1.0.0', packages=find_packages(), include_package_data=True, # <-- zip_safe=False, install_requires=[ 'flask', ], )

2.在 MANIFEST.in 中包含文件模式:

2.Include the file pattern in MANIFEST.in:

graft myapp/static graft myapp/templates graft migrations # <--

构建软件包时将包含此文件.有关完整的 MANIFEST.in ,请参见此处.>可用的命令.

This files will be included when you build the package. See here for the full MANIFEST.in command available.

更多推荐

烧瓶迁移在生产中的使用

本文发布于:2023-10-17 22:08:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:烧瓶

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!