Skip to content
Discussion options

You must be logged in to vote

The correct way to do this pattern is to construct the URL inside of env.py

this is tested and works

def run_migrations_online() -> None:

    from sqlalchemy import create_engine
    import re
    import os

    url_tokens = {
        "DB_USER": os.getenv("DB_USER", ""),
        "DB_PASS": os.getenv("DB_PASS", ""),
        "DB_HOST": os.getenv("DB_HOST", ""),
        "DB_NAME": os.getenv("DB_NAME", "")
    }

    url = config.get_main_option("sqlalchemy.url")

    url = re.sub(r"\${(.+?)}", lambda m: url_tokens[m.group(1)], url)

    connectable = create_engine(url)

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

Replies: 6 comments 12 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@zzzeek
Comment options

@zzzeek
Comment options

@Lepiloff
Comment options

Comment options

You must be logged in to vote
7 replies
@Lepiloff
Comment options

@zzzeek
Comment options

@zzzeek
Comment options

Answer selected by CaselIT
@Jarmos-san
Comment options

@CaselIT
Comment options

@cfloressuazo
Comment options

@CaselIT
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@CaselIT
Comment options

@MahirMahbub
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants