Skip to content

Commit

Permalink
feat(persistence): clear project (#2976)
Browse files Browse the repository at this point in the history
* clear project

* clear traces
  • Loading branch information
mikeldking committed Apr 24, 2024
1 parent be87ad4 commit 665c166
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ type Mutation {
"""
exportClusters(clusters: [ClusterInput!]!, fileName: String): ExportedFile!
deleteProject(id: GlobalID!): Query!
clearProject(id: GlobalID!): Query!
}

"""A node in the graph with a globally unique ID"""
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"RERANKER",
"respx",
"rgba",
"rowid",
"seafoam",
"sqlalchemy",
"Starlette",
Expand Down
2 changes: 0 additions & 2 deletions src/phoenix/db/migrations/versions/cf03bd6bae1d_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def upgrade() -> None:
nullable=False,
index=True,
),
# TODO(mikeldking): might not be the right place for this
sa.Column("session_id", sa.String, nullable=True),
sa.Column("trace_id", sa.String, nullable=False, unique=True),
sa.Column("start_time", sa.TIMESTAMP(timezone=True), nullable=False, index=True),
sa.Column("end_time", sa.TIMESTAMP(timezone=True), nullable=False),
Expand Down
1 change: 0 additions & 1 deletion src/phoenix/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class Trace(Base):
ForeignKey("projects.id", ondelete="CASCADE"),
index=True,
)
session_id: Mapped[Optional[str]]
trace_id: Mapped[str]
start_time: Mapped[datetime] = mapped_column(UtcTimeStamp, index=True)
end_time: Mapped[datetime] = mapped_column(UtcTimeStamp)
Expand Down
10 changes: 9 additions & 1 deletion src/phoenix/server/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import numpy.typing as npt
import strawberry
from sqlalchemy import select
from sqlalchemy import delete, select
from sqlalchemy.orm import load_only
from strawberry import ID, UNSET
from strawberry.types import Info
Expand Down Expand Up @@ -263,5 +263,13 @@ async def delete_project(self, info: Info[Context, None], id: GlobalID) -> Query
await session.delete(project)
return Query()

@strawberry.mutation
async def clear_project(self, info: Info[Context, None], id: GlobalID) -> Query:
project_id = from_global_id_with_expected_type(str(id), "Project")
delete_statement = delete(models.Trace).where(models.Trace.project_rowid == project_id)
async with info.context.db() as session:
await session.execute(delete_statement)
return Query()


schema = strawberry.Schema(query=Query, mutation=Mutation)

0 comments on commit 665c166

Please sign in to comment.