Description
Define the SQLAlchemy ORM models and database session management for the API backend.
The existing Alembic migrations should be extended or new migration created.
Models to Create
Account — Stellar account info (id, public_key, first_seen, last_active, balance, etc.)
Transaction — Blockchain transactions (hash, ledger, source, destination, amount, asset, fee, timestamp)
FraudAlert — Anomaly detection results (account_id, pattern, risk_score, description, detected_at)
LoyaltyPoints — Points balance per account (account_id, balance, tier, multiplier)
PointsTransaction — Earn/redeem/adjust records (account_id, type, points, source, timestamp)
ModelRegistry — Registered model versions (name, version, path, metrics, created_at)
Session Management
- Create async SQLAlchemy engine and session factory
- Provide a
get_db dependency for FastAPI
- Support both sync and async endpoints
Acceptance Criteria
- All models are defined in
api/models/ directory
- Tables are created by running
alembic upgrade head
- Session management works with FastAPI dependency injection
- Basic CRUD queries work in pytest against a test database
Labels
enhancement, api, database
Description
Define the SQLAlchemy ORM models and database session management for the API backend.
The existing Alembic migrations should be extended or new migration created.
Models to Create
Account— Stellar account info (id, public_key, first_seen, last_active, balance, etc.)Transaction— Blockchain transactions (hash, ledger, source, destination, amount, asset, fee, timestamp)FraudAlert— Anomaly detection results (account_id, pattern, risk_score, description, detected_at)LoyaltyPoints— Points balance per account (account_id, balance, tier, multiplier)PointsTransaction— Earn/redeem/adjust records (account_id, type, points, source, timestamp)ModelRegistry— Registered model versions (name, version, path, metrics, created_at)Session Management
get_dbdependency for FastAPIAcceptance Criteria
api/models/directoryalembic upgrade headLabels
enhancement,api,database