Skip to content

Commit

Permalink
Merge pull request #51 from Pogchamp-company/develop
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
RustyGuard authored Dec 19, 2023
2 parents 379e1f6 + b96d94b commit c9543f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion alembic_postgresql_enum/sql_commands/column_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ def rename_default_if_required(default_value: str,
enum_name: str,
enum_values_to_rename: List[Tuple[str, str]]
) -> str:
is_array = default_value.endswith("[]")
# remove old type postfix
column_default_value = default_value[:default_value.find("::")]

for old_value, new_value in enum_values_to_rename:
column_default_value = column_default_value.replace(f"'{old_value}'", f"'{new_value}'")
column_default_value = column_default_value.replace(f'"{old_value}"', f'"{new_value}"')

return f"{column_default_value}::{enum_name}"
suffix = "[]" if is_array else ""
return f"{column_default_value}::{enum_name}{suffix}"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "alembic-postgresql-enum"
version = "1.0.0"
version = "1.0.1"
description = "Alembic autogenerate support for creation, alteration and deletion of enums"
authors = ["RustyGuard"]
license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions tests/sync_enum_values/test_rename_default_if_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ def test_array_with_renames():
assert (rename_default_if_required(old_default_value, 'order_status', [
('passive', 'inactive')
]) == """'{"inactive"}'::order_status""")


def test_array_default_value():
old_default_value = """'{}'::order_status_old[]"""

assert (rename_default_if_required(old_default_value, 'order_status', [])
== """'{}'::order_status[]""")

0 comments on commit c9543f3

Please sign in to comment.