feat: multiple scenes
This commit is contained in:
@@ -24,6 +24,7 @@ export function getDb(): Database.Database {
|
||||
db.pragma('foreign_keys = ON')
|
||||
|
||||
initSchema(db)
|
||||
migrateSchema(db)
|
||||
return db
|
||||
}
|
||||
|
||||
@@ -32,6 +33,7 @@ function initSchema(db: Database.Database): void {
|
||||
CREATE TABLE IF NOT EXISTS runs (
|
||||
id TEXT PRIMARY KEY,
|
||||
recollectionId TEXT NOT NULL,
|
||||
sceneId TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
graphSnapshot TEXT NOT NULL,
|
||||
createdAt TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
@@ -61,6 +63,14 @@ function initSchema(db: Database.Database): void {
|
||||
`)
|
||||
}
|
||||
|
||||
function migrateSchema(db: Database.Database): void {
|
||||
// Add sceneId column if it doesn't exist (added in Phase 2)
|
||||
const cols = db.prepare("PRAGMA table_info(runs)").all() as Array<{ name: string }>
|
||||
if (!cols.some((c) => c.name === 'sceneId')) {
|
||||
db.exec('ALTER TABLE runs ADD COLUMN sceneId TEXT')
|
||||
}
|
||||
}
|
||||
|
||||
export function closeDb(): void {
|
||||
if (db) {
|
||||
db.close()
|
||||
|
||||
@@ -7,6 +7,7 @@ export type RunStatus = 'pending' | 'running' | 'completed' | 'failed'
|
||||
export type Run = {
|
||||
id: string
|
||||
recollectionId: string
|
||||
sceneId?: string | null
|
||||
status: RunStatus
|
||||
graphSnapshot: string
|
||||
createdAt: string
|
||||
|
||||
@@ -8,8 +8,8 @@ import type { Run, RunStep, RunStatus } from '../models/run.js'
|
||||
export function createRun(run: Run): void {
|
||||
const db = getDb()
|
||||
db.prepare(`
|
||||
INSERT INTO runs (id, recollectionId, status, graphSnapshot, createdAt, updatedAt, error)
|
||||
VALUES (@id, @recollectionId, @status, @graphSnapshot, @createdAt, @updatedAt, @error)
|
||||
INSERT INTO runs (id, recollectionId, sceneId, status, graphSnapshot, createdAt, updatedAt, error)
|
||||
VALUES (@id, @recollectionId, @sceneId, @status, @graphSnapshot, @createdAt, @updatedAt, @error)
|
||||
`).run(run)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { executeRun } from '../services/graphRunnerService.js'
|
||||
*/
|
||||
export async function handleCreateRun(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { recollectionId, graph } = req.body
|
||||
const { recollectionId, sceneId, graph } = req.body
|
||||
|
||||
if (!recollectionId || typeof recollectionId !== 'string') {
|
||||
res.status(400).json({ error: 'recollectionId is required' })
|
||||
@@ -30,6 +30,7 @@ export async function handleCreateRun(req: Request, res: Response): Promise<void
|
||||
const run: Run = {
|
||||
id: crypto.randomUUID(),
|
||||
recollectionId,
|
||||
sceneId: typeof sceneId === 'string' ? sceneId : null,
|
||||
status: 'pending',
|
||||
graphSnapshot: JSON.stringify(graph),
|
||||
createdAt: new Date().toISOString(),
|
||||
|
||||
Reference in New Issue
Block a user