From 95275bf34063dd758713d57940a07d331ad5c63f Mon Sep 17 00:00:00 2001 From: kasium <15907922+kasium@users.noreply.github.com> Date: Thu, 23 Nov 2023 23:39:59 +0100 Subject: [PATCH] Fix alembic SQL generation for RENAME TABLE (#180) Closes #179 --- sqlalchemy_hana/alembic.py | 9 +++++++++ test/test_alembic.py | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/sqlalchemy_hana/alembic.py b/sqlalchemy_hana/alembic.py index 6f34852..2ce71cd 100644 --- a/sqlalchemy_hana/alembic.py +++ b/sqlalchemy_hana/alembic.py @@ -11,6 +11,7 @@ ColumnNullable, ColumnType, DropColumn, + RenameTable, alter_table, format_column_name, format_server_default, @@ -111,3 +112,11 @@ def visit_column_default(element: ColumnDefault, compiler: HANADDLCompiler) -> s else "NULL" ) return f"{table} ALTER ({column} {type_} DEFAULT {default})" + + +@compiles(RenameTable, "hana") +def visit_rename_table(element: RenameTable, compiler: HANADDLCompiler) -> str: + """Generate SQL to rename a table.""" + old_table = format_table_name(compiler, element.table_name, element.schema) + new_table = format_table_name(compiler, element.new_table_name, element.schema) + return f"RENAME TABLE {old_table} TO {new_table}" diff --git a/test/test_alembic.py b/test/test_alembic.py index d7afb08..f99a86f 100644 --- a/test/test_alembic.py +++ b/test/test_alembic.py @@ -103,6 +103,11 @@ def test_rename_mix_case_column(self): """RENAME COLUMN "strange Table nAme"."colume A 1" TO column_a""" ) + def test_rename_table(self): + context = op_fixture("hana") + op.rename_table("old_table", "new_table") + context.assert_("RENAME TABLE old_table TO new_table") + def test_create_check_constraint(self): context = op_fixture("hana") op.create_check_constraint(