Skip to content

Commit 6dd98d7

Browse files
committed
remove unused imports and rename migration file
1 parent 233ab82 commit 6dd98d7

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

backend/app/alembic/versions/f2589428c1d0_change_vector_store_id_to_vector_store_.py renamed to backend/app/alembic/versions/f2589428c1d0_change_vector_store_id_to_vector_store_ids.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88
from alembic import op
99
import sqlalchemy as sa
10-
import sqlmodel.sql.sqltypes
1110
from sqlalchemy.dialects import postgresql
1211

1312
# revision identifiers, used by Alembic.
@@ -37,15 +36,29 @@ def upgrade():
3736

3837

3938
def downgrade():
40-
# ### commands auto generated by Alembic - please adjust! ###
39+
# Add back the single vector_store_id column as nullable for safe data migration
4140
op.add_column(
4241
"openai_assistant",
4342
sa.Column(
4443
"vector_store_id",
4544
sa.VARCHAR(length=255),
4645
autoincrement=False,
47-
nullable=False,
46+
nullable=True, # Allow nulls temporarily for safe migration
4847
),
4948
)
49+
50+
op.execute(
51+
"""
52+
UPDATE openai_assistant
53+
SET vector_store_id = vector_store_ids[1]
54+
WHERE vector_store_ids IS NOT NULL AND array_length(vector_store_ids, 1) > 0
55+
"""
56+
)
57+
5058
op.drop_column("openai_assistant", "vector_store_ids")
51-
# ### end Alembic commands ###
59+
60+
op.alter_column(
61+
"openai_assistant",
62+
"vector_store_id",
63+
existing_type=sa.VARCHAR(length=255),
64+
)

backend/app/tests/api/routes/test_assistants.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import pytest
22
from fastapi.testclient import TestClient
3-
from sqlmodel import Session
4-
from unittest.mock import MagicMock, patch
3+
from unittest.mock import patch
54
from app.main import app
6-
from app.tests.utils.utils import random_email
7-
from app.core.security import get_password_hash
85
from app.tests.utils.openai import mock_openai_assistant
96

107
client = TestClient(app)
@@ -18,7 +15,6 @@ def normal_user_api_key_header():
1815
@patch("app.api.routes.assistants.fetch_assistant_from_openai")
1916
def test_ingest_assistant_success(
2017
mock_fetch_assistant,
21-
db: Session,
2218
normal_user_api_key_header: str,
2319
):
2420
"""Test successful assistant ingestion from OpenAI."""
@@ -43,7 +39,6 @@ def test_ingest_assistant_success(
4339
@patch("app.api.routes.assistants.configure_openai")
4440
def test_ingest_assistant_openai_not_configured(
4541
mock_configure_openai,
46-
db: Session,
4742
normal_user_api_key_header: dict,
4843
):
4944
"""Test assistant ingestion failure when OpenAI is not configured."""

backend/app/tests/utils/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import random
22
import string
33
from uuid import UUID
4-
from typing import Optional, Type, TypeVar
4+
from typing import Type, TypeVar
55

66
import pytest
77
from fastapi.testclient import TestClient
@@ -59,7 +59,7 @@ def get_non_existent_id(session: Session, model: Type[T]) -> int:
5959
return (result or 0) + 1
6060

6161

62-
def get_project(session: Session, name: Optional[str] = None) -> Project:
62+
def get_project(session: Session, name: str | None = None) -> Project:
6363
"""
6464
Retrieve an active project from the database.
6565
@@ -69,11 +69,11 @@ def get_project(session: Session, name: Optional[str] = None) -> Project:
6969
if name:
7070
statement = (
7171
select(Project)
72-
.where(Project.name == name, Project.is_active == True)
72+
.where(Project.name == name, Project.is_active)
7373
.limit(1)
7474
)
7575
else:
76-
statement = select(Project).where(Project.is_active == True).limit(1)
76+
statement = select(Project).where(Project.is_active).limit(1)
7777

7878
project = session.exec(statement).first()
7979

0 commit comments

Comments
 (0)