make memory migration additive and drop unused sourceThreadId

This commit is contained in:
shatfield4
2026-04-23 18:36:21 -07:00
parent 5c96c97986
commit c3fbd53c63
6 changed files with 36 additions and 63 deletions

View File

@@ -8,7 +8,6 @@ import { baseHeaders } from "@/utils/request";
* @property {number|null} workspaceId
* @property {"workspace"|"global"} scope
* @property {string} content
* @property {number|null} sourceThreadId
* @property {string|null} lastUsedAt
* @property {string} createdAt
* @property {string} updatedAt

View File

@@ -44,7 +44,7 @@ When finished you MUST call the save-memories tool with your final list. Do not
// Phase 1 — discover (user, workspace) groups with unprocessed visible chats.
// include:true filters out chats deleted via /reset — they must never be summarized.
const allUnprocessed = await WorkspaceChats.where(
{ memoryProcessed: false, include: true },
{ memoryProcessed: null, include: true },
null,
{ createdAt: "asc" }
);

View File

@@ -11,7 +11,6 @@ const VALID_SCOPES = ["workspace", "global"];
* @property {number|null} workspaceId
* @property {"workspace"|"global"} scope
* @property {string} content
* @property {number|null} sourceThreadId
* @property {Date|null} lastUsedAt
* @property {Date} createdAt
* @property {Date} updatedAt
@@ -93,7 +92,6 @@ const Memory = {
* @param {number|null} [params.workspaceId]
* @param {"workspace"|"global"} [params.scope]
* @param {string} params.content
* @param {number|null} [params.sourceThreadId]
* @returns {Promise<{memory: Memory|null, message: string|null}>}
*/
create: async function ({
@@ -101,7 +99,6 @@ const Memory = {
workspaceId = null,
scope = "workspace",
content,
sourceThreadId = null,
}) {
try {
const count = await this.countForScope(userId, workspaceId, scope);
@@ -121,7 +118,6 @@ const Memory = {
workspaceId: this.validations.workspaceId(workspaceId),
scope: this.validations.scope(scope),
content: this.validations.content(content),
sourceThreadId: this.validations.workspaceId(sourceThreadId),
},
});
return { memory, message: null };

View File

@@ -1,43 +0,0 @@
-- CreateTable
CREATE TABLE "memories" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER,
"workspace_id" INTEGER,
"scope" TEXT NOT NULL DEFAULT 'workspace',
"content" TEXT NOT NULL,
"source_thread_id" INTEGER,
"last_used_at" DATETIME,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "memories_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "memories_workspace_id_fkey" FOREIGN KEY ("workspace_id") REFERENCES "workspaces" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_workspace_chats" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"workspaceId" INTEGER NOT NULL,
"prompt" TEXT NOT NULL,
"response" TEXT NOT NULL,
"include" BOOLEAN NOT NULL DEFAULT true,
"user_id" INTEGER,
"thread_id" INTEGER,
"api_session_id" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastUpdatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"feedbackScore" BOOLEAN,
"memory_processed" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "workspace_chats_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_workspace_chats" ("api_session_id", "createdAt", "feedbackScore", "id", "include", "lastUpdatedAt", "prompt", "response", "thread_id", "user_id", "workspaceId") SELECT "api_session_id", "createdAt", "feedbackScore", "id", "include", "lastUpdatedAt", "prompt", "response", "thread_id", "user_id", "workspaceId" FROM "workspace_chats";
DROP TABLE "workspace_chats";
ALTER TABLE "new_workspace_chats" RENAME TO "workspace_chats";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
-- CreateIndex
CREATE INDEX "memories_user_id_workspace_id_idx" ON "memories"("user_id", "workspace_id");
-- CreateIndex
CREATE INDEX "memories_user_id_scope_idx" ON "memories"("user_id", "scope");

View File

@@ -0,0 +1,22 @@
-- AlterTable
ALTER TABLE "workspace_chats" ADD COLUMN "memory_processed" BOOLEAN;
-- CreateTable
CREATE TABLE "memories" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER,
"workspace_id" INTEGER,
"scope" TEXT NOT NULL DEFAULT 'workspace',
"content" TEXT NOT NULL,
"last_used_at" DATETIME,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "memories_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "memories_workspace_id_fkey" FOREIGN KEY ("workspace_id") REFERENCES "workspaces" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateIndex
CREATE INDEX "memories_user_id_workspace_id_idx" ON "memories"("user_id", "workspace_id");
-- CreateIndex
CREATE INDEX "memories_user_id_scope_idx" ON "memories"("user_id", "scope");

View File

@@ -189,9 +189,9 @@ model workspace_chats {
api_session_id String? // String identifier for only the dev API to partition chats in any mode.
createdAt DateTime @default(now())
lastUpdatedAt DateTime @default(now())
feedbackScore Boolean?
memoryProcessed Boolean @default(false) @map("memory_processed")
users users? @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
feedbackScore Boolean?
memoryProcessed Boolean? @map("memory_processed")
users users? @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
}
model workspace_agent_invocations {
@@ -400,18 +400,17 @@ model external_communication_connectors {
}
model memories {
id Int @id @default(autoincrement())
userId Int? @map("user_id")
workspaceId Int? @map("workspace_id")
scope String @default("workspace")
content String
sourceThreadId Int? @map("source_thread_id")
lastUsedAt DateTime? @map("last_used_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
id Int @id @default(autoincrement())
userId Int? @map("user_id")
workspaceId Int? @map("workspace_id")
scope String @default("workspace")
content String
lastUsedAt DateTime? @map("last_used_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
user users? @relation(fields: [userId], references: [id], onDelete: Cascade)
workspace workspaces? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
user users? @relation(fields: [userId], references: [id], onDelete: Cascade)
workspace workspaces? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
@@index([userId, workspaceId])
@@index([userId, scope])