Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion alphatrion/metadata/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ def __init__(self, db_url: str, init_tables: bool = False):
# Mostly used in tests.
Base.metadata.create_all(self._engine)

def create_project(self, name: str, description: str | None = None) -> uuid.UUID:
def create_project(
self, name: str, description: str | None = None, meta: dict | None = None
) -> uuid.UUID:
session = self._session()
new_project = Project(
name=name,
description=description,
meta=meta,
)
session.add(new_project)
session.commit()
Expand Down
1 change: 1 addition & 0 deletions alphatrion/metadata/sql_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Project(Base):
uuid = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = Column(String, nullable=False)
description = Column(String, nullable=True)
meta = Column(JSON, nullable=True, comment="Additional metadata for the project")

created_at = Column(DateTime(timezone=True), default=lambda: datetime.now(UTC))
updated_at = Column(
Expand Down
2 changes: 2 additions & 0 deletions alphatrion/server/graphql/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def list_projects(page: int = 0, page_size: int = 10) -> list[Project]:
id=p.uuid,
name=p.name,
description=p.description,
meta=p.meta,
created_at=p.created_at,
updated_at=p.updated_at,
)
Expand All @@ -40,6 +41,7 @@ def get_project(id: str) -> Project | None:
id=project.uuid,
name=project.name,
description=project.description,
meta=project.meta,
created_at=project.created_at,
updated_at=project.updated_at,
)
Expand Down
1 change: 1 addition & 0 deletions alphatrion/server/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Project:
id: strawberry.ID
name: str | None
description: str | None
meta: JSON | None
created_at: datetime
updated_at: datetime

Expand Down
3 changes: 3 additions & 0 deletions hack/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def generate_project() -> Project:
uuid=uuid.uuid4(),
name=fake.bs().title(),
description=fake.catch_phrase(),
meta=make_json_serializable(
fake.pydict(nb_elements=3, variable_nb_elements=True)
),
)


Expand Down
32 changes: 32 additions & 0 deletions migrations/versions/c89fc8504699_add_project_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add project meta

Revision ID: c89fc8504699
Revises: 648be86800d3
Create Date: 2025-12-01 15:40:10.591556

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'c89fc8504699'
down_revision: Union[str, Sequence[str], None] = '648be86800d3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('projects', sa.Column('meta', sa.JSON(), nullable=True, comment='Additional metadata for the project'))
# ### end Alembic commands ###


def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('projects', 'meta')
# ### end Alembic commands ###
10 changes: 8 additions & 2 deletions tests/integration/server/test_graphql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_query_single_project():
id
name
description
meta
createdAt
updatedAt
}}
Expand All @@ -35,15 +36,20 @@ def test_query_single_project():
def test_query_projects():
init(init_tables=True)
metadb = graphql_runtime().metadb
_ = metadb.create_project(name="Test Project1", description="A project for testing")
_ = metadb.create_project(name="Test Project2", description="A project for testing")
_ = metadb.create_project(
name="Test Project1", description="A project for testing", meta={"foo": "bar"}
)
_ = metadb.create_project(
name="Test Project2", description="A project for testing", meta={"baz": 123}
)

query = """
query {
projects {
id
name
description
meta
createdAt
updatedAt
}
Expand Down
Loading