From 8dd2c04ad12ea36f29554508a5c20b520883e9d6 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 23 Feb 2026 22:04:22 +0400 Subject: [PATCH] =?UTF-8?q?setup=20du=20sch=C3=A9ma=20de=20base=20pour=20c?= =?UTF-8?q?ommencer,=20on=20am=C3=A9liorera=20ensuite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/db/index.ts | 1 + packages/db/schema.ts | 54 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 packages/db/index.ts diff --git a/packages/db/index.ts b/packages/db/index.ts new file mode 100644 index 0000000..e27a6e2 --- /dev/null +++ b/packages/db/index.ts @@ -0,0 +1 @@ +export * from './schema'; diff --git a/packages/db/schema.ts b/packages/db/schema.ts index a14363f..8f67aa9 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -1,8 +1,56 @@ -import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core'; +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: serial('id').primaryKey(), + id: uuid('id').defaultRandom().primaryKey(), name: text('name').notNull(), description: text('description'), - createdAt: timestamp('created_at').defaultNow(), + 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], + }), +}));