From: Mike Bayer Date: Thu, 19 Mar 2020 17:15:48 +0000 (-0400) Subject: Don't include schema in "to" portion of Oracle RENAME table X-Git-Tag: rel_1_4_2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2f4470c51a9c2a7d2586a9cab00162dcc90667f;p=thirdparty%2Fsqlalchemy%2Falembic.git Don't include schema in "to" portion of Oracle RENAME table 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 --- diff --git a/alembic/ddl/oracle.py b/alembic/ddl/oracle.py index 50e183af..aaf759ad 100644 --- a/alembic/ddl/oracle.py +++ b/alembic/ddl/oracle.py @@ -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 index 00000000..2eb6e249 --- /dev/null +++ b/docs/build/unreleased/670.rst @@ -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. + diff --git a/tests/test_oracle.py b/tests/test_oracle.py index 537d8c6a..b2e704f9 100644 --- a/tests/test_oracle.py +++ b/tests/test_oracle.py @@ -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")