mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 05:20:44 +08:00
feat(persistence): PostgreSQL assistant store, chat persist fixes, gateway scripts
- Add SQLAlchemy Core repos, pg adapter/compat, assistant_store factory, Alembic bootstrap and migration/cutover scripts. - Harden chat_message writes (NUL scrub for PG), turn_uuid on attempt failure, WS turn_runner fallbacks and gateway executed_turn_uuid init. - start_gateway: log paths, PS7 stderr handling via cmd, background stdout/stderr redirect; runtime assistant_runtime_log_dir export. - Ops: clear_all_chat_sessions with PG-only --postgresql and env-gated wipe; clear_postgres_chat_sessions.ps1. - Tests: SA repos, pg compat, persist fallback, smoke env isolation; CI and docs touch-ups. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2b32d11f43
commit
d14e9d3596
103 changed files with 7574 additions and 1641 deletions
|
|
@ -46,6 +46,45 @@ AIA_PREWARM_INTERVAL_SECONDS=600
|
|||
AIA_ASSISTANT_DB_PATH=
|
||||
OPS_ASSISTANT_DB_PATH=
|
||||
|
||||
# AIA_ASSISTANT_DB_BACKEND / OPS_ASSISTANT_DB_BACKEND 持久化后端:sqlite(默认)或 postgresql。
|
||||
# 设为 postgresql 时需配置 AIA_ASSISTANT_DATABASE_URL。首次连 PG 前在实例上建库(如 CREATE DATABASE oclaw),再应用 schema:
|
||||
# 推荐:alembic upgrade head(或执行 svc/persistence/ddl/postgresql_bootstrap.sql),可选再运行
|
||||
# runtime/operations/scripts/migrate_assistant_sqlite_to_postgresql.py 从 SQLite 迁数据。
|
||||
#
|
||||
# 【Alembic】迁移脚本目录名为 assistant_migrations/(避免与 PyPI 包名 alembic 及 python -m alembic 冲突)。
|
||||
# 仓库根执行:python -m alembic upgrade head(或 alembic.exe -c alembic.ini upgrade head)。
|
||||
# 执行前请设置与本节相同的 PG 环境变量(至少 AIA_ASSISTANT_DB_BACKEND=postgresql 与 AIA_ASSISTANT_DATABASE_URL),以便 env.py 连上目标库。
|
||||
#
|
||||
# 【割接到 PostgreSQL(生产/联调)建议顺序】
|
||||
# 1) 备份当前 SQLite 主库文件(db_path 指向的路径)。
|
||||
# 2) 在 PG 上 CREATE DATABASE …(如 oclaw),并对该库执行 alembic upgrade head。
|
||||
# 3) 运行导入(空库),任选其一(均依赖本机已安装 requirements.txt 含 psycopg、SQLAlchemy):
|
||||
# · Linux / 无头设备:chmod +x runtime/operations/scripts/assistant_import_sqlite_to_postgresql.sh
|
||||
# 后执行 ./runtime/operations/scripts/assistant_import_sqlite_to_postgresql.sh --dry-run 再去掉 --dry-run。
|
||||
# 或 ./runtime/operations/scripts/cutover_sqlite_to_postgresql.sh(含 SQLite 文件备份 + dry-run + 导入)。
|
||||
# · Windows:powershell -ExecutionPolicy Bypass -File runtime/operations/scripts/cutover_sqlite_to_postgresql.ps1 -LoadSystemEnv
|
||||
# · 直接 Python(URL 可读环境变量或 _local/system.env + --load-system-env):
|
||||
# python runtime/operations/scripts/migrate_assistant_sqlite_to_postgresql.py --load-system-env --sqlite-from-db-path --dry-run
|
||||
# 或显式:--sqlite <路径> [--pg-url <postgresql+psycopg或 postgresql 连接串>]
|
||||
# 默认要求 PG 各表为空;若需叠加数据用 --allow-non-empty(自担风险)。
|
||||
# 4) 核对脚本末尾 verify 行数一致后,将 AIA_ASSISTANT_DB_BACKEND=postgresql 与 AIA_ASSISTANT_DATABASE_URL 写入 system.env / 部署环境并重启网关。
|
||||
# 【应用启动顺序】PostgreSQL 模式下须先对目标库执行 schema 迁移(alembic upgrade head),再启动网关;不要在空库上直接启动生产实例(缺表会失败)。数据割接时顺序为:备份 SQLite → 建库并迁移 → 导入脚本 → 再切换 env 并启动应用。
|
||||
AIA_ASSISTANT_DB_BACKEND=
|
||||
OPS_ASSISTANT_DB_BACKEND=
|
||||
|
||||
# AIA_ASSISTANT_DATABASE_URL / OPS_ASSISTANT_DATABASE_URL PostgreSQL 连接串。
|
||||
# 可用 libpq 形式:postgresql://user:pass@host:5432/dbname
|
||||
# 也可用 SQLAlchemy 形式:postgresql+psycopg://user:pass@host:5432/dbname(与 SQLAlchemy URL 一致;原生 psycopg 连接前会自动去掉 +psycopg)。
|
||||
# 别名:AIA_ASSISTANT_PG_DSN / OPS_ASSISTANT_PG_DSN。
|
||||
# AIA_TEST_PG_URL 仅 pytest:若设置,tests/test_database_backend.py::test_get_assistant_store_postgresql_smoke 会连真实 PG;
|
||||
# 可与 AIA_ASSISTANT_DATABASE_URL 填同一串(含 postgresql+psycopg:// 亦可)。
|
||||
AIA_ASSISTANT_DATABASE_URL=
|
||||
OPS_ASSISTANT_DATABASE_URL=
|
||||
AIA_TEST_PG_URL=
|
||||
|
||||
# AIA_LOG_CHAT_MESSAGE_PERSIST 设为 1/true/on 时,每次成功写入 chat_message 后打一条 WARNING 日志(含 backend、session_id、message_id、role、event_type),便于在 gateway.err.log 里 grep「chat_message_persisted」;默认关闭。
|
||||
# AIA_LOG_CHAT_MESSAGE_PERSIST=
|
||||
|
||||
# AIA_ASSISTANT_MASTER_KEY 用于加密迁移密钥等;不设则部分迁移不可用。
|
||||
# 【前端】管理后台「密钥迁移」相关界面会检测是否配置(提示文案)。
|
||||
AIA_ASSISTANT_MASTER_KEY=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue