From 266a5be38b282e2a96ff3983bcf38adccb856176 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 15 Jan 2026 16:26:49 +0200 Subject: [PATCH] Add chat_comment_mentions table migration --- .../67_add_chat_comment_mentions_table.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 surfsense_backend/alembic/versions/67_add_chat_comment_mentions_table.py diff --git a/surfsense_backend/alembic/versions/67_add_chat_comment_mentions_table.py b/surfsense_backend/alembic/versions/67_add_chat_comment_mentions_table.py new file mode 100644 index 000000000..ceb8669ae --- /dev/null +++ b/surfsense_backend/alembic/versions/67_add_chat_comment_mentions_table.py @@ -0,0 +1,45 @@ +"""Add chat_comment_mentions table for @mentions in comments + +Revision ID: 67 +Revises: 66 +""" + +from collections.abc import Sequence + +from alembic import op + +revision: str = "67" +down_revision: str | None = "66" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + """Create chat_comment_mentions table.""" + op.execute( + """ + CREATE TABLE IF NOT EXISTS chat_comment_mentions ( + id SERIAL PRIMARY KEY, + comment_id INTEGER NOT NULL REFERENCES chat_comments(id) ON DELETE CASCADE, + mentioned_user_id UUID NOT NULL REFERENCES "user"(id) ON DELETE CASCADE, + read BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + UNIQUE (comment_id, mentioned_user_id) + ); + + -- Create indexes + CREATE INDEX IF NOT EXISTS idx_chat_comment_mentions_comment_id + ON chat_comment_mentions(comment_id); + CREATE INDEX IF NOT EXISTS idx_chat_comment_mentions_user_unread + ON chat_comment_mentions(mentioned_user_id) WHERE read = FALSE; + """ + ) + + +def downgrade() -> None: + """Drop chat_comment_mentions table.""" + op.execute( + """ + DROP TABLE IF EXISTS chat_comment_mentions; + """ + )