How can we help you today? How can we help you today?

Does Flyway support Jinja template if-else-endif syntax?

Hi,

I tried to run SQL statement for specific environment by using Jinja template if-else-endif syntax.

--
{% if '${env}' = 'stg' %}
grant test_role to test_user;
{% endif %}
--

but it failed with syntax error.

--
SQL State  : 42601
Error Code : 0
Message    : ERROR: syntax error at or near "{"
  Position: 1
Line       : 4
Statement  : {% if 'stg' = 'stg' %}
--

Does Flyway support Jinja template if-else-endif syntax?
yohei
0

Comments

2 comments

  • yohei

    Jinja template is Python based tool https://jinja.palletsprojects.com/en/3.1.x/

    Flyway is a Java based tool.

    so I guess Flyway does not support Jinja but I am OK if Flyway support some template engine and if-else-endif syntax.

    yohei
    0
  • Peter_Laws
    Hi yohei,

    Thanks for the question!
    Flyway supports both Script migrations and SQL Migrations and from your phrasing it sounds like you're trying to blend those together into a single file.

    Please see https://documentation.red-gate.com/fd/migrations-184127470.html under for mroe detail on Script migrations. You said Jinja is python based and flyway does support .py file, so there may be a happy medium for what you need.

    I'd expect that you could have branching logic in your script that then invoked the desired behaviour using this format.
    Peter_Laws
    0

Add comment

Please sign in to leave a comment.