Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.0.2 #55

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[]""")