Skip to content

Commit

Permalink
Fix alembic SQL generation for RENAME TABLE (#180)
Browse files Browse the repository at this point in the history
Closes #179
  • Loading branch information
kasium authored Nov 23, 2023
1 parent af3f440 commit 95275bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sqlalchemy_hana/alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ColumnNullable,
ColumnType,
DropColumn,
RenameTable,
alter_table,
format_column_name,
format_server_default,
Expand Down Expand Up @@ -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}"
5 changes: 5 additions & 0 deletions test/test_alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 95275bf

Please sign in to comment.