【问题标题】:alembic upgrade as heroku releasealembic 升级为 heroku 版本
【发布时间】:2020-12-22 04:24:51
【问题描述】:

我正在拔头发,任何帮助将不胜感激。

我正在尝试在部署我的新应用时运行 alembic 升级。我已经搜索堆栈溢出 3 个小时了,但找不到任何有用的东西。我所做的每一件事都有相同的结果。

这来自我的 heroku 发布日志 FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section

我正在为我的 ProcFile 使用以下内容

release: alembic upgrade head
worker: python bot.py

我正在为我的 env.py 文件使用类似的东西

http://allan-simon.github.io/blog/posts/python-alembic-with-environment-variables/

但这是我的实际情况......这已被修改为 NOTHING 应该尝试打开 alembic.ini

from logging.config import fileConfig

from sqlalchemy import engine_from_config, create_engine
from sqlalchemy import pool

from alembic import context
import logging

logging.basicConfig()

logging.info("running upgrade with logging")

target_metadata = None
import sys
import os

sys.path.insert(0, os.getcwd())
from guildmate.persistence.database_objects import BASE

logging.info("got base")

target_metadata = BASE.metadata

import dotenv

dotenv.load_dotenv()


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    logging.info("running offline")
    database_url = os.getenv("DATABASE_URL")
    logging.info(f"{database_url}")
    connectable = create_engine(database_url)
    context.configure(
        url=database_url,
        target_metadata=target_metadata,
        literal_binds=True,
        dialect_opts={"paramstyle": "named"},
    )

    with context.begin_transaction():
        context.run_migrations()


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    logging.info("running offline")
    database_url = os.getenv("DATABASE_URL")
    logging.info(f"{database_url}")
    connectable = create_engine(database_url)

    with connectable.connect() as connection:
        context.configure(
            connection=connection, target_metadata=target_metadata, compare_type=True
        )

        with context.begin_transaction():
            context.run_migrations()


if context.is_offline_mode():
    run_migrations_offline()
else:
    run_migrations_online()

我正在使用环境变量来配置数据库 url - 尽管它似乎从未到达那里。

升级在本地运行良好,我可以整日运行。

我还没有想出一种方法来从 alembic 或堆栈跟踪或任何东西中获取任何形式的日志记录,所以我什至不知道是哪一行导致了问题。

我唯一能想到的是发布阶段使用的是预发布代码?它甚至没有任何蒸馏器的东西,所以这没有意义。我真的没有想法。

【问题讨论】:

    标签: python heroku sqlalchemy alembic


    【解决方案1】:

    愚蠢。即使我已经通过 env.py 完成了 alembic.ini 中的所有配置,它仍然必须有一个 alembic.ini。我在没有 url 的情况下检查了我的 repo,它工作得很好。

    【讨论】:

      猜你喜欢
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 2020-12-06
      • 2015-12-01
      • 2011-02-19
      • 2017-04-12
      相关资源
      最近更新 更多