Skip to content
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

initial my documents feature pass #3320

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
125 changes: 125 additions & 0 deletions backend/alembic/versions/25d86cbfce78_add_my_documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from alembic import op
import sqlalchemy as sa
import datetime

# revision identifiers, used by Alembic.
revision = "25d86cbfce78"
down_revision = "a8c2065484e6"
branch_labels = None
depends_on = None


def upgrade() -> None:
# Create user_folder table with additional 'display_priority' field
op.create_table(
"user_folder",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("user_id", sa.UUID(), sa.ForeignKey("user.id"), nullable=True),
sa.Column(
"parent_id", sa.Integer(), sa.ForeignKey("user_folder.id"), nullable=True
),
sa.Column("name", sa.String(length=255), nullable=True),
sa.Column("display_priority", sa.Integer(), nullable=True, default=0),
sa.Column("created_at", sa.DateTime(), default=datetime.datetime.utcnow),
)

# Migrate data from chat_folder to user_folder
op.execute(
"""
INSERT INTO user_folder (id, user_id, name, display_priority, created_at)
SELECT id, user_id, name, display_priority, CURRENT_TIMESTAMP FROM chat_folder
"""
)

# Update chat_session table to reference user_folder instead of chat_folder
with op.batch_alter_table("chat_session") as batch_op:
batch_op.drop_constraint("chat_session_chat_folder_fk", type_="foreignkey")
batch_op.alter_column(
"folder_id",
existing_type=sa.Integer(),
nullable=True,
existing_nullable=True,
existing_server_default=None,
)
batch_op.create_foreign_key(
"fk_chat_session_folder_id_user_folder",
"user_folder",
["folder_id"],
["id"],
ondelete="SET NULL",
)

# Drop the chat_folder table
op.drop_table("chat_folder")

# Create user_file table
op.create_table(
"user_file",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("user_id", sa.UUID(), sa.ForeignKey("user.id"), nullable=True),
sa.Column(
"parent_folder_id",
sa.Integer(),
sa.ForeignKey("user_folder.id"),
nullable=True,
),
sa.Column("file_type", sa.String(), nullable=True),
sa.Column("file_id", sa.String(length=255), nullable=False),
sa.Column("document_id", sa.String(length=255), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column(
"created_at",
sa.DateTime(),
default=datetime.datetime.utcnow,
),
)


def downgrade() -> None:
# Recreate chat_folder table
op.create_table(
"chat_folder",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column(
"user_id",
sa.UUID(),
sa.ForeignKey("user.id", ondelete="CASCADE"),
nullable=True,
),
sa.Column("name", sa.String(length=255), nullable=True),
sa.Column("display_priority", sa.Integer(), nullable=True, default=0),
)

# Migrate data back from user_folder to chat_folder
op.execute(
"""
INSERT INTO chat_folder (id, user_id, name, display_priority)
SELECT id, user_id, name, display_priority FROM user_folder
WHERE id IN (SELECT DISTINCT folder_id FROM chat_session WHERE folder_id IS NOT NULL)
"""
)

# Update chat_session table to reference chat_folder again
with op.batch_alter_table("chat_session") as batch_op:
batch_op.drop_constraint(
"fk_chat_session_folder_id_user_folder", type_="foreignkey"
)
batch_op.alter_column(
"folder_id",
existing_type=sa.Integer(),
nullable=True,
existing_nullable=True,
existing_server_default=None,
)
batch_op.create_foreign_key(
"chat_session_chat_folder_fk",
"chat_folder",
["folder_id"],
["id"],
ondelete="SET NULL",
)

# Drop the user_file table
op.drop_table("user_file")
# Drop the user_folder table
op.drop_table("user_folder")
2 changes: 1 addition & 1 deletion backend/danswer/background/celery/tasks/indexing/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def connector_indexing_task_wrapper(


def connector_indexing_task(
index_attempt_id: int,
index_attempt_id: int | None,
cc_pair_id: int,
search_settings_id: int,
tenant_id: str | None,
Expand Down
2 changes: 2 additions & 0 deletions backend/danswer/configs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class FileOrigin(str, Enum):
CHAT_IMAGE_GEN = "chat_image_gen"
CONNECTOR = "connector"
GENERATED_REPORT = "generated_report"
MY_DOCUMENTS = "my_documents"
OTHER = "other"


Expand Down Expand Up @@ -249,6 +250,7 @@ class DanswerRedisLocks:

SLACK_BOT_LOCK = "da_lock:slack_bot"
SLACK_BOT_HEARTBEAT_PREFIX = "da_heartbeat:slack_bot"
ANONYMOUS_USER_ENABLED = "anonymous_user_enabled"


class DanswerCeleryPriority(int, Enum):
Expand Down
2 changes: 1 addition & 1 deletion backend/danswer/connectors/confluence/onyx_confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_current_user(self, expand: str | None = None) -> Any:
try:
response = self.get(url, params=params)
except HTTPError as e:
if e.response.status_code == 403:
if e.response is not None and e.response.status_code == 403:
raise ApiPermissionError(
"The calling user does not have permission", reason=e
)
Expand Down
132 changes: 0 additions & 132 deletions backend/danswer/db/folder.py

This file was deleted.

Loading