RazerM · GitHub

Seems like someone had this before but didn't follow up with details: #439

alembic: 1.0.10
sqlalchemy: 1.2.19
psycopg2: 2.8.2

Revision:

"""Test revision

Revision ID: 3e64c96e6cc5
Revises: ae08c6f2822a
Create Date: 2019-05-15 11:30:29.061244

"""
# revision identifiers, used by Alembic.
revision = '3e64c96e6cc5'
down_revision = 'ae08c6f2822a'
branch_labels = None
depends_on = None
from alembic import op
def upgrade():
    op.execute('''
        CREATE FUNCTION
          _tmp_raise_exception()
        RETURNS void AS
        $body$
        BEGIN
          RAISE EXCEPTION 'Here is a number: %', 15;
        END;
        $body$
        LANGUAGE 'plpgsql'
    ''')
def downgrade():
    op.execute('DROP FUNCTION _tmp_raise_exception()')

--sql output (note the %%):

$ alembic upgrade --sql ae08c6f2822a:3e64c96e6cc5
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Generating static SQL
INFO  [alembic.runtime.migration] Will assume transactional DDL.
BEGIN;
INFO  [alembic.runtime.migration] Running upgrade ae08c6f2822a -> 3e64c96e6cc5, Test revision
-- Running upgrade ae08c6f2822a -> 3e64c96e6cc5
CREATE FUNCTION
          _tmp_raise_exception()
        RETURNS void AS
        $body$
        BEGIN
          RAISE EXCEPTION 'Here is a number: %%', 15;
        END;
        $body$
        LANGUAGE 'plpgsql';
UPDATE alembic_version SET version_num='3e64c96e6cc5' WHERE alembic_version.version_num = 'ae08c6f2822a';
COMMIT;

This generated SQL is invalid.

Read the original on github.com ↗