From 90c3dc98ca65065b2a11fc41a7e1bae0747d7a3c Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Tue, 23 Jun 2026 12:59:50 +0530 Subject: [PATCH] fix(zero):add authz parent schemas --- surfsense_web/zero/schema/automations.ts | 7 ++++ surfsense_web/zero/schema/chat.ts | 7 ++++ surfsense_web/zero/schema/index.ts | 46 +++++++++++++++++++++--- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/surfsense_web/zero/schema/automations.ts b/surfsense_web/zero/schema/automations.ts index 4d6ebfac7..f9b89c533 100644 --- a/surfsense_web/zero/schema/automations.ts +++ b/surfsense_web/zero/schema/automations.ts @@ -1,5 +1,12 @@ import { json, number, string, table } from "@rocicorp/zero"; +export const automationTable = table("automations") + .columns({ + id: number(), + searchSpaceId: number().from("search_space_id"), + }) + .primaryKey("id"); + // Thin live row: status + per-step progress only. Heavy fields // (definition_snapshot, inputs, output, artifacts, error) stay on REST // (`GET /automations/{id}/runs/{run_id}`) and load on detail expand. diff --git a/surfsense_web/zero/schema/chat.ts b/surfsense_web/zero/schema/chat.ts index 8da41ee45..07229ac94 100644 --- a/surfsense_web/zero/schema/chat.ts +++ b/surfsense_web/zero/schema/chat.ts @@ -20,6 +20,13 @@ export const newChatMessageTable = table("new_chat_messages") }) .primaryKey("id"); +export const newChatThreadTable = table("new_chat_threads") + .columns({ + id: number(), + searchSpaceId: number().from("search_space_id"), + }) + .primaryKey("id"); + export const chatCommentTable = table("chat_comments") .columns({ id: number(), diff --git a/surfsense_web/zero/schema/index.ts b/surfsense_web/zero/schema/index.ts index d1187ddab..915135c19 100644 --- a/surfsense_web/zero/schema/index.ts +++ b/surfsense_web/zero/schema/index.ts @@ -1,6 +1,11 @@ import { createBuilder, createSchema, relationships } from "@rocicorp/zero"; -import { automationRunTable } from "./automations"; -import { chatCommentTable, chatSessionStateTable, newChatMessageTable } from "./chat"; +import { automationRunTable, automationTable } from "./automations"; +import { + chatCommentTable, + chatSessionStateTable, + newChatMessageTable, + newChatThreadTable, +} from "./chat"; import { documentTable, searchSourceConnectorTable } from "./documents"; import { folderTable } from "./folders"; import { notificationTable } from "./inbox"; @@ -18,14 +23,40 @@ const chatCommentRelationships = relationships(chatCommentTable, ({ one }) => ({ destSchema: chatCommentTable, destField: ["id"], }), + thread: one({ + sourceField: ["threadId"], + destSchema: newChatThreadTable, + destField: ["id"], + }), })); -const newChatMessageRelationships = relationships(newChatMessageTable, ({ many }) => ({ +const newChatMessageRelationships = relationships(newChatMessageTable, ({ one, many }) => ({ comments: many({ sourceField: ["id"], destSchema: chatCommentTable, destField: ["messageId"], }), + thread: one({ + sourceField: ["threadId"], + destSchema: newChatThreadTable, + destField: ["id"], + }), +})); + +const chatSessionStateThreadRelationships = relationships(chatSessionStateTable, ({ one }) => ({ + thread: one({ + sourceField: ["threadId"], + destSchema: newChatThreadTable, + destField: ["id"], + }), +})); + +const automationRunRelationships = relationships(automationRunTable, ({ one }) => ({ + automation: one({ + sourceField: ["automationId"], + destSchema: automationTable, + destField: ["id"], + }), })); export const schema = createSchema({ @@ -34,14 +65,21 @@ export const schema = createSchema({ documentTable, folderTable, searchSourceConnectorTable, + newChatThreadTable, newChatMessageTable, chatCommentTable, chatSessionStateTable, userTable, + automationTable, automationRunTable, podcastTable, ], - relationships: [chatCommentRelationships, newChatMessageRelationships], + relationships: [ + chatCommentRelationships, + newChatMessageRelationships, + chatSessionStateThreadRelationships, + automationRunRelationships, + ], }); export type Schema = typeof schema;