Skip to content

[Database] Implement async CRUD operations for core entities (incidents, model registry, policy audits) #22

@saviornt

Description

@saviornt

Description

Implement reusable, type-safe, async CRUD operations for the main entities so both Appliance and Assistant can safely read/write without duplicating logic.

Type

  • Task

Focus Area (pick one)

  • Shared Utils & Models

Priority

  • Medium

Acceptance Criteria

  • File: shared/src/database/crud.py
  • Async CRUD operations for:
    • Incidents: create, get_by_id, get_recent, get_by_device_mac, mark_resolved
    • ModelRegistry: create_new_version, get_latest, get_by_hash, list_versions
    • PolicyAudits: log_action, get_for_incident
  • All functions accept AsyncSession from session.py
  • Use SQLAlchemy 2.0 select() / insert() / update() style
  • Return Pydantic models via .model_validate(db_obj)
  • Basic filtering + pagination (limit / offset)
  • Proper exception handling (custom NotFoundError, DuplicateError, etc.)
  • Unit tests covering happy path + edge cases (no results, constraint violations)
  • Full Google-style docstrings
  • Type annotations; mypy strict clean

Blocker / Dependencies

  • [Database] Implement robust async SQLite session factory + connection pooling
  • [Database] Define Pydantic v2 models and initial relational schema

Notes / Links

  • Related files: shared/src/database/schemas.py, shared/src/database/models.py

Metadata

Metadata

Assignees

Labels

databaseneeds-triageNew issue that hasn't been reviewed/prioritized yettaskGeneral work item (implementation, setup, cleanup) – most common label

Projects

Status

Manual QA Testing

Relationships

None yet

Development

No branches or pull requests

Issue actions