feat(core): add workspace_id to session table (#15410)
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `session` ADD `workspace_id` text;--> statement-breakpoint
|
||||||
|
CREATE INDEX `session_workspace_idx` ON `session` (`workspace_id`);
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,7 @@ import { SessionPrompt } from "./prompt"
|
|||||||
import { fn } from "@/util/fn"
|
import { fn } from "@/util/fn"
|
||||||
import { Command } from "../command"
|
import { Command } from "../command"
|
||||||
import { Snapshot } from "@/snapshot"
|
import { Snapshot } from "@/snapshot"
|
||||||
|
import { WorkspaceContext } from "../control-plane/workspace-context"
|
||||||
|
|
||||||
import type { Provider } from "@/provider/provider"
|
import type { Provider } from "@/provider/provider"
|
||||||
import { PermissionNext } from "@/permission/next"
|
import { PermissionNext } from "@/permission/next"
|
||||||
@@ -63,6 +64,7 @@ export namespace Session {
|
|||||||
id: row.id,
|
id: row.id,
|
||||||
slug: row.slug,
|
slug: row.slug,
|
||||||
projectID: row.project_id,
|
projectID: row.project_id,
|
||||||
|
workspaceID: row.workspace_id ?? undefined,
|
||||||
directory: row.directory,
|
directory: row.directory,
|
||||||
parentID: row.parent_id ?? undefined,
|
parentID: row.parent_id ?? undefined,
|
||||||
title: row.title,
|
title: row.title,
|
||||||
@@ -84,6 +86,7 @@ export namespace Session {
|
|||||||
return {
|
return {
|
||||||
id: info.id,
|
id: info.id,
|
||||||
project_id: info.projectID,
|
project_id: info.projectID,
|
||||||
|
workspace_id: info.workspaceID,
|
||||||
parent_id: info.parentID,
|
parent_id: info.parentID,
|
||||||
slug: info.slug,
|
slug: info.slug,
|
||||||
directory: info.directory,
|
directory: info.directory,
|
||||||
@@ -118,6 +121,7 @@ export namespace Session {
|
|||||||
id: Identifier.schema("session"),
|
id: Identifier.schema("session"),
|
||||||
slug: z.string(),
|
slug: z.string(),
|
||||||
projectID: z.string(),
|
projectID: z.string(),
|
||||||
|
workspaceID: z.string().optional(),
|
||||||
directory: z.string(),
|
directory: z.string(),
|
||||||
parentID: Identifier.schema("session").optional(),
|
parentID: Identifier.schema("session").optional(),
|
||||||
summary: z
|
summary: z
|
||||||
@@ -297,6 +301,7 @@ export namespace Session {
|
|||||||
version: Installation.VERSION,
|
version: Installation.VERSION,
|
||||||
projectID: Instance.project.id,
|
projectID: Instance.project.id,
|
||||||
directory: input.directory,
|
directory: input.directory,
|
||||||
|
workspaceID: WorkspaceContext.workspaceID,
|
||||||
parentID: input.parentID,
|
parentID: input.parentID,
|
||||||
title: input.title ?? createDefaultTitle(!!input.parentID),
|
title: input.title ?? createDefaultTitle(!!input.parentID),
|
||||||
permission: input.permission,
|
permission: input.permission,
|
||||||
@@ -527,6 +532,7 @@ export namespace Session {
|
|||||||
|
|
||||||
export function* list(input?: {
|
export function* list(input?: {
|
||||||
directory?: string
|
directory?: string
|
||||||
|
workspaceID?: string
|
||||||
roots?: boolean
|
roots?: boolean
|
||||||
start?: number
|
start?: number
|
||||||
search?: string
|
search?: string
|
||||||
@@ -535,6 +541,9 @@ export namespace Session {
|
|||||||
const project = Instance.project
|
const project = Instance.project
|
||||||
const conditions = [eq(SessionTable.project_id, project.id)]
|
const conditions = [eq(SessionTable.project_id, project.id)]
|
||||||
|
|
||||||
|
if (WorkspaceContext.workspaceID) {
|
||||||
|
conditions.push(eq(SessionTable.workspace_id, WorkspaceContext.workspaceID))
|
||||||
|
}
|
||||||
if (input?.directory) {
|
if (input?.directory) {
|
||||||
conditions.push(eq(SessionTable.directory, input.directory))
|
conditions.push(eq(SessionTable.directory, input.directory))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export const SessionTable = sqliteTable(
|
|||||||
project_id: text()
|
project_id: text()
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => ProjectTable.id, { onDelete: "cascade" }),
|
.references(() => ProjectTable.id, { onDelete: "cascade" }),
|
||||||
|
workspace_id: text(),
|
||||||
parent_id: text(),
|
parent_id: text(),
|
||||||
slug: text().notNull(),
|
slug: text().notNull(),
|
||||||
directory: text().notNull(),
|
directory: text().notNull(),
|
||||||
@@ -31,7 +32,11 @@ export const SessionTable = sqliteTable(
|
|||||||
time_compacting: integer(),
|
time_compacting: integer(),
|
||||||
time_archived: integer(),
|
time_archived: integer(),
|
||||||
},
|
},
|
||||||
(table) => [index("session_project_idx").on(table.project_id), index("session_parent_idx").on(table.parent_id)],
|
(table) => [
|
||||||
|
index("session_project_idx").on(table.project_id),
|
||||||
|
index("session_workspace_idx").on(table.workspace_id),
|
||||||
|
index("session_parent_idx").on(table.parent_id),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
export const MessageTable = sqliteTable(
|
export const MessageTable = sqliteTable(
|
||||||
|
|||||||
@@ -808,6 +808,7 @@ export type Session = {
|
|||||||
id: string
|
id: string
|
||||||
slug: string
|
slug: string
|
||||||
projectID: string
|
projectID: string
|
||||||
|
workspaceID?: string
|
||||||
directory: string
|
directory: string
|
||||||
parentID?: string
|
parentID?: string
|
||||||
summary?: {
|
summary?: {
|
||||||
@@ -1671,6 +1672,7 @@ export type GlobalSession = {
|
|||||||
id: string
|
id: string
|
||||||
slug: string
|
slug: string
|
||||||
projectID: string
|
projectID: string
|
||||||
|
workspaceID?: string
|
||||||
directory: string
|
directory: string
|
||||||
parentID?: string
|
parentID?: string
|
||||||
summary?: {
|
summary?: {
|
||||||
|
|||||||
Reference in New Issue
Block a user