import { pgTable, serial, text, timestamp, pgEnum, uuid, } from 'drizzle-orm/pg-core'; import { relations } from 'drizzle-orm'; export const statusEnum = pgEnum('status', [ 'backlog', 'todo', 'in_progress', 'done', 'archived', ]); export const priorityEnum = pgEnum('priority', [ 'low', 'medium', 'high', 'urgent', ]); export const projects = pgTable('projects', { id: uuid('id').defaultRandom().primaryKey(), name: text('name').notNull(), description: text('description'), slug: text('slug').unique().notNull(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), }); export const tasks = pgTable('tasks', { id: serial('id').primaryKey(), projectId: uuid('project_id') .references(() => projects.id, { onDelete: 'cascade' }) .notNull(), title: text('title').notNull(), content: text('content'), status: statusEnum('status').default('todo').notNull(), priority: priorityEnum('priority').default('medium').notNull(), dueDate: timestamp('due_date'), createdAt: timestamp('created_at').defaultNow().notNull(), }); export const projectsRelations = relations(projects, ({ many }) => ({ tasks: many(tasks), })); export const tasksRelations = relations(tasks, ({ one }) => ({ project: one(projects, { fields: [tasks.projectId], references: [projects.id], }), }));