From 60acf3e0c145fbe4efc8b41c3a25f874ad89e843 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Fri, 6 Dec 2024 13:24:36 -0800 Subject: [PATCH] fix slackbot channel config nullable (#3363) * fix slackbot * nit --- ...2_non_nullbale_slack_bot_id_in_channel_.py | 40 +++++++++++++++++++ backend/danswer/db/models.py | 4 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 backend/alembic/versions/f7a894b06d02_non_nullbale_slack_bot_id_in_channel_.py diff --git a/backend/alembic/versions/f7a894b06d02_non_nullbale_slack_bot_id_in_channel_.py b/backend/alembic/versions/f7a894b06d02_non_nullbale_slack_bot_id_in_channel_.py new file mode 100644 index 00000000000..370ab1f0d84 --- /dev/null +++ b/backend/alembic/versions/f7a894b06d02_non_nullbale_slack_bot_id_in_channel_.py @@ -0,0 +1,40 @@ +"""non-nullbale slack bot id in channel config + +Revision ID: f7a894b06d02 +Revises: 9f696734098f +Create Date: 2024-12-06 12:55:42.845723 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "f7a894b06d02" +down_revision = "9f696734098f" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # Delete all rows with null slack_bot_id + op.execute("DELETE FROM slack_channel_config WHERE slack_bot_id IS NULL") + + # Make slack_bot_id non-nullable + op.alter_column( + "slack_channel_config", + "slack_bot_id", + existing_type=sa.Integer(), + nullable=False, + ) + + +def downgrade() -> None: + # Make slack_bot_id nullable again + op.alter_column( + "slack_channel_config", + "slack_bot_id", + existing_type=sa.Integer(), + nullable=True, + ) diff --git a/backend/danswer/db/models.py b/backend/danswer/db/models.py index 30b69457653..b9e0f7bc416 100644 --- a/backend/danswer/db/models.py +++ b/backend/danswer/db/models.py @@ -1490,7 +1490,9 @@ class SlackChannelConfig(Base): __tablename__ = "slack_channel_config" id: Mapped[int] = mapped_column(primary_key=True) - slack_bot_id: Mapped[int] = mapped_column(ForeignKey("slack_bot.id"), nullable=True) + slack_bot_id: Mapped[int] = mapped_column( + ForeignKey("slack_bot.id"), nullable=False + ) persona_id: Mapped[int | None] = mapped_column( ForeignKey("persona.id"), nullable=True )