How can I get alembic to connect to test database in my python script?

Good Afternoon, I'm having an issue with using alembic to test my api in python. My current code is as follows

from alembic.config import Config
from alembic import command

    alembic_cfg = Config("\\Users\\Ron\\git-repos\\fast-api-languages-orig\\alembic.ini")
    alembic_cfg.set_main_option('script_location', "\\Users\\Ron\\git-repos\\fast-api-languages-orig\\alembic_languages_db")
    alembic_cfg.set_main_option("sqlalchemy.url", f"postgresql://{settings.DB_USER}:{settings.DB_PASS}@{settings.DB_HOST}/{settings.postgres_redis}-test")
    
    command.current(alembic_cfg, verbose=True)
    command.upgrade(alembic_cfg, "head")
    command.downgrade(alembic_cfg, "head")

Not sure if that is formatted right. This is my first question on SO, So I may just have to redo that but for some reason the script runs find however alembic isn't connecting to my new test database as specified in the <alembic_cfg.set_main_option("sqlalchemy.url"...> . It instead connects to the old db and I know this because when I run command.current(alembic_cfg, verbose=True) then it shows my old db url with the old revisions from november. For example it shows "Current revision(s) for postgresql://postgres:XXXXX@localhost/api-redis" instead of api-redis-test for the database. And of course the downgrade nor the upgrade command works. Do you guys see any mistake I'm making?

edit: Ok so I realize command.downgrade(alembic_cfg, "base") is the correct way but what's interesting is that when i do print(config.get_main_option("sqlalchemy.url")) and then run pytest it does show the correct db postgresql://postgres:****@localhost/api-redis-test. So while the option is being changed alembic still defaults to the database in the env.py file 🤔.



from Recent Questions - Stack Overflow https://ift.tt/3mhWlhV
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)