123 lines
5.1 KiB
TypeScript
123 lines
5.1 KiB
TypeScript
import { boolean, datetime, int, mysqlEnum, mysqlTable, text, timestamp, varchar } from "drizzle-orm/mysql-core";
|
|
|
|
/**
|
|
* Core user table backing auth flow.
|
|
* Extend this file with additional tables as your product grows.
|
|
* Columns use camelCase to match both database fields and generated types.
|
|
*/
|
|
export const users = mysqlTable("users", {
|
|
/**
|
|
* Surrogate primary key. Auto-incremented numeric value managed by the database.
|
|
* Use this for relations between tables.
|
|
*/
|
|
id: int("id").autoincrement().primaryKey(),
|
|
/** Manus OAuth identifier (openId) returned from the OAuth callback. Unique per user. */
|
|
openId: varchar("openId", { length: 64 }).notNull().unique(),
|
|
name: text("name"),
|
|
email: varchar("email", { length: 320 }),
|
|
loginMethod: varchar("loginMethod", { length: 64 }),
|
|
role: mysqlEnum("role", ["user", "admin"]).default("user").notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
lastSignedIn: timestamp("lastSignedIn").defaultNow().notNull(),
|
|
});
|
|
|
|
export type User = typeof users.$inferSelect;
|
|
export type InsertUser = typeof users.$inferInsert;
|
|
|
|
/**
|
|
* Table des formations (ex: Manager Itinova)
|
|
*/
|
|
export const formations = mysqlTable("formations", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
description: text("description"),
|
|
/** Lien unique pour l'inscription à cette formation */
|
|
lienUnique: varchar("lienUnique", { length: 100 }).notNull().unique(),
|
|
actif: boolean("actif").default(true).notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type Formation = typeof formations.$inferSelect;
|
|
export type InsertFormation = typeof formations.$inferInsert;
|
|
|
|
/**
|
|
* Table des apprenants
|
|
*/
|
|
export const apprenants = mysqlTable("apprenants", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
prenom: varchar("prenom", { length: 255 }).notNull(),
|
|
email: varchar("email", { length: 320 }).notNull().unique(),
|
|
codeEtablissement: varchar("codeEtablissement", { length: 50 }).notNull(),
|
|
fonction: mysqlEnum("fonction", ["directeur", "chef_service", "autre"]).notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type Apprenant = typeof apprenants.$inferSelect;
|
|
export type InsertApprenant = typeof apprenants.$inferInsert;
|
|
|
|
/**
|
|
* Table des séquences de formation
|
|
* Une séquence peut contenir jusqu'à 4 dates de formation
|
|
*/
|
|
export const sequences = mysqlTable("sequences", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
formationId: int("formationId").notNull(),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
/** Lieu de la formation */
|
|
lieu: varchar("lieu", { length: 500 }).notNull(),
|
|
/** Public cible de la séquence (Directeur, Chef de service, Autre) */
|
|
publicCible: mysqlEnum("publicCible", ["directeur", "chef_service", "autre"]).notNull(),
|
|
/** Capacité maximale (12 par défaut) */
|
|
capaciteMax: int("capaciteMax").default(12).notNull(),
|
|
/** Date de blocage des inscriptions (J-15 avant la première date) */
|
|
dateBlocage: datetime("dateBlocage").notNull(),
|
|
/** Statut de la séquence */
|
|
statut: mysqlEnum("statut", ["ouverte", "bloquee", "terminee"]).default("ouverte").notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type Sequence = typeof sequences.$inferSelect;
|
|
export type InsertSequence = typeof sequences.$inferInsert;
|
|
|
|
/**
|
|
* Table des dates de formation pour chaque séquence
|
|
* Une séquence peut avoir jusqu'à 4 dates
|
|
*/
|
|
export const datesFormation = mysqlTable("datesFormation", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
sequenceId: int("sequenceId").notNull(),
|
|
/** Date de début de cette journée de formation */
|
|
dateDebut: datetime("dateDebut").notNull(),
|
|
/** Date de fin de cette journée de formation */
|
|
dateFin: datetime("dateFin").notNull(),
|
|
/** Ordre de la date dans la séquence (1 à 4) */
|
|
ordre: int("ordre").notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
});
|
|
|
|
export type DateFormation = typeof datesFormation.$inferSelect;
|
|
export type InsertDateFormation = typeof datesFormation.$inferInsert;
|
|
|
|
/**
|
|
* Table des inscriptions
|
|
* L'inscription à une séquence inscrit automatiquement à toutes ses dates
|
|
*/
|
|
export const inscriptions = mysqlTable("inscriptions", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
apprenantId: int("apprenantId").notNull(),
|
|
sequenceId: int("sequenceId").notNull(),
|
|
/** Statut de l'inscription */
|
|
statut: mysqlEnum("statut", ["confirmee", "liste_attente", "annulee"]).notNull(),
|
|
dateInscription: timestamp("dateInscription").defaultNow().notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type Inscription = typeof inscriptions.$inferSelect;
|
|
export type InsertInscription = typeof inscriptions.$inferInsert;
|