Is it possible to pass variables into the script.py.mako
file at revision generation time?
#1423
Answered
by
zzzeek
ghost
asked this question in
Usage Questions
-
I'm working on a system where I have a few # script.mako.py
def upgrade () -> None:
if "switch" in context.get_x_argument():
# do stuff conditional on switch
else:
# do other stuff as # script.mako.py
def upgrade () -> None:
% if some_object.arguments.switch:
# do stuff
% else
# do other stuff
% endif Why? Because I'd like to generate the migrations that can then be run in other contexts without having to remember the particular values of the switches passed in at generation time. Yes, I could just copy & paste, but the template engine is right there, you know? TIA! |
Beta Was this translation helpful? Give feedback.
Answered by
zzzeek
Feb 13, 2024
Replies: 1 comment 3 replies
-
sure, you can do whatever you want in the template. some examples on doing more in the templates you can see for example at |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sure, you can do whatever you want in the template.
some examples on doing more in the templates you can see for example at
alembic/alembic/templates/multidb/script.py.mako
Line 38 in 8829bd6