Skip to content

Add persistent storage backend (SQLite/PostgreSQL) #1

Description

@mkmkkkkk

Problem

Currently SpendTracker only records transactions in memory. All spending history and policy state is lost on restart. This is fine for development but unacceptable for production deployments.

Proposed Solution

Implement a StorageBackend interface with the adapter pattern:

interface StorageBackend {
  recordTransaction(tx: Transaction): Promise<void>;
  getTransactions(filter: TransactionFilter): Promise<Transaction[]>;
  getSpendingTotal(agentId: string, window: TimeWindow): Promise<number>;
}

Implementation Plan

  1. Phase 1: SQLite — Zero-config, embedded, perfect for single-node deployments
  2. Phase 2: PostgreSQL — For multi-instance / production environments
  3. Phase 3: Migration tooling — Schema versioning with automatic migrations

Acceptance Criteria

  • StorageBackend interface defined
  • SQLite adapter implemented and tested
  • Existing in-memory tracker refactored to implement the same interface
  • Configuration via environment variables (PAYSENTRY_STORAGE=sqlite|memory)
  • Documentation updated with storage configuration guide

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions