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

后端 未结 10 1605
[愿得一人]
[愿得一人] 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:25

    As Doug T. said you can edit env.py to provide URL from somewhere else than ini file. Instead of creating new engine you can pass an additional url argument to the engine_from_config function (kwargs are later merged to options taken from ini file). In that case you could e.g. store encrypted password in ini file and decrypt it in runtime by passphrase stored in ENV variable.

    connectable = engine_from_config(                 
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',                         
        poolclass=pool.NullPool,                      
        url=some_decrypted_endpoint)                                   
    

提交回复
热议问题