Skip to content

Commit

Permalink
update ports + cascades
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Sep 21, 2024
1 parent ff6d2cb commit c2c195c
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 4 deletions.
100 changes: 100 additions & 0 deletions backend/alembic/versions/35e518e0ddf4_properly_cascade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""properly_cascade
Revision ID: 35e518e0ddf4
Revises: f32615f71aeb
Create Date: 2024-09-20 21:24:04.891018
"""
from alembic import op


# revision identifiers, used by Alembic.
revision = "35e518e0ddf4"
down_revision = "f32615f71aeb"
branch_labels = None
depends_on = None


def upgrade() -> None:
# Update chat_message foreign key constraint
op.drop_constraint(
"chat_message_chat_session_id_fkey", "chat_message", type_="foreignkey"
)
op.create_foreign_key(
"chat_message_chat_session_id_fkey",
"chat_message",
"chat_session",
["chat_session_id"],
["id"],
ondelete="CASCADE",
)

# Update chat_message__search_doc foreign key constraints
op.drop_constraint(
"chat_message__search_doc_chat_message_id_fkey",
"chat_message__search_doc",
type_="foreignkey",
)
op.drop_constraint(
"chat_message__search_doc_search_doc_id_fkey",
"chat_message__search_doc",
type_="foreignkey",
)

op.create_foreign_key(
"chat_message__search_doc_chat_message_id_fkey",
"chat_message__search_doc",
"chat_message",
["chat_message_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"chat_message__search_doc_search_doc_id_fkey",
"chat_message__search_doc",
"search_doc",
["search_doc_id"],
["id"],
ondelete="CASCADE",
)


def downgrade() -> None:
# Revert chat_message foreign key constraint
op.drop_constraint(
"chat_message_chat_session_id_fkey", "chat_message", type_="foreignkey"
)
op.create_foreign_key(
"chat_message_chat_session_id_fkey",
"chat_message",
"chat_session",
["chat_session_id"],
["id"],
)

# Revert chat_message__search_doc foreign key constraints
op.drop_constraint(
"chat_message__search_doc_chat_message_id_fkey",
"chat_message__search_doc",
type_="foreignkey",
)
op.drop_constraint(
"chat_message__search_doc_search_doc_id_fkey",
"chat_message__search_doc",
type_="foreignkey",
)

op.create_foreign_key(
"chat_message__search_doc_chat_message_id_fkey",
"chat_message__search_doc",
"chat_message",
["chat_message_id"],
["id"],
)
op.create_foreign_key(
"chat_message__search_doc_search_doc_id_fkey",
"chat_message__search_doc",
"search_doc",
["search_doc_id"],
["id"],
)
4 changes: 3 additions & 1 deletion backend/danswer/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ class ChatSession(Base):
"ChatFolder", back_populates="chat_sessions"
)
messages: Mapped[list["ChatMessage"]] = relationship(
"ChatMessage", back_populates="chat_session"
"ChatMessage", back_populates="chat_session", cascade="all, delete-orphan"
)
persona: Mapped["Persona"] = relationship("Persona")

Expand Down Expand Up @@ -1018,6 +1018,8 @@ class ChatMessage(Base):
"SearchDoc",
secondary=ChatMessage__SearchDoc.__table__,
back_populates="chat_messages",
cascade="all, delete-orphan",
single_parent=True,
)
# NOTE: Should always be attached to the `assistant` message.
# represents the tool calls used to generate this message
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ export function ChatPage({
onClose={() => setShowDeleteAllModal(false)}
additionalDetails="This action cannot be undone. All your chat sessions will be deleted."
onSubmit={async () => {
const response = await deleteAllChatSessions("chat");
const response = await deleteAllChatSessions("Chat");
if (response.ok) {
setShowDeleteAllModal(false);
setPopup({
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/chat/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export async function deleteChatSession(chatSessionId: number) {
return response;
}

export async function deleteAllChatSessions(sessionType: "chat" | "search") {
export async function deleteAllChatSessions(sessionType: "Chat" | "Search") {
const response = await fetch(`/api/chat/delete-all-chat-sessions`, {
method: "DELETE",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/search/SearchSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ export const SearchSection = ({
onClose={() => setShowDeleteAllModal(false)}
additionalDetails="This action cannot be undone. All your search sessions will be deleted."
onSubmit={async () => {
const response = await deleteAllChatSessions("search");
const response = await deleteAllChatSessions("Search");
if (response.ok) {
setShowDeleteAllModal(false);
setPopup({
Expand Down

0 comments on commit c2c195c

Please sign in to comment.