Skip to content

[FEATURE] Unify database_url configuration for Postgres and SQLite #539

Description

@divideby0

Feature Description

Extend BASIC_MEMORY_DATABASE_URL to accept SQLite URLs (for custom paths) and extract search_path from Postgres URLs (for schema isolation).

Problem This Feature Solves

Users need database isolation without dedicated infrastructure:

  • Git worktrees share ~/.basic-memory/memory.db, causing index conflicts between branches
  • Project portability - can't clone a repo and have BM "just work" with a project-local index
  • Shared Postgres - can't coexist with other apps in an existing database (no schema support)

Currently database_url only works for Postgres and ignores SQLite.

Proposed Solution

  1. Accept SQLite URLs - Enable project-local databases:

    sqlite+aiosqlite:///.basic-memory/memory.db
    
  2. Extract search_path from Postgres URLs - Enable schema isolation:

    postgresql+asyncpg://host/db?search_path=basic_memory
    

    (asyncpg rejects this param directly, so BM extracts it and passes to server_settings)

  3. Auto-create schema - Run CREATE SCHEMA IF NOT EXISTS before migrations

  4. Set Alembic version_table_schema - Ensure migration tracking uses the same schema

Alternative Solutions

Additional Context

  • SQLite: three slashes = relative, four = absolute (SQLAlchemy convention)
  • Postgres: search_path supports multiple schemas (myschema,public)
  • Backwards compatible - no config = current behavior
  • Cloud mode unaffected (uses remote API)
  • Markdown remains source of truth; index rebuilds if path changes

Impact

Enables project-scoped databases without requiring dedicated Postgres instances or polluting user-level state. Particularly useful for teams using git worktrees or developers working across multiple projects.

I'm planning to prepare a PR for this and would appreciate feedback on the approach.

Activity

  1. added 2 commits that reference this issue on Feb 2, 2026
    62c37b3
    213331f
  2. phernandez commented on Aug 29, 2026

    @phernandez
    Member

    Triage: still wanted, not scheduled. Both halves are reasonable — a SQLite database_url for a project-local index (worktrees are the motivating case) and search_path on Postgres URLs for schema isolation. The Postgres side needs care with the Alembic env (migrations run per URL) and the cloud runtime, which sets its own URL; the SQLite side is mostly config plumbing plus the WAL/pragma setup in db.py. Happy to review a PR that starts with the SQLite half.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions