]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Fixed format of RENAME for table that includes
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Apr 2013 20:33:12 +0000 (16:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Apr 2013 20:33:12 +0000 (16:33 -0400)
schema with Postgresql; the schema name shouldn't
be in the "TO" field.
#32

alembic/ddl/postgresql.py
docs/build/changelog.rst
tests/test_op.py

index 1f146789a3b7d28f667597a4aa531555b59ca8be..fce467b295660889d89a63d8bba7a864112a4418 100644 (file)
@@ -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)
+    )
index e758074b8554adbb66ddc80a42eebeef6afd2de9..a294bb90ccdf7eb4902a936d9d50901f98a4c811 100644 (file)
@@ -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
index 1118ae49503d5c09645b9eaf91b1089183fe19de..3e914728f987092e8a6a2c08977d4abc77ec677c 100644 (file)
@@ -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))