diff --git a/alembic_postgresql_enum/sql_commands/column_default.py b/alembic_postgresql_enum/sql_commands/column_default.py index 5dc71db..9f009a0 100644 --- a/alembic_postgresql_enum/sql_commands/column_default.py +++ b/alembic_postgresql_enum/sql_commands/column_default.py @@ -48,6 +48,7 @@ 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("::")] @@ -55,4 +56,5 @@ def rename_default_if_required(default_value: str, 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}" diff --git a/pyproject.toml b/pyproject.toml index 2e8af04..71baa70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/sync_enum_values/test_rename_default_if_required.py b/tests/sync_enum_values/test_rename_default_if_required.py index 58aff51..9f5b0dc 100644 --- a/tests/sync_enum_values/test_rename_default_if_required.py +++ b/tests/sync_enum_values/test_rename_default_if_required.py @@ -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[]""") \ No newline at end of file