feat: Datenmodell (SQLAlchemy) und Alembic-Migration

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 17:09:02 +02:00
parent 53ffd65104
commit d37cb230c4
10 changed files with 633 additions and 0 deletions

17
finance/tests/conftest.py Normal file
View File

@@ -0,0 +1,17 @@
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from sqlalchemy.pool import StaticPool
from app.db import Base
@pytest.fixture
def db():
engine = create_engine(
"sqlite://", poolclass=StaticPool,
connect_args={"check_same_thread": False},
)
Base.metadata.create_all(engine)
with Session(engine) as session:
yield session

View File

@@ -0,0 +1,24 @@
from datetime import date
from decimal import Decimal
from app.models.tables import Account, Statement, Transaction
def test_account_transaction_roundtrip(db):
acc = Account(bank="DKB", iban="DE02120300000000202051", name="Giro", type="giro")
db.add(acc)
db.flush()
st = Statement(filename="a.pdf", bank="DKB", account_id=acc.id,
period_start=date(2026, 6, 1), period_end=date(2026, 6, 30),
opening_balance=Decimal("100.00"), closing_balance=Decimal("50.00"),
status="draft")
db.add(st)
db.flush()
tx = Transaction(account_id=acc.id, statement_id=st.id,
booking_date=date(2026, 6, 3), value_date=date(2026, 6, 3),
amount=Decimal("-50.00"), purpose="Miete Juni",
counterparty="Vermieter GmbH", status="draft",
dedup_hash="abc", is_duplicate=False)
db.add(tx)
db.commit()
assert db.query(Transaction).one().amount == Decimal("-50.00")