From 47cd7b1d7a46da25de3daabe3756f4b244e71b9c Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 23 Jan 2026 15:43:11 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20Add=20created=5Fat=20field=20to?= =?UTF-8?q?=20User=20and=20Item=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...bbcc925_add_created_at_to_user_and_item.py | 31 +++++++++++++++++++ backend/app/api/routes/items.py | 3 +- backend/app/api/routes/users.py | 2 +- backend/app/models.py | 14 +++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py diff --git a/backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py b/backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py new file mode 100644 index 0000000000..2fae99e7c5 --- /dev/null +++ b/backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py @@ -0,0 +1,31 @@ +"""Add created_at to User and Item + +Revision ID: 44fc2bbcc925 +Revises: 1a31ce608336 +Create Date: 2026-01-23 15:42:52.493895 + +""" +from alembic import op +import sqlalchemy as sa +import sqlmodel.sql.sqltypes + + +# revision identifiers, used by Alembic. +revision = '44fc2bbcc925' +down_revision = '1a31ce608336' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('item', sa.Column('created_at', sa.DateTime(timezone=True), nullable=False)) + op.add_column('user', sa.Column('created_at', sa.DateTime(timezone=True), nullable=False)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('user', 'created_at') + op.drop_column('item', 'created_at') + # ### end Alembic commands ### diff --git a/backend/app/api/routes/items.py b/backend/app/api/routes/items.py index 3d4e4e07b5..971cf48f69 100644 --- a/backend/app/api/routes/items.py +++ b/backend/app/api/routes/items.py @@ -21,7 +21,7 @@ def read_items( if current_user.is_superuser: count_statement = select(func.count()).select_from(Item) count = session.exec(count_statement).one() - statement = select(Item).offset(skip).limit(limit) + statement = select(Item).order_by(Item.created_at.desc()).offset(skip).limit(limit) items = session.exec(statement).all() else: count_statement = ( @@ -33,6 +33,7 @@ def read_items( statement = ( select(Item) .where(Item.owner_id == current_user.id) + .order_by(Item.created_at.desc()) .offset(skip) .limit(limit) ) diff --git a/backend/app/api/routes/users.py b/backend/app/api/routes/users.py index 68f87ee253..61727949c8 100644 --- a/backend/app/api/routes/users.py +++ b/backend/app/api/routes/users.py @@ -42,7 +42,7 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any: count_statement = select(func.count()).select_from(User) count = session.exec(count_statement).one() - statement = select(User).offset(skip).limit(limit) + statement = select(User).order_by(User.created_at.desc()).offset(skip).limit(limit) users = session.exec(statement).all() return UsersPublic(data=users, count=count) diff --git a/backend/app/models.py b/backend/app/models.py index 2d060ba0b4..2114333816 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -1,9 +1,15 @@ import uuid +from datetime import datetime, timezone from pydantic import EmailStr +from sqlalchemy import DateTime from sqlmodel import Field, Relationship, SQLModel +def get_datetime_utc() -> datetime: + return datetime.now(timezone.utc) + + # Shared properties class UserBase(SQLModel): email: EmailStr = Field(unique=True, index=True, max_length=255) @@ -43,6 +49,10 @@ class UpdatePassword(SQLModel): class User(UserBase, table=True): id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) hashed_password: str + created_at: datetime = Field( + default_factory=get_datetime_utc, + sa_type=DateTime(timezone=True), # type: ignore + ) items: list["Item"] = Relationship(back_populates="owner", cascade_delete=True) @@ -75,6 +85,10 @@ class ItemUpdate(ItemBase): # Database model, database table inferred from class name class Item(ItemBase, table=True): id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) + created_at: datetime = Field( + default_factory=get_datetime_utc, + sa_type=DateTime(timezone=True), # type: ignore + ) owner_id: uuid.UUID = Field( foreign_key="user.id", nullable=False, ondelete="CASCADE" ) From 5c1576ae2edb3c13d4292dd5f88fcf4c11088ca6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jan 2026 14:44:53 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format=20and=20update?= =?UTF-8?q?=20with=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/routes/items.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/app/api/routes/items.py b/backend/app/api/routes/items.py index 971cf48f69..2b2ce57772 100644 --- a/backend/app/api/routes/items.py +++ b/backend/app/api/routes/items.py @@ -21,7 +21,9 @@ def read_items( if current_user.is_superuser: count_statement = select(func.count()).select_from(Item) count = session.exec(count_statement).one() - statement = select(Item).order_by(Item.created_at.desc()).offset(skip).limit(limit) + statement = ( + select(Item).order_by(Item.created_at.desc()).offset(skip).limit(limit) + ) items = session.exec(statement).all() else: count_statement = ( From da7238bbeafe06e071db1032cf144e3b11882427 Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 23 Jan 2026 15:52:22 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Update=20created=5Fat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...=> fe56fa70289e_add_created_at_to_user_and_item.py} | 10 +++++----- backend/app/models.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) rename backend/app/alembic/versions/{44fc2bbcc925_add_created_at_to_user_and_item.py => fe56fa70289e_add_created_at_to_user_and_item.py} (81%) diff --git a/backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py b/backend/app/alembic/versions/fe56fa70289e_add_created_at_to_user_and_item.py similarity index 81% rename from backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py rename to backend/app/alembic/versions/fe56fa70289e_add_created_at_to_user_and_item.py index 2fae99e7c5..3e15754825 100644 --- a/backend/app/alembic/versions/44fc2bbcc925_add_created_at_to_user_and_item.py +++ b/backend/app/alembic/versions/fe56fa70289e_add_created_at_to_user_and_item.py @@ -1,8 +1,8 @@ """Add created_at to User and Item -Revision ID: 44fc2bbcc925 +Revision ID: fe56fa70289e Revises: 1a31ce608336 -Create Date: 2026-01-23 15:42:52.493895 +Create Date: 2026-01-23 15:50:37.171462 """ from alembic import op @@ -11,7 +11,7 @@ # revision identifiers, used by Alembic. -revision = '44fc2bbcc925' +revision = 'fe56fa70289e' down_revision = '1a31ce608336' branch_labels = None depends_on = None @@ -19,8 +19,8 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('item', sa.Column('created_at', sa.DateTime(timezone=True), nullable=False)) - op.add_column('user', sa.Column('created_at', sa.DateTime(timezone=True), nullable=False)) + op.add_column('item', sa.Column('created_at', sa.DateTime(timezone=True), nullable=True)) + op.add_column('user', sa.Column('created_at', sa.DateTime(timezone=True), nullable=True)) # ### end Alembic commands ### diff --git a/backend/app/models.py b/backend/app/models.py index 2114333816..9a580f8895 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -49,7 +49,7 @@ class UpdatePassword(SQLModel): class User(UserBase, table=True): id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) hashed_password: str - created_at: datetime = Field( + created_at: datetime | None = Field( default_factory=get_datetime_utc, sa_type=DateTime(timezone=True), # type: ignore ) @@ -85,7 +85,7 @@ class ItemUpdate(ItemBase): # Database model, database table inferred from class name class Item(ItemBase, table=True): id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) - created_at: datetime = Field( + created_at: datetime | None = Field( default_factory=get_datetime_utc, sa_type=DateTime(timezone=True), # type: ignore ) From 51a5772c0a4dc667283b146bb8b7f22f690c5f3c Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 23 Jan 2026 16:03:45 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20Add=20created=5Fat=20field=20to?= =?UTF-8?q?=20User=20and=20Item=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/app/models.py b/backend/app/models.py index 9a580f8895..b5132e0e2c 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -59,6 +59,7 @@ class User(UserBase, table=True): # Properties to return via API, id is always required class UserPublic(UserBase): id: uuid.UUID + created_at: datetime | None = None class UsersPublic(SQLModel): @@ -99,6 +100,7 @@ class Item(ItemBase, table=True): class ItemPublic(ItemBase): id: uuid.UUID owner_id: uuid.UUID + created_at: datetime | None = None class ItemsPublic(SQLModel): From 17fe3b071a5519ca92e49af30bf3efd21ad11527 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jan 2026 15:04:19 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format=20and=20update?= =?UTF-8?q?=20with=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/client/schemas.gen.ts | 24 ++++++++++++++++++++++++ frontend/src/client/types.gen.ts | 2 ++ 2 files changed, 26 insertions(+) diff --git a/frontend/src/client/schemas.gen.ts b/frontend/src/client/schemas.gen.ts index fba9429f53..5c0c9c4a4e 100644 --- a/frontend/src/client/schemas.gen.ts +++ b/frontend/src/client/schemas.gen.ts @@ -126,6 +126,18 @@ export const ItemPublicSchema = { type: 'string', format: 'uuid', title: 'Owner Id' + }, + created_at: { + anyOf: [ + { + type: 'string', + format: 'date-time' + }, + { + type: 'null' + } + ], + title: 'Created At' } }, type: 'object', @@ -352,6 +364,18 @@ export const UserPublicSchema = { type: 'string', format: 'uuid', title: 'Id' + }, + created_at: { + anyOf: [ + { + type: 'string', + format: 'date-time' + }, + { + type: 'null' + } + ], + title: 'Created At' } }, type: 'object', diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index e5cf34c34c..e62b56cad3 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -23,6 +23,7 @@ export type ItemPublic = { description?: (string | null); id: string; owner_id: string; + created_at?: (string | null); }; export type ItemsPublic = { @@ -75,6 +76,7 @@ export type UserPublic = { is_superuser?: boolean; full_name?: (string | null); id: string; + created_at?: (string | null); }; export type UserRegister = {