Alembic paths and environment organization #887
-
|
We added a database bootstrapping step to our project that can run migrations automatically during deployment, but to get both that and the CLI working, we restorted to several workarounds, and I'm wondering if I might have missed a better way to do it. When the app's Docker container runs, it executes some setup scripts (via To use the CLI without the The path hacking seems unavoidable for a lot of Alembic use cases, but I don't like having If you have any suggestions on how to better organize a project like this, I'd appreciate it! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
There's an ALEMBIC_CONFIG environment variable. I would set that in your scripts so that there is no need to use -c.
that also sounds overly complicated, you can set PYTHONPATH on the outside to refer to wherever you want. Also even if you are setting sys.path inside of env.py, there is certainly no reason for that to be in the script.py.mako template, env.py is sufficient.
I would keep alembic.ini inside the app directory. i'm not really following the problem with that because when you say "which our developers were tripping over" I don't know what the overall environment is, are the devs bashing into the docker container directly or something like that? Overall, just set ALEMBIC_CONFIG to where the file is, the devs when they bash in should have a .bashrc that sets basic environmental details so that things like this are set up for devs, this is normal stuff for environments.
|
Beta Was this translation helpful? Give feedback.
-
|
Thank you for taking the time to reply in detail. I think the key thing I failed to understand was that using Using And this is an obsolete problem now, but when we only added the project root to Thanks again. |
Beta Was this translation helpful? Give feedback.
Thank you for taking the time to reply in detail. I think the key thing I failed to understand was that using
%(here)scould save a lot of trouble dealing with relative path resolution happening in the CLI and our bootstrapper code. I didn't think to try that in the project organization that came before this one.Using
prepend_sys_pathwe were able to eliminate all the explicit path hacking, and using%(here)s/alembicwe were able to movealembic.iniback into the module directory.And this is an obsolete problem now, but when we only added the project root to
sys.pathinenv.py(and not in the mako template and migrations),alembic currentworked, butalembic historydid not. The latter …