fix: migrate memory domain before indexing
这个提交存在于:
父节点
66b5d0bf70
当前提交
a8598e755d
共有 3 个文件被更改,包括 36 次插入 和 2 次删除
|
|
@ -236,8 +236,6 @@ class MemoryStore:
|
|||
supersedes_id TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_memories_domain ON memories(memory_domain, lifecycle, scope, group_id, subject_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_memories_scope_session
|
||||
ON memories(scope, session_id, group_id, subject_id, object_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_memories_visibility
|
||||
|
|
@ -491,6 +489,9 @@ class MemoryStore:
|
|||
"""
|
||||
)
|
||||
self._ensure_memory_columns_sync()
|
||||
self._conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_memories_domain ON memories(memory_domain, lifecycle, scope, group_id, subject_id)"
|
||||
)
|
||||
self._ensure_timeline_columns_sync()
|
||||
self._ensure_acl_columns_sync()
|
||||
self._ensure_memory_fts_sync()
|
||||
|
|
|
|||
|
|
@ -105,3 +105,13 @@
|
|||
- 修复或规避:不修改普通陪伴分支;将宿主依赖测试单独标记为环境阻塞,其余 142 项运维版测试正常执行。
|
||||
- 预防规则:跨插件测试必须区分纯单元测试与宿主集成测试;宿主依赖缺失不能被误报为业务回归。
|
||||
- 验证证据:`compileall -q core tests page_api.py` 通过;`git diff --check` 通过;排除 `test_security_cache` 后 `142 tests` 全部通过;定向 Q5、Q4.2、总结、检索和存储测试全部通过。
|
||||
|
||||
## 2026-07-25 — Q5 首次 VM 部署暴露旧库索引迁移顺序
|
||||
|
||||
- 阶段:Q5 VM 部署验收与修复
|
||||
- 类型:部署 / 数据库迁移 / API契约
|
||||
- 现象:提交 `66b5d0b` 部署后 AstrBot 服务仍 active,但运维记忆插件初始化失败,日志报 `sqlite3.OperationalError: no such column: memory_domain`,Archivist 自动降级。
|
||||
- 根因:`memories` 旧表在字段迁移前执行了依赖新字段的 `idx_memories_domain` 创建。
|
||||
- 修复或规避:将域索引创建移动到 `_ensure_memory_columns_sync()` 之后;增加真实 Q4 schema 去掉单字段的升级测试;不删除或重建用户数据目录。
|
||||
- 预防规则:任何新增数据库列必须先完成幂等字段迁移,再创建索引、触发器和查询约束;部署验收必须看插件加载日志和 Bridge 可用性,不能只看 systemd active。
|
||||
- 验证证据:本地旧库迁移测试通过;待修复提交重新部署后复核插件加载、Archivist capability、服务状态和数据目录。
|
||||
|
|
|
|||
|
|
@ -82,6 +82,29 @@ class UserMemoryContractTests(unittest.IsolatedAsyncioTestCase):
|
|||
with self.assertRaisesRegex(UserMemoryBoundaryError, "missing_user_evidence"):
|
||||
validate_user_memory_record(record)
|
||||
|
||||
async def test_existing_q4_database_adds_domain_before_domain_index(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
seed_path = Path(temp) / "seed.db"
|
||||
legacy_path = Path(temp) / "legacy.db"
|
||||
seed = MemoryStore(seed_path)
|
||||
seed.initialize()
|
||||
schema = seed._conn.execute(
|
||||
"SELECT sql FROM sqlite_master WHERE type='table' AND name='memories'"
|
||||
).fetchone()[0]
|
||||
seed.close()
|
||||
legacy_schema = schema.replace(",\n memory_domain TEXT NOT NULL DEFAULT 'unknown'", "")
|
||||
connection = __import__("sqlite3").connect(legacy_path)
|
||||
connection.execute(legacy_schema)
|
||||
connection.commit()
|
||||
connection.close()
|
||||
store = MemoryStore(legacy_path)
|
||||
store.initialize()
|
||||
columns = {row["name"] for row in store._conn.execute("PRAGMA table_info(memories)").fetchall()}
|
||||
indexes = {row["name"] for row in store._conn.execute("PRAGMA index_list(memories)").fetchall()}
|
||||
self.assertIn("memory_domain", columns)
|
||||
self.assertIn("idx_memories_domain", indexes)
|
||||
store.close()
|
||||
|
||||
async def test_store_persists_time_domain_and_deduplicates_explicit_id(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
store = MemoryStore(Path(temp) / "memory.db")
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用