Skip to content

refactor(db): extract Database trait abstraction layer (Phase 1) #166

Description

@ajianaz

Phase 1 — Foundation: isolate SQLite-specific code behind generic trait

Goal

Create trapfall-db crate with a Database trait. Move all 60+ raw SQL queries from store.rs + auth.rs into SqliteBackend impl. Zero behavior change.

Tasks

  • Create crates/trapfall-db/ with lib.rs, schema.rs, sqlite.rs
  • Define Database trait with all store methods (projects, issues, events, auth, alerts, lifecycle)
  • Move entity structs (Project, Issue, Event, User, Session, AlertRule, AuthAttempt) to schema.rs
  • Implement SqliteBackend — copy existing SQLite queries from store.rs + auth.rs
  • Update AppState to hold Box<dyn Database> instead of SqlitePool
  • Update all consumers: server.rs, digest.rs, alert.rs, retention.rs, ws.rs, metrics.rs, search.rs, mcp.rs
  • Run full test suite — all tests pass, zero behavior change

Acceptance Criteria

  • trapfall-db crate compiles and passes tests
  • trapfalld uses Box<dyn Database> everywhere
  • No SqlitePool reference outside sqlite.rs
  • All existing tests pass

Effort

~1-2 days

Depends on

None — this is the foundation for all other phases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:multi-backendEpic: SQLite + Postgres multi-backend supportpriority:highP1 - Fix soonrefactorCode refactoring or restructuringv0.0.5v0.0.5 milestone

    Type

    No type

    Fields

    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