1

I'm pulling my hair out, any help would be appreciated.

I'm attempting to run an alembic upgrade on deployment of my new app. I've been searching stack overflow for 3 hours now and cannot find anything that works. Every thing I do has the same result.

this comes from my heroku release log FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section

I'm using the following for my ProcFile

release: alembic upgrade head
worker: python bot.py

I'm using something similar to this for my env.py file

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

but here is my actual... This has been modified that NOTHING should be attempting to open 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()

I'm using environmental variables to configure the database url - though it never even seems to get to there.

The upgrade works FINE locally, I can run it all day and night.

I have not figured out a way to get any form of logging from alembic, or stack trace or anything so I don't even know what line is causing the problem.

The only thing I can think of is that the release phase is using the pre-release code? which doesn't even have any alembic stuff so that doesn't make sense. I've truly got no ideas.

bravosierra99
  • 1,331
  • 11
  • 23

1 Answers1

0

Stupid. Even though I’ve done all the configuration that is in alembic.ini via env.py it still MUST have an alembic.ini. I checked one into my repo without the url and it works just fine.

bravosierra99
  • 1,331
  • 11
  • 23