setup du schéma de base pour commencer, on améliorera ensuite

This commit is contained in:
= 2026-02-23 22:04:22 +04:00
parent e2114f5b7f
commit 8dd2c04ad1
2 changed files with 52 additions and 3 deletions

1
packages/db/index.ts Normal file
View file

@ -0,0 +1 @@
export * from './schema';

View file

@ -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', { export const projects = pgTable('projects', {
id: serial('id').primaryKey(), id: uuid('id').defaultRandom().primaryKey(),
name: text('name').notNull(), name: text('name').notNull(),
description: text('description'), 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],
}),
}));