From f59589bb2891bb0b72e030a215c9198f6451bea3 Mon Sep 17 00:00:00 2001 From: Djalim Simaila Date: Wed, 22 Apr 2026 13:13:33 +0200 Subject: [PATCH] feat(database): add roles, permissions, users, modules, and related tables Add tables for role-based access control and academic entities. Includes modules, UEs, notes, and adjustments. Update students and mobility tables to reference new primary keys. This enables richer data modeling for the application. --- databases/schema.ts | 80 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/databases/schema.ts b/databases/schema.ts index 1d7632e..0694007 100644 --- a/databases/schema.ts +++ b/databases/schema.ts @@ -2,10 +2,36 @@ import { date, integer, pgTable, + primaryKey, + real, serial, text, } from "npm:drizzle-orm/pg-core"; +export const roles = pgTable("roles", { + id: serial("id").primaryKey(), + nom: text("nom").notNull(), +}); + +export const permissions = pgTable("permissions", { + id: text("id").primaryKey(), + nom: text("nom").notNull(), +}); + +export const rolePermissions = pgTable("role_permissions", { + idRole: integer("idRole").notNull().references(() => roles.id), + idPermission: text("idPermission").notNull().references(() => permissions.id), +}, (t) => ({ + pk: primaryKey({ columns: [t.idRole, t.idPermission] }), +})); + +export const users = pgTable("users", { + id: text("id").primaryKey(), + nom: text("nom").notNull(), + prenom: text("prenom").notNull(), + idRole: integer("idRole").references(() => roles.id), +}); + export const promotions = pgTable("promotions", { id: serial("id").primaryKey(), endyear: integer("endyear"), @@ -13,16 +39,58 @@ export const promotions = pgTable("promotions", { }); export const students = pgTable("students", { - userId: text("userId").primaryKey(), - firstName: text("firstName"), - lastName: text("lastName"), - mail: text("mail"), - promotionId: integer("promotionId").references(() => promotions.id), + numEtud: serial("numEtud").primaryKey(), + nom: text("nom").notNull(), + prenom: text("prenom").notNull(), + idPromo: text("idPromo").references(() => promotions.id as unknown as string), }); +export const modules = pgTable("modules", { + id: text("id").primaryKey(), + nom: text("nom").notNull(), +}); + +export const enseignements = pgTable("enseignements", { + idProf: text("idProf").notNull().references(() => users.id), + idModule: text("idModule").notNull().references(() => modules.id), + idPromo: text("idPromo").notNull(), +}, (t) => ({ + pk: primaryKey({ columns: [t.idProf, t.idModule, t.idPromo] }), +})); + +export const ues = pgTable("ues", { + id: serial("id").primaryKey(), + nom: text("nom").notNull(), +}); + +export const ueModules = pgTable("ue_modules", { + idModule: text("idModule").notNull().references(() => modules.id), + idUE: integer("idUE").notNull().references(() => ues.id), + idPromo: text("idPromo").notNull(), + coeff: real("coeff").notNull(), +}, (t) => ({ + pk: primaryKey({ columns: [t.idModule, t.idUE, t.idPromo] }), +})); + +export const notes = pgTable("notes", { + numEtud: integer("numEtud").notNull().references(() => students.numEtud), + idModule: text("idModule").notNull().references(() => modules.id), + note: real("note").notNull(), +}, (t) => ({ + pk: primaryKey({ columns: [t.numEtud, t.idModule] }), +})); + +export const ajustements = pgTable("ajustements", { + numEtud: integer("numEtud").notNull().references(() => students.numEtud), + idUE: integer("idUE").notNull().references(() => ues.id), + valeur: real("valeur").notNull(), +}, (t) => ({ + pk: primaryKey({ columns: [t.numEtud, t.idUE] }), +})); + export const mobility = pgTable("mobility", { id: serial("id").primaryKey(), - studentId: text("studentId").references(() => students.userId), + studentId: integer("studentId").references(() => students.numEtud), startDate: date("startDate"), endDate: date("endDate"), weeksCount: integer("weeksCount"),