Skip to content

Conversation

@allenlinli
Copy link

📋 Description

Currently, the database of OpenMemory is not persistent because of the relative path in .env.example.

This PR fixes Docker database persistence issues and improves development environment setup. The primary change updates OM_DB_PATH to use an absolute path (/data/openmemory.sqlite) instead of a relative path (./data/openmemory.sqlite), ensuring the database persists across container restarts when using Docker volumes.

Key Changes

  1. Database Path Fix (Commit d5256a7)
    - Changed OM_DB_PATH from ./data/openmemory.sqlite to /data/openmemory.sqlite
    - Ensures database persists across container restarts when using Docker volume
    - Aligns with Docker best practices (data in /data, not /app/data)
    - Code fallbacks remain unchanged for local development compatibility
  2. Migration Script Refactor (Commit 6669b27)
    - Updated migrate.ts to use env.db_path instead of duplicating path logic
    - Improves code maintainability and consistency
  3. Backward Compatibility (Commit df05c5d)
    - Added backend symlink pointing to packages/openmemory-js
    - Maintains compatibility with VS Code extension and documentation that reference backend/ directory
    - Fixes issues after backend directory was removed in Beta 1.3.0
  4. Development Environment (Commit 27b9057)
    - Added nodemon@^3.1.11 to devDependencies
    - Fixes missing dependency that was already used in the dev script since Dec 9, 2025
    - Ensures npm run dev works on fresh installs without global nodemon

Updated Files

Database Path Changes:

  • .env.example: Updated configuration template
  • ARCHITECTURE.md: Updated documentation example
  • packages/openmemory-js/README.md: Updated JavaScript package docs
  • packages/openmemory-py/README.md: Updated Python package docs

Other Changes:

  • backend (symlink): Added for backward compatibility
  • packages/openmemory-js/package.json: Added nodemon dependency
  • packages/openmemory-js/package-lock.json: Updated with nodemon packages
  • packages/openmemory-js/src/core/migrate.ts: Refactored to use env.db_path

🔄 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

🧪 Testing

  • I have tested this change locally
  • Verified database persists after docker compose down && docker compose up
  • Verified npm run dev works after fresh npm install
  • Verified backward compatibility with VS Code extension
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Testing Steps

  1. Test Local Development:
    git clone https://github.com/CaviraOSS/OpenMemory.git
    cd OpenMemory
    cp .env.example .env

cd backend
npm install
npm run dev # default :8080

  1. Test Docker Persistence:

Start containers

docker compose up -d

Add some test memories (use API or dashboard)

curl -X POST http://localhost:8080/api/memories
-H "Content-Type: application/json"
-d '{"content": "test memory"}'

Stop containers

docker compose down

Restart containers

docker compose up -d

Verify memories persist

curl http://localhost:8080/api/memories

  1. Test VS Code Extension:
  • Verified extension can find backend at backend/dist/ai/mcp.js via symlink
  • MCP server path resolution works correctly

🔍 Code Review Checklist

  • Code follows the project's coding standards
  • Self-review of the code has been performed
  • Code is properly commented, particularly in hard-to-understand areas
  • Changes generate no new warnings
  • Any dependent changes have been merged and published

📚 Related Issues

Fixes database persistence issue in Docker deployments where data was lost on container restart.

🚀 Deployment Notes

Docker Users:

  • Database will now persist in the volume mounted at /data
  • No action required - upgrade path is automatic
  • Existing relative paths will continue to work for local development

Local Development:

  • First-time contributors can now run npm install && npm run dev without needing global nodemon
  • Backend directory symlink ensures all documentation paths remain valid

📋 Additional Context

Why Absolute Path?

The relative path ./data/openmemory.sqlite resolves to /app/data/openmemory.sqlite inside the Docker container (since the working directory is /app). This directory is not mounted to a volume, so data is lost when the container is removed.

The absolute path /data/openmemory.sqlite points to the Docker volume mount, ensuring persistence.

Backward Compatibility

  • Code fallbacks still support relative paths for local development
  • The symlink ensures VS Code extension and documentation references to backend/ continue to work
  • No breaking changes for existing deployments

Thank you!

allenlinli and others added 4 commits January 17, 2026 15:07
…ence

- Change OM_DB_PATH from ./data/openmemory.sqlite to /data/openmemory.sqlite
- Ensures database persists across container restarts when using Docker volume
- Aligns with Docker best practices (data in /data, not /app/data)
- Code fallbacks remain unchanged for local development compatibility

Updated files:
- .env.example: configuration template
- ARCHITECTURE.md: documentation example
- packages/openmemory-js/README.md: JavaScript package docs
- packages/openmemory-py/README.md: Python package docs

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove duplicate environment variable reading in migrate.ts
- Use centralized env.db_path from cfg.ts for consistency
- Ensures consistent fallback behavior across all DB initialization code

Before: process.env.OM_DB_PATH || "./data/openmemory.sqlite"
After:  env.db_path (already handles env var + fallback in cfg.ts)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The backend directory was removed in Beta 1.3.0 when code was moved to
packages/openmemory-js. However, VS Code extension and documentation
still reference backend/dist/ai/mcp.js path.

This symlink restores backward compatibility without duplicating code.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The dev script has been using nodemon since Dec 9, 2025 (commit fb5a833),
but the dependency was never formally declared in package.json. This caused
the dev script to fail on fresh installs unless nodemon was globally installed.

This change adds nodemon@^3.1.11 to devDependencies, ensuring the development
environment works correctly after npm ci or fresh npm install.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

# Conflicts:
#	packages/openmemory-js/package-lock.json
@allenlinli allenlinli force-pushed the fix/make-database-persistent-in-example branch from 27b9057 to a5a83f3 Compare January 17, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant