setup du schéma de base pour commencer, on améliorera ensuite
This commit is contained in:
parent
e2114f5b7f
commit
8dd2c04ad1
1
packages/db/index.ts
Normal file
1
packages/db/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './schema';
|
||||||
|
|
@ -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],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue