import { sql } from "drizzle-orm"; import { index, real, smallint, text, timestamp, uuid } from "drizzle-orm/pg-core"; import { appSchema } from "./_schema"; export const projects = appSchema.table("projects", { id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), name: text("name").notNull(), description: text("description"), status: text("status").notNull().default("active"), createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(), }); export const projectSteps = appSchema.table( "project_steps", { id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), projectId: uuid("project_id").notNull().references(() => projects.id, { onDelete: "cascade" }), title: text("title").notNull(), status: text("status").notNull().default("backlog"), position: real("position").notNull().default(0), createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => ({ projectIdIdx: index("project_steps_project_id_idx").on(t.projectId), }), ); export const projectIdeas = appSchema.table( "project_ideas", { id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), projectId: uuid("project_id").references(() => projects.id, { onDelete: "cascade" }), content: text("content").notNull(), priority: smallint("priority"), createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => ({ projectIdIdx: index("project_ideas_project_id_idx").on(t.projectId), }), ); export type ProjectRow = typeof projects.$inferSelect; export type ProjectInsert = typeof projects.$inferInsert; export type ProjectStepRow = typeof projectSteps.$inferSelect; export type ProjectIdeaRow = typeof projectIdeas.$inferSelect;