烧瓶迁移在生产中的使用 [英] flask-migrate usage in production

查看:76
本文介绍了烧瓶迁移在生产中的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于在进行部署时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.

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

Typically as in https://github.com/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.

这篇关于烧瓶迁移在生产中的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆