From cf1152571df7c7710504963cae82729e4eca5254 Mon Sep 17 00:00:00 2001 From: ooodc <549496103@qq.com> Date: Sat, 6 Jun 2026 15:07:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=86=85=E5=AD=98?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9A=84=E5=8E=BB=E9=87=8D=E5=92=8C=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=20scope=5Fkey=20=E4=B8=BA=20"default"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/storage/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 1326709..28c37a3 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1729,6 +1729,26 @@ fn ensure_scheduler_schema(conn: &Connection) -> Result<(), StorageError> { } fn ensure_memory_scope_key_migration(conn: &Connection) -> Result<(), StorageError> { + // 步骤1:去重。多条记录 scope_key 不同,改为 "default" 后会违反唯一约束。 + // 对每个 (scope_kind, namespace, memory_key) 组合保留 updated_at 最新的一条。 + conn.execute( + " + DELETE FROM memories + WHERE rowid NOT IN ( + SELECT rowid FROM ( + SELECT rowid, ROW_NUMBER() OVER ( + PARTITION BY scope_kind, namespace, memory_key + ORDER BY updated_at DESC + ) AS rn + FROM memories + ) + WHERE rn = 1 + ) + ", + [], + )?; + + // 步骤2:统一 scope_key conn.execute( "UPDATE memories SET scope_key = 'default' WHERE scope_key != 'default'", [],