Add the data layer for the spending analysis app including models for household members, accounts, categories, transactions, categorization rules, and CSV import mappings. All models use SQLAlchemy 2.0 mapped columns with proper foreign key relationships. Includes db.py with Base class, engine/session factories, and 6 passing tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
777 B
Python
25 lines
777 B
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from src.db import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from src.models.household import HouseholdMember
|
|
|
|
|
|
class Account(Base):
|
|
__tablename__ = "accounts"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(100))
|
|
institution: Mapped[str] = mapped_column(String(100))
|
|
account_type: Mapped[str] = mapped_column(String(20))
|
|
owner_id: Mapped[int | None] = mapped_column(ForeignKey("household_members.id"))
|
|
is_shared: Mapped[bool] = mapped_column(default=False)
|
|
|
|
owner: Mapped[HouseholdMember | None] = relationship(back_populates="accounts")
|