Skip to content

Commit

Permalink
Merge pull request #55 from Pogchamp-company/develop
Browse files Browse the repository at this point in the history
Version 1.0.2
  • Loading branch information
RustyGuard authored Jan 5, 2024
2 parents c9543f3 + a89aab7 commit 7a9a402
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion alembic_postgresql_enum/operations/sync_enum_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _set_enum_values(cls,
) from error

if column_default is not None:
column_default = rename_default_if_required(column_default, enum_name,
column_default = rename_default_if_required(schema, column_default, enum_name,
enum_values_to_rename)

set_default(connection, schema, table_reference, column_default)
Expand Down
5 changes: 4 additions & 1 deletion alembic_postgresql_enum/sql_commands/column_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def set_default(connection: 'Connection',
))


def rename_default_if_required(default_value: str,
def rename_default_if_required(schema: str,
default_value: str,
enum_name: str,
enum_values_to_rename: List[Tuple[str, str]]
) -> str:
Expand All @@ -57,4 +58,6 @@ def rename_default_if_required(default_value: str,
column_default_value = column_default_value.replace(f'"{old_value}"', f'"{new_value}"')

suffix = "[]" if is_array else ""
if schema:
return f"{column_default_value}::{schema}.{enum_name}{suffix}"
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.1"
version = "1.0.2"
description = "Alembic autogenerate support for creation, alteration and deletion of enums"
authors = ["RustyGuard"]
license = "MIT"
Expand Down
32 changes: 16 additions & 16 deletions tests/sync_enum_values/test_rename_default_if_required.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from alembic_postgresql_enum.sql_commands.column_default import rename_default_if_required


def test_without_renames():
old_default_value = "'passive'::order_status_old"
def test_without_renames_with_schema():
old_default_value = "'passive'::test.order_status_old"

assert (rename_default_if_required(old_default_value, 'order_status', [])
== "'passive'::order_status")
assert (rename_default_if_required('test', old_default_value, 'order_status', [])
== "'passive'::test.order_status")


def test_with_renames():
old_default_value = "'passive'::order_status_old"
def test_with_renames_with_schema():
old_default_value = "'passive'::test.order_status_old"

assert (rename_default_if_required(old_default_value, 'order_status', [
assert (rename_default_if_required('test', old_default_value, 'order_status', [
('passive', 'inactive')
]) == "'inactive'::order_status")
]) == "'inactive'::test.order_status")


def test_array_with_renames():
old_default_value = """'{"passive"}'::order_status_old"""
def test_array_with_renames_with_schema():
old_default_value = """'{"passive"}'::test.order_status_old"""

assert (rename_default_if_required(old_default_value, 'order_status', [
assert (rename_default_if_required('test', old_default_value, 'order_status', [
('passive', 'inactive')
]) == """'{"inactive"}'::order_status""")
]) == """'{"inactive"}'::test.order_status""")


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

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

0 comments on commit 7a9a402

Please sign in to comment.