我正在拔头发,任何帮助将不胜感激。
我正在尝试在部署新应用程序时进行一次自我升级。我已经搜索堆栈溢出了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文件使用类似的东西
{{3}}
但这是我的实际...这已被修改为: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,堆栈跟踪或其他任何方式获取任何形式的日志记录的方法,所以我什至不知道是哪一行导致了问题。
我唯一能想到的是发布阶段正在使用预发布代码?甚至没有任何蒸馏物质,所以这没有任何意义。我真的不知道。
答案 0 :(得分:0)
愚蠢。即使我已经通过env.py完成了alembic.ini中的所有配置,它仍然必须具有alembic.ini。我在没有URL的情况下将其签入了我的仓库中,效果很好。