Skip to content

Commit 8e0f8df

Browse files
committed
✨ [feat][backend] Add Account.created_at
1 parent f31ea5d commit 8e0f8df

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""add account created_at
2+
3+
Revision ID: 0041
4+
Revises: 0040
5+
Create Date: 2026-07-19 17:56:10.091969
6+
7+
"""
8+
import sqlalchemy as sa
9+
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '0041'
14+
down_revision = '0040'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column(
22+
"account",
23+
sa.Column(
24+
"created_at",
25+
sa.DateTime(timezone=True),
26+
server_default=sa.text("now()"),
27+
nullable=False,
28+
),
29+
)
30+
# ### end Alembic commands ###
31+
32+
33+
def downgrade():
34+
# ### commands auto generated by Alembic - please adjust! ###
35+
op.drop_column('account', 'created_at')
36+
# ### end Alembic commands ###

backend/kayman/schemas/account.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from datetime import UTC, datetime
12
from decimal import Decimal
23
from typing import TYPE_CHECKING
34

45
from pydantic_extra_types.timezone_name import TimeZoneName
5-
from sqlmodel import Column, Field, Relationship, SQLModel
6+
from sqlmodel import Column, DateTime, Field, Relationship, SQLModel
67

78
from kayman.schemas._custom_types import SATimezone
89

@@ -24,6 +25,10 @@ class Account(AccountBase, table=True):
2425
# we don't accept initial value on create, and will always use 0 as default
2526
balance: Decimal = Field(default=0)
2627
timezone: TimeZoneName = Field(sa_column=Column(SATimezone(), nullable=False))
28+
created_at: datetime = Field(
29+
default_factory=lambda: datetime.now(UTC),
30+
sa_column=Column(DateTime(timezone=True), nullable=False),
31+
)
2732
currency: "Currency" = Relationship(back_populates="accounts")
2833
statements: list["Statement"] = Relationship(back_populates="account")
2934
transactions: list["Transaction"] = Relationship(back_populates="account")
@@ -37,6 +42,7 @@ class AccountRead(AccountBase):
3742
id: int
3843
balance: Decimal
3944
timezone: TimeZoneName
45+
created_at: datetime
4046

4147

4248
class AccountUpdate(SQLModel):

backend/kayman/tests/crud/test_account.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def assert_account_matches(
3737
# - a server-assigned id for new accounts
3838
if isinstance(expected, Account):
3939
assert actual.id == expected.id
40+
assert actual.created_at == expected.created_at
4041
else:
4142
assert actual.id is not None
43+
assert actual.created_at is not None
4244

4345
# balance should be
4446
# - 0 for new accounts

backend/kayman/tests/factories/account.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import UTC, datetime
2+
13
import factory
24
from factory.alchemy import SQLAlchemyModelFactory
35

@@ -15,3 +17,4 @@ class Meta:
1517
currency_code = factory.SelfAttribute("currency.code")
1618
balance = factory.Faker("pydecimal", left_digits=5, right_digits=2)
1719
timezone = "UTC"
20+
created_at = factory.LazyFunction(lambda: datetime.now(UTC))

0 commit comments

Comments
 (0)