feat(persistence): add SQLAlchemy 2.0 async ORM scaffold

Introduce a unified database configuration (DatabaseConfig) that
controls both the LangGraph checkpointer and the DeerFlow application
persistence layer from a single `database:` config section.

New modules:
- deerflow.config.database_config — Pydantic config with memory/sqlite/postgres backends
- deerflow.persistence — async engine lifecycle, DeclarativeBase with to_dict mixin, Alembic skeleton
- deerflow.runtime.runs.store — RunStore ABC + MemoryRunStore implementation

Gateway integration initializes/tears down the persistence engine in
the existing langgraph_runtime() context manager. Legacy checkpointer
config is preserved for backward compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
rayhpeng
2026-04-01 15:50:06 +08:00
parent 3e461d9d08
commit 1ff6b5f7ab
18 changed files with 1099 additions and 17 deletions
+29
View File
@@ -584,6 +584,35 @@ checkpointer:
# type: postgres
# connection_string: postgresql://user:password@localhost:5432/deerflow
# ============================================================================
# Database
# ============================================================================
# Unified storage backend for LangGraph checkpointer and DeerFlow
# application data (runs, threads metadata, etc.).
#
# backend: memory -- No persistence, data lost on restart (default)
# backend: sqlite -- Single-node deployment, files in sqlite_dir
# backend: postgres -- Production multi-node deployment
#
# SQLite mode automatically uses separate .db files for checkpointer
# and application data to avoid write-lock contention.
#
# Postgres mode: put your connection URL in .env as DATABASE_URL,
# then reference it here with $DATABASE_URL.
# Install the postgres driver: uv sync --extra postgres
#
# NOTE: When both `checkpointer` and `database` are configured,
# `checkpointer` takes precedence for LangGraph state persistence.
# If you use `database`, you can remove the `checkpointer` section.
#
# database:
# backend: sqlite
# sqlite_dir: ./data
#
# database:
# backend: postgres
# postgres_url: $DATABASE_URL
# ============================================================================
# IM Channels Configuration
# ============================================================================