Files
turbostarter/packages/db/src/schema/diagram.ts
Alejandro Gutiérrez c4379afe1f
Some checks failed
CI / Tests / 🧪 Test (push) Has been cancelled
feat: implement Stories 3.4, 3.5, 3.6 — AI proposals, wizard, hover & palette
Story 3.4: AI semantic suggestions with accept/reject workflow
- ProposalBar overlay with visual diff
- Accept/reject flow with graph snapshot restore
- useProposalDiff hook for change summary
- System prompt scoping for selected elements

Story 3.5: New diagram wizard with AI type inference
- CreateDiagramDialog with AI type inference (Haiku)
- initialDescription prop for chat-first flow
- Auto-send on mount with hasSentInitial ref guard
- DB migration for diagram description column

Story 3.6: Hover affordances and command palette
- HoverAffordances toolbar (5 AI actions, debounced)
- CommandPalette (Cmd+K) with AI, nav, Go to Node
- prefillChat/fitViewRequested/focusNodeId actions
- Code review: getNodesBounds, onOpenRightPanel,
  timer cleanup, test count fix

374 tests passing (251 web + 123 AI).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 08:55:06 +00:00

74 lines
2.1 KiB
TypeScript

import {
integer,
jsonb,
pgEnum,
pgTable,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { generateId } from "@turbostarter/shared/utils";
import {
createInsertSchema,
createSelectSchema,
createUpdateSchema,
} from "../lib/zod";
import { user } from "./auth";
import type * as z from "zod";
export const diagramTypeEnum = pgEnum("diagram_type", [
"bpmn",
"er",
"orgchart",
"architecture",
"sequence",
"flowchart",
]);
export const project = pgTable("project", {
id: text().primaryKey().notNull().$defaultFn(generateId),
name: text().notNull(),
userId: text()
.references(() => user.id, { onDelete: "cascade" })
.notNull(),
sortOrder: integer().default(0),
createdAt: timestamp().defaultNow(),
updatedAt: timestamp().$onUpdate(() => new Date()),
});
export const diagram = pgTable("diagram", {
id: text().primaryKey().notNull().$defaultFn(generateId),
title: text().notNull(),
type: diagramTypeEnum().notNull(),
graphData: jsonb().$type<object>().default({}),
description: text(),
userId: text()
.references(() => user.id, { onDelete: "cascade" })
.notNull(),
projectId: text(),
sortOrder: integer().default(0),
lastAiMessage: text(),
deletedAt: timestamp(),
createdAt: timestamp().defaultNow(),
updatedAt: timestamp().$onUpdate(() => new Date()),
});
export const insertDiagramSchema = createInsertSchema(diagram);
export const selectDiagramSchema = createSelectSchema(diagram);
export const updateDiagramSchema = createUpdateSchema(diagram);
export type InsertDiagram = z.infer<typeof insertDiagramSchema>;
export type SelectDiagram = z.infer<typeof selectDiagramSchema>;
export type UpdateDiagram = z.infer<typeof updateDiagramSchema>;
export const insertProjectSchema = createInsertSchema(project);
export const selectProjectSchema = createSelectSchema(project);
export const updateProjectSchema = createUpdateSchema(project);
export type InsertProject = z.infer<typeof insertProjectSchema>;
export type SelectProject = z.infer<typeof selectProjectSchema>;
export type UpdateProject = z.infer<typeof updateProjectSchema>;