Skip to content

Commit

Permalink
Check whether server_default is changed with alter_column
Browse files Browse the repository at this point in the history
  • Loading branch information
artem.golovin committed Jun 30, 2024
1 parent 78d35c2 commit 757d16b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion alembic_postgresql_enum/get_enum_data/declared_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Tuple, Any, Set, Union, List, TYPE_CHECKING, cast, Dict

import sqlalchemy
from alembic.operations.ops import UpgradeOps, ModifyTableOps, AddColumnOp, CreateTableOp
from alembic.operations.ops import UpgradeOps, ModifyTableOps, AddColumnOp, CreateTableOp, AlterColumnOp
from sqlalchemy import MetaData, Column
from sqlalchemy.dialects import postgresql

Expand Down Expand Up @@ -66,6 +66,11 @@ def get_just_added_defaults(
] = operation.column.server_default.arg.text
except AttributeError:
pass
elif isinstance(operation, AlterColumnOp):
if operation.modify_server_default is not False:
new_server_defaults[
operation.schema or default_schema, operation.table_name, operation.column_name
] = operation.modify_server_default

elif isinstance(operations_group, CreateTableOp):
for column in operations_group.columns:
Expand Down

0 comments on commit 757d16b

Please sign in to comment.