import { sqliteTable, text } from "drizzle-orm/sqlite-core"; import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox"; import { Type, type Static } from "@alkdev/typebox"; import { commonCols } from "./common.ts"; import { graphTypes } from "./graphTypes.ts"; import { GRAPH_STATUS } from "../../graphs/types.ts"; export const graphs = sqliteTable("graphs", { ...commonCols, graphTypeId: text("graph_type_id").references(() => graphTypes.id, { onDelete: "set null" }), name: text("name").notNull(), description: text("description").default(""), status: text("status", { enum: ["active", "archived", "draft"] }) .default("draft") .notNull(), }); export const SelectGraph = createSelectSchema(graphs, { metadata: Type.Object({}, { additionalProperties: true }), createdAt: Type.Date(), updatedAt: Type.Date(), }); export type SelectGraph = Static; export const InsertGraph = createInsertSchema(graphs, { name: Type.String({ minLength: 2 }), status: Type.Optional(Type.Union([ Type.Literal(GRAPH_STATUS.Active), Type.Literal(GRAPH_STATUS.Archived), Type.Literal(GRAPH_STATUS.Draft), ])), }); export type InsertGraph = Static;