Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphrass committed Oct 4, 2024
1 parent 142a29b commit 32df079
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions butterfree/migrations/database_migration/cassandra_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _get_alter_column_type_query(self, column: Diff, table_name: str) -> str:
Alter column type query.
"""

def _get_alter_column_type_query(self, column: Diff, table_name: str) -> str:
"""Creates CQL statement to alter columns' types.
In Cassandra 3.4.x to 3.11.x alter type is not allowed.
Expand All @@ -102,15 +103,20 @@ def _get_alter_column_type_query(self, column: Diff, table_name: str) -> str:

temp_column_name = f"{column.column}_temp"

add_temp_column_query = f"ALTER TABLE {table_name} ADD {temp_column_name} {column.value};"
copy_data_to_temp_query = f"UPDATE {table_name} SET {temp_column_name} = {column.column};"
add_temp_column_query = (
f"ALTER TABLE {table_name} ADD {temp_column_name} {column.value};"
)
copy_data_to_temp_query = (
f"UPDATE {table_name} SET {temp_column_name} = {column.column};"
)

drop_old_column_query = f"ALTER TABLE {table_name} DROP {column.column};"
rename_temp_column_query = f"ALTER TABLE {table_name} RENAME {temp_column_name} TO {column.column};"
rename_temp_column_query = (
f"ALTER TABLE {table_name} RENAME {temp_column_name} TO {column.column};"
)

return f"{add_temp_column_query} {copy_data_to_temp_query} {drop_old_column_query} {rename_temp_column_query};"


@staticmethod
def _get_create_table_query(columns: List[Dict[str, Any]], table_name: str) -> str:
"""Creates CQL statement to create a table.
Expand Down

0 comments on commit 32df079

Please sign in to comment.