We are attempting to generate a SQL Migration script using Alembic (offline mode). Part of the view in the migration uses the MySQL function DATE_FORMAT, as in the example below. When the migration scripts are created, the percent characters are being doubled-up in the generated SQL.
We've been manually modifying the generated scripts to set it back to a single % character instead, but would like to get out of that practice and have our upgrades / downgrades generate SQL that can be piped into the db without manually modification.
From what I have been able to determine, running the Alembic migration in online mode with the no_parameters = True set in the execution_options allows, "...percent signs straight through without escaping, thus providing cross-compatible operation with DBAPI execution and static script generation."
(see: https://alembic.readthedocs.org/en/latest/changelog.html#change-1dff9e522d76403d9af885164fd284e9 )
Since the execution_options are set as a property of the Connection and no connection is present when running in offline mode, this does not seem to be an option for us.
Any help or advice would be most appreciated!
=======================
Alembic migration file:
def upgrade():
my_view_sql = """
CREATE VIEW my_view
AS
SELECT DATE_FORMAT(m.my_date, '%m/%d/%Y') AS 'my_date'
FROM some_table as m
"""
op.execute(my_view_sql)
======================
Generated SQL:
-- Running upgrade old_version -> new_version
CREATE VIEW my_view
AS
SELECT DATE_FORMAT(m.my_date, '%%m/%%d/%%Y') AS 'my_date'
FROM some_table as m;
UPDATE alembic_version SET version_num='new_version';