]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Don't include schema in "to" portion of Oracle RENAME table
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 19 Mar 2020 17:15:48 +0000 (13:15 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 19 Mar 2020 17:15:48 +0000 (13:15 -0400)
Fixed issue in Oracle backend where a table RENAME with a schema-qualified
name would include the schema in the "to" portion, which is rejected by
Oracle.

Change-Id: I8110a58bea20ebe48bfca0877da6bd8e0abd17c2
Fixes: #670
alembic/ddl/oracle.py
docs/build/unreleased/670.rst [new file with mode: 0644]
tests/test_oracle.py

index 50e183afdc6a80fdd93b46eeffe27e7b2c8c84a6..aaf759adcb2d8298fd56e0ad515c013352e88ef3 100644 (file)
@@ -10,7 +10,9 @@ from .base import ColumnNullable
 from .base import ColumnType
 from .base import format_column_name
 from .base import format_server_default
+from .base import format_table_name
 from .base import format_type
+from .base import RenameTable
 from .impl import DefaultImpl
 
 
@@ -105,6 +107,14 @@ def visit_column_comment(element, compiler, **kw):
     )
 
 
+@compiles(RenameTable, "oracle")
+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),
+    )
+
+
 def alter_column(compiler, name):
     return "MODIFY %s" % format_column_name(compiler, name)
 
diff --git a/docs/build/unreleased/670.rst b/docs/build/unreleased/670.rst
new file mode 100644 (file)
index 0000000..2eb6e24
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, op directives, oracle
+    :tickets: 670
+
+    Fixed issue in Oracle backend where a table RENAME with a schema-qualified
+    name would include the schema in the "to" portion, which is rejected by
+    Oracle.
+
index 537d8c6a63722fa0d620c9181d6144b8a614e0da..b2e704f93f668d0f4f9e386eb8922a0f8ec701c3 100644 (file)
@@ -80,6 +80,16 @@ class OpTest(TestBase):
             "INTEGER GENERATED ALWAYS AS (foo * 5)"
         )
 
+    def test_alter_table_rename_oracle(self):
+        context = op_fixture("oracle")
+        op.rename_table("s", "t")
+        context.assert_("ALTER TABLE s RENAME TO t")
+
+    def test_alter_table_rename_schema_oracle(self):
+        context = op_fixture("oracle")
+        op.rename_table("s", "t", schema="myowner")
+        context.assert_("ALTER TABLE myowner.s RENAME TO t")
+
     def test_alter_column_rename_oracle(self):
         context = op_fixture("oracle")
         op.alter_column("t", "c", name="x")