Skip to content

Commit

Permalink
update organization
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodanswer committed Nov 12, 2024
1 parent 942e47d commit c5089f1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""default chosen assistants to none
Revision ID: 26b931506ecb
Revises: c0fd6e4da83a
Create Date: 2024-11-12 13:23:29.858995
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "26b931506ecb"
down_revision = "c0fd6e4da83a"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"user", sa.Column("chosen_assistants_new", postgresql.JSONB(), nullable=True)
)

op.execute(
"""
UPDATE "user"
SET chosen_assistants_new =
CASE
WHEN chosen_assistants = '[-2, -1, 0]' THEN NULL
ELSE chosen_assistants
END
"""
)

op.drop_column("user", "chosen_assistants")

op.alter_column(
"user", "chosen_assistants_new", new_column_name="chosen_assistants"
)


def downgrade():
op.add_column(
"user",
sa.Column(
"chosen_assistants_old",
postgresql.JSONB(),
nullable=False,
server_default="[-2, -1, 0]",
),
)

op.execute(
"""
UPDATE "user"
SET chosen_assistants_old =
CASE
WHEN chosen_assistants IS NULL THEN '[-2, -1, 0]'::jsonb
ELSE chosen_assistants
END
"""
)

op.drop_column("user", "chosen_assistants")

op.alter_column(
"user", "chosen_assistants_old", new_column_name="chosen_assistants"
)
4 changes: 2 additions & 2 deletions backend/danswer/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class User(SQLAlchemyBaseUserTableUUID, Base):

# if specified, controls the assistants that are shown to the user + their order
# if not specified, all assistants are shown
chosen_assistants: Mapped[list[int]] = mapped_column(
postgresql.JSONB(), nullable=False, default=[-2, -1, 0]
chosen_assistants: Mapped[list[int] | None] = mapped_column(
postgresql.JSONB(), nullable=True, default=None
)
visible_assistants: Mapped[list[int]] = mapped_column(
postgresql.JSONB(), nullable=False, default=[]
Expand Down
2 changes: 0 additions & 2 deletions web/src/app/assistants/mine/AssistantsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ export function AssistantsList() {

setCurrentlyVisibleAssistants(updatedAssistants);
await updateUserAssistantList(updatedAssistants.map((a) => a.id));
await refreshUser();
await refreshAssistants();
}
}

Expand Down
2 changes: 0 additions & 2 deletions web/src/app/chat/modal/configuration/AssistantsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export function AssistantsTab({

setAssistants(updatedAssistants);
await updateUserAssistantList(updatedAssistants.map((a) => a.id));
await refreshUser();
await refreshAssistants();
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/components/context/AssistantsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const AssistantsProvider: React.FC<{
const [assistants, setAssistants] = useState<Persona[]>(
initialAssistants || []
);
const { user, isLoadingUser, refreshUser, isAdmin } = useUser();
const { user, isLoadingUser, isAdmin } = useUser();
const [editablePersonas, setEditablePersonas] = useState<Persona[]>([]);
const [allAssistants, setAllAssistants] = useState<Persona[]>([]);

Expand Down

0 comments on commit c5089f1

Please sign in to comment.