Skip to content

feat: PostgreSQL/pgvector database backend #140

@RobertLD

Description

@RobertLD

Summary

Add PostgreSQL with pgvector as an alternative database backend to SQLite, enabling multi-user concurrent access and horizontal scaling.

Motivation

SQLite is perfect for personal use but has single-writer limitations. PostgreSQL with pgvector unlocks: concurrent multi-user access, team deployments, cloud-hosted instances, and is required for any SaaS/hosted offering.

Implementation

  • src/db/postgres.ts — PostgreSQL connection manager using pg (node-postgres)
  • src/db/backend.ts — Abstract database interface that both SQLite and Postgres implement
  • src/db/migrations-pg.ts — PostgreSQL-specific schema migrations (pgvector types, GIN indexes)
  • Refactor src/db/schema.ts to be backend-agnostic
  • Config: LIBSCOPE_DB_URL=postgresql://... or libscope config set db.backend postgres

Key Differences from SQLite

  • Vector search via pgvector <-> (cosine distance) instead of sqlite-vec
  • FTS via tsvector + ts_query instead of FTS5
  • Connection pooling (pg Pool)
  • Proper concurrent transactions

Migration Path

  • libscope migrate --to postgres --url <pg-url> — migrate existing SQLite data to Postgres
  • Auto-detect backend from connection string

Acceptance Criteria

  • Database interface abstraction (SQLite + Postgres implement same interface)
  • Postgres connection manager with pooling
  • All schema migrations ported to Postgres/pgvector
  • Vector search working with pgvector
  • Full-text search working with tsvector
  • Migration tool from SQLite → Postgres
  • All existing tests pass against both backends
  • Integration test suite for Postgres (can use Docker)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions