Is it possible to store the alembic connect string outside of alembic.ini?

后端 未结 10 1747
[愿得一人]
[愿得一人] 2021-01-30 15:41

I\'m using Alembic with SQL Alchemy. With SQL Alchemy, I tend to follow a pattern where I don\'t store the connect string with the versioned code. Instead I have file secr

10条回答
  •  名媛妹妹
    2021-01-30 16:38

    In env.py just add

    config.set_main_option('sqlalchemy.url', os.environ['DB_URL'])
    

    after

    config = context.config
    

    like

    config = context.config
    config.set_main_option('sqlalchemy.url', os.environ['DB_URL'])
    

    and then execute like that:

    DB_URL="mysql://atuamae:de4@127.0.0.1/db" \
      alembic upgrade head
    

提交回复
热议问题