refactor(core): move v1 schemas into core (#30473)

This commit is contained in:
Dax 2026-06-02 22:42:13 -04:00 committed by GitHub
commit 83452558f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
129 changed files with 1578 additions and 1227 deletions

View file

@ -3,16 +3,16 @@ import * as DatabasePath from "../database/path"
import { ProjectTable } from "../project/sql"
import type { SessionMessage } from "./message"
import type { Snapshot } from "../snapshot"
import { PermissionLegacy } from "../permission/legacy"
import { PermissionV1 } from "../v1/permission"
import { ProjectV2 } from "../project"
import type { SessionSchema } from "./schema"
import type { MessageID, PartID, Info as LegacyMessageInfo, Part as LegacyMessagePart } from "./legacy"
import type { MessageID, PartID, SessionV1 } from "../v1/session"
import { WorkspaceV2 } from "../workspace"
import { Timestamps } from "../database/schema.sql"
type SessionMessageData = Omit<(typeof SessionMessage.Message)["Encoded"], "type" | "id">
type LegacyMessageData = Omit<LegacyMessageInfo, "id" | "sessionID">
type LegacyPartData = Omit<LegacyMessagePart, "id" | "sessionID" | "messageID">
type V1MessageData = Omit<SessionV1.Info, "id" | "sessionID">
type V1PartData = Omit<SessionV1.Part, "id" | "sessionID" | "messageID">
export const SessionTable = sqliteTable(
"session",
@ -42,7 +42,7 @@ export const SessionTable = sqliteTable(
tokens_cache_read: integer().notNull().default(0),
tokens_cache_write: integer().notNull().default(0),
revert: text({ mode: "json" }).$type<{ messageID: MessageID; partID?: PartID; snapshot?: string; diff?: string }>(),
permission: text({ mode: "json" }).$type<PermissionLegacy.Ruleset>(),
permission: text({ mode: "json" }).$type<PermissionV1.Ruleset>(),
agent: text(),
model: text({ mode: "json" }).$type<{
id: string
@ -69,7 +69,7 @@ export const MessageTable = sqliteTable(
.notNull()
.references(() => SessionTable.id, { onDelete: "cascade" }),
...Timestamps,
data: text({ mode: "json" }).notNull().$type<LegacyMessageData>(),
data: text({ mode: "json" }).notNull().$type<V1MessageData>(),
},
(table) => [index("message_session_time_created_id_idx").on(table.session_id, table.time_created, table.id)],
)
@ -84,7 +84,7 @@ export const PartTable = sqliteTable(
.references(() => MessageTable.id, { onDelete: "cascade" }),
session_id: text().$type<SessionSchema.ID>().notNull(),
...Timestamps,
data: text({ mode: "json" }).notNull().$type<LegacyPartData>(),
data: text({ mode: "json" }).notNull().$type<V1PartData>(),
},
(table) => [
index("part_message_id_id_idx").on(table.message_id, table.id),