feat(id): brand WorkspaceID through Drizzle and Zod schemas (#16964)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { Argv } from "yargs"
|
||||
import type { Session as SDKSession, Message, Part } from "@opencode-ai/sdk/v2"
|
||||
import { Session } from "../../session"
|
||||
import { SessionID } from "../../session/schema"
|
||||
import { SessionID, MessageID } from "../../session/schema"
|
||||
import { WorkspaceID } from "../../control-plane/schema"
|
||||
import { cmd } from "./cmd"
|
||||
import { bootstrap } from "../bootstrap"
|
||||
import { Database } from "../../storage/db"
|
||||
@@ -157,7 +158,11 @@ export const ImportCommand = cmd({
|
||||
...exportData.info,
|
||||
id: SessionID.make(exportData.info.id),
|
||||
parentID: exportData.info.parentID ? SessionID.make(exportData.info.parentID) : undefined,
|
||||
workspaceID: exportData.info.workspaceID ? WorkspaceID.make(exportData.info.workspaceID) : undefined,
|
||||
projectID: Instance.project.id,
|
||||
revert: exportData.info.revert
|
||||
? { ...exportData.info.revert, messageID: MessageID.make(exportData.info.revert.messageID) }
|
||||
: undefined,
|
||||
})
|
||||
Database.use((db) =>
|
||||
db
|
||||
@@ -168,28 +173,30 @@ export const ImportCommand = cmd({
|
||||
)
|
||||
|
||||
for (const msg of exportData.messages) {
|
||||
const { id: _mid, sessionID: _msid, ...msgData } = msg.info
|
||||
Database.use((db) =>
|
||||
db
|
||||
.insert(MessageTable)
|
||||
.values({
|
||||
id: msg.info.id,
|
||||
id: MessageID.make(msg.info.id),
|
||||
session_id: row.id,
|
||||
time_created: msg.info.time?.created ?? Date.now(),
|
||||
data: msg.info,
|
||||
data: msgData,
|
||||
})
|
||||
.onConflictDoNothing()
|
||||
.run(),
|
||||
)
|
||||
|
||||
for (const part of msg.parts) {
|
||||
const { id: _pid, sessionID: _psid, messageID: _pmid, ...partData } = part
|
||||
Database.use((db) =>
|
||||
db
|
||||
.insert(PartTable)
|
||||
.values({
|
||||
id: part.id,
|
||||
message_id: msg.info.id,
|
||||
message_id: MessageID.make(msg.info.id),
|
||||
session_id: row.id,
|
||||
data: part,
|
||||
data: partData,
|
||||
})
|
||||
.onConflictDoNothing()
|
||||
.run(),
|
||||
|
||||
Reference in New Issue
Block a user