From: Mike Bayer Date: Thu, 4 Apr 2013 20:33:12 +0000 (-0400) Subject: Fixed format of RENAME for table that includes X-Git-Tag: rel_0_5_0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=705f0e7fa70625c836b3a90793f0b0c659fd11bf;p=thirdparty%2Fsqlalchemy%2Falembic.git Fixed format of RENAME for table that includes schema with Postgresql; the schema name shouldn't be in the "TO" field. #32 --- diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py index 1f146789..fce467b2 100644 --- a/alembic/ddl/postgresql.py +++ b/alembic/ddl/postgresql.py @@ -1,5 +1,6 @@ from alembic.ddl.impl import DefaultImpl from sqlalchemy import types as sqltypes +from .base import compiles, alter_table, format_table_name, RenameTable import re class PostgresqlImpl(DefaultImpl): @@ -29,3 +30,11 @@ class PostgresqlImpl(DefaultImpl): rendered_metadata_default ) ) + + +@compiles(RenameTable, "postgresql") +def visit_rename_table(element, compiler, **kw): + return "%s RENAME TO %s" % ( + alter_table(compiler, element.table_name, element.schema), + format_table_name(compiler, element.new_table_name, None) + ) diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index e758074b..a294bb90 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -6,6 +6,14 @@ Changelog .. changelog:: :version: 0.5.0 + .. change:: + :tags: bug, postgresql + :tickets: 32 + + Fixed format of RENAME for table that includes + schema with Postgresql; the schema name shouldn't + be in the "TO" field. + .. change:: :tags: feature :tickets: 90 diff --git a/tests/test_op.py b/tests/test_op.py index 1118ae49..3e914728 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -23,6 +23,16 @@ def test_rename_table_schema(): op.rename_table('t1', 't2', schema="foo") context.assert_("ALTER TABLE foo.t1 RENAME TO foo.t2") +def test_rename_table_postgresql(): + context = op_fixture("postgresql") + op.rename_table('t1', 't2') + context.assert_("ALTER TABLE t1 RENAME TO t2") + +def test_rename_table_schema_postgresql(): + context = op_fixture("postgresql") + op.rename_table('t1', 't2', schema="foo") + context.assert_("ALTER TABLE foo.t1 RENAME TO t2") + def test_add_column(): context = op_fixture() op.add_column('t1', Column('c1', Integer, nullable=False))