-
Notifications
You must be signed in to change notification settings - Fork 18
Change enum on history events to str #1379
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| """Change enum columns to string type | ||
| Revision ID: cb7368a4bfae | ||
| Revises: 51547dcccb10 | ||
| Create Date: 2025-05-14 15:45:43.734154+00:00 | ||
| """ | ||
| # pylint: disable=no-member, invalid-name, missing-function-docstring, unused-import, no-name-in-module | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "cb7368a4bfae" | ||
| down_revision = "51547dcccb10" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| with op.batch_alter_table("history", schema=None) as batch_op: | ||
| batch_op.alter_column( | ||
| "entity_type", | ||
| existing_type=postgresql.ENUM( | ||
| "ATTRIBUTE", | ||
| "AVAILABILITY", | ||
| "BACKFILL", | ||
| "CATALOG", | ||
| "COLUMN_ATTRIBUTE", | ||
| "DEPENDENCY", | ||
| "ENGINE", | ||
| "LINK", | ||
| "MATERIALIZATION", | ||
| "NAMESPACE", | ||
| "NODE", | ||
| "PARTITION", | ||
| "QUERY", | ||
| "TAG", | ||
| name="entitytype", | ||
| ), | ||
| type_=sa.String(length=20), | ||
| existing_nullable=True, | ||
| ) | ||
| batch_op.alter_column( | ||
| "activity_type", | ||
| existing_type=postgresql.ENUM( | ||
| "CREATE", | ||
| "DELETE", | ||
| "RESTORE", | ||
| "UPDATE", | ||
| "REFRESH", | ||
| "TAG", | ||
| "SET_ATTRIBUTE", | ||
| "STATUS_CHANGE", | ||
| name="activitytype", | ||
| ), | ||
| type_=sa.String(length=20), | ||
| existing_nullable=True, | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| with op.batch_alter_table("history", schema=None) as batch_op: | ||
| batch_op.alter_column( | ||
| "activity_type", | ||
| existing_type=sa.String(length=20), | ||
| type_=postgresql.ENUM( | ||
| "CREATE", | ||
| "DELETE", | ||
| "RESTORE", | ||
| "UPDATE", | ||
| "REFRESH", | ||
| "TAG", | ||
| "SET_ATTRIBUTE", | ||
| "STATUS_CHANGE", | ||
| name="activitytype", | ||
| ), | ||
| existing_nullable=True, | ||
| ) | ||
| batch_op.alter_column( | ||
| "entity_type", | ||
| existing_type=sa.String(length=20), | ||
| type_=postgresql.ENUM( | ||
| "ATTRIBUTE", | ||
| "AVAILABILITY", | ||
| "BACKFILL", | ||
| "CATALOG", | ||
| "COLUMN_ATTRIBUTE", | ||
| "DEPENDENCY", | ||
| "ENGINE", | ||
| "LINK", | ||
| "MATERIALIZATION", | ||
| "NAMESPACE", | ||
| "NODE", | ||
| "PARTITION", | ||
| "QUERY", | ||
| "TAG", | ||
| name="entitytype", | ||
| ), | ||
| existing_nullable=True, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,13 @@ | |
| JSON, | ||
| BigInteger, | ||
| DateTime, | ||
| Enum, | ||
| Index, | ||
| Integer, | ||
| String, | ||
| ) | ||
| from sqlalchemy.orm import Mapped, mapped_column | ||
|
|
||
| from datajunction_server.database.base import Base | ||
| from datajunction_server.internal.history import ActivityType, EntityType | ||
| from datajunction_server.typing import UTCDatetime | ||
|
|
||
|
|
||
|
|
@@ -35,14 +33,14 @@ class History(Base): | |
| BigInteger().with_variant(Integer, "sqlite"), | ||
| primary_key=True, | ||
| ) | ||
| entity_type: Mapped[Optional[EntityType]] = mapped_column( | ||
| Enum(EntityType), | ||
| entity_type: Mapped[Optional[str]] = mapped_column( | ||
| String(20), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only 20?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason, I just thought that the postgres default of infinite length seemed unnecessary for what will just be a string representation of an enum value. Should I make this larger? Or maybe don't specify the length at all? |
||
| default=None, | ||
| ) | ||
| entity_name: Mapped[Optional[str]] = mapped_column(String, default=None) | ||
| node: Mapped[Optional[str]] = mapped_column(String, default=None) | ||
| activity_type: Mapped[Optional[ActivityType]] = mapped_column( | ||
| Enum(ActivityType), | ||
| activity_type: Mapped[Optional[str]] = mapped_column( | ||
| String(20), | ||
| default=None, | ||
| ) | ||
| user: Mapped[Optional[str]] = mapped_column(String, default=None) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also drop the enum types from Postgres? Maybe with something like: