Skip to content

[FEATURE] Database Session & Models — SQLAlchemy tables for accounts, transactions, alerts, loyalty #231

@gelluisaac

Description

@gelluisaac

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions