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

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

    So what appears to work is reimplementing engine creation in env.py, which is apparently a place for doing this kind of customizing Instead of using the sqlalchemy connect string in the ini:

    engine = engine_from_config(
                config.get_section(config.config_ini_section),
                prefix='sqlalchemy.',
               poolclass=pool.NullPool)
    

    You can replace and specify your own engine configuration:

    import store
    engine = store.engine
    

    Indeed the docs seems to imply this is ok:

    sqlalchemy.url - A URL to connect to the database via SQLAlchemy. This key is in fact only referenced within the env.py file that is specific to the “generic” configuration; a file that can be customized by the developer. A multiple database configuration may respond to multiple keys here, or may reference other sections of the file.

提交回复
热议问题