feat(db): add Anomalie, Notification and Historique tracking models
This commit is contained in:
@@ -154,14 +154,14 @@ erDiagram
|
|||||||
int emprunt_id FK
|
int emprunt_id FK
|
||||||
int materiel_id FK
|
int materiel_id FK
|
||||||
int utilisateur_id FK
|
int utilisateur_id FK
|
||||||
int traitee_par_id FK
|
int traitee_par_id FK "nullable"
|
||||||
string type
|
string type
|
||||||
string description
|
string description
|
||||||
string statut
|
string statut
|
||||||
boolean detectee_automatiquement
|
boolean detectee_automatiquement
|
||||||
string observation
|
string observation "nullable"
|
||||||
datetime date_detection
|
datetime date_detection
|
||||||
datetime date_resolution
|
datetime date_resolution "nullable"
|
||||||
datetime created_at
|
datetime created_at
|
||||||
datetime updated_at
|
datetime updated_at
|
||||||
}
|
}
|
||||||
@@ -169,11 +169,11 @@ erDiagram
|
|||||||
HISTORIQUE {
|
HISTORIQUE {
|
||||||
int id PK
|
int id PK
|
||||||
int utilisateur_id FK
|
int utilisateur_id FK
|
||||||
int emprunt_id FK
|
int emprunt_id FK "nullable"
|
||||||
int materiel_id FK
|
int materiel_id FK "nullable"
|
||||||
int campus_id FK
|
int campus_id FK "nullable"
|
||||||
int salle_pret_id FK
|
int salle_pret_id FK "nullable"
|
||||||
int poste_emprunt_id FK
|
int poste_emprunt_id FK "nullable"
|
||||||
string action
|
string action
|
||||||
string description
|
string description
|
||||||
datetime date_action
|
datetime date_action
|
||||||
@@ -183,7 +183,7 @@ erDiagram
|
|||||||
NOTIFICATION {
|
NOTIFICATION {
|
||||||
int id PK
|
int id PK
|
||||||
int utilisateur_id FK
|
int utilisateur_id FK
|
||||||
int anomalie_id FK
|
int anomalie_id FK "nullable"
|
||||||
string titre
|
string titre
|
||||||
string message
|
string message
|
||||||
string type
|
string type
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
BEGIN TRY
|
||||||
|
|
||||||
|
BEGIN TRAN;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE [dbo].[anomalie] (
|
||||||
|
[id] INT NOT NULL IDENTITY(1,1),
|
||||||
|
[emprunt_id] INT NOT NULL,
|
||||||
|
[materiel_id] INT NOT NULL,
|
||||||
|
[utilisateur_id] INT NOT NULL,
|
||||||
|
[traitee_par_id] INT,
|
||||||
|
[type] NVARCHAR(1000) NOT NULL,
|
||||||
|
[description] NVARCHAR(1000) NOT NULL,
|
||||||
|
[statut] NVARCHAR(1000) NOT NULL,
|
||||||
|
[detectee_automatiquement] BIT NOT NULL CONSTRAINT [anomalie_detectee_automatiquement_df] DEFAULT 1,
|
||||||
|
[observation] NVARCHAR(1000),
|
||||||
|
[date_detection] DATETIME2 NOT NULL,
|
||||||
|
[date_resolution] DATETIME2,
|
||||||
|
[created_at] DATETIME2 NOT NULL CONSTRAINT [anomalie_created_at_df] DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
[updated_at] DATETIME2 NOT NULL,
|
||||||
|
CONSTRAINT [anomalie_pkey] PRIMARY KEY CLUSTERED ([id])
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE [dbo].[notification] (
|
||||||
|
[id] INT NOT NULL IDENTITY(1,1),
|
||||||
|
[utilisateur_id] INT NOT NULL,
|
||||||
|
[anomalie_id] INT,
|
||||||
|
[titre] NVARCHAR(1000) NOT NULL,
|
||||||
|
[message] NVARCHAR(1000) NOT NULL,
|
||||||
|
[type] NVARCHAR(1000) NOT NULL,
|
||||||
|
[lu] BIT NOT NULL CONSTRAINT [notification_lu_df] DEFAULT 0,
|
||||||
|
[date_creation] DATETIME2 NOT NULL CONSTRAINT [notification_date_creation_df] DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT [notification_pkey] PRIMARY KEY CLUSTERED ([id])
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE [dbo].[historique] (
|
||||||
|
[id] INT NOT NULL IDENTITY(1,1),
|
||||||
|
[utilisateur_id] INT NOT NULL,
|
||||||
|
[emprunt_id] INT,
|
||||||
|
[materiel_id] INT,
|
||||||
|
[campus_id] INT,
|
||||||
|
[salle_pret_id] INT,
|
||||||
|
[poste_emprunt_id] INT,
|
||||||
|
[action] NVARCHAR(1000) NOT NULL,
|
||||||
|
[description] NVARCHAR(1000) NOT NULL,
|
||||||
|
[date_action] DATETIME2 NOT NULL,
|
||||||
|
[created_at] DATETIME2 NOT NULL CONSTRAINT [historique_created_at_df] DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT [historique_pkey] PRIMARY KEY CLUSTERED ([id])
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[anomalie] ADD CONSTRAINT [anomalie_emprunt_id_fkey] FOREIGN KEY ([emprunt_id]) REFERENCES [dbo].[emprunt]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[anomalie] ADD CONSTRAINT [anomalie_materiel_id_fkey] FOREIGN KEY ([materiel_id]) REFERENCES [dbo].[materiel]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[anomalie] ADD CONSTRAINT [anomalie_utilisateur_id_fkey] FOREIGN KEY ([utilisateur_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[anomalie] ADD CONSTRAINT [anomalie_traitee_par_id_fkey] FOREIGN KEY ([traitee_par_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[notification] ADD CONSTRAINT [notification_utilisateur_id_fkey] FOREIGN KEY ([utilisateur_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[notification] ADD CONSTRAINT [notification_anomalie_id_fkey] FOREIGN KEY ([anomalie_id]) REFERENCES [dbo].[anomalie]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[historique] ADD CONSTRAINT [historique_utilisateur_id_fkey] FOREIGN KEY ([utilisateur_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[historique] ADD CONSTRAINT [historique_emprunt_id_fkey] FOREIGN KEY ([emprunt_id]) REFERENCES [dbo].[emprunt]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[historique] ADD CONSTRAINT [historique_materiel_id_fkey] FOREIGN KEY ([materiel_id]) REFERENCES [dbo].[materiel]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[historique] ADD CONSTRAINT [historique_campus_id_fkey] FOREIGN KEY ([campus_id]) REFERENCES [dbo].[campus]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[historique] ADD CONSTRAINT [historique_salle_pret_id_fkey] FOREIGN KEY ([salle_pret_id]) REFERENCES [dbo].[salle_pret]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE [dbo].[historique] ADD CONSTRAINT [historique_poste_emprunt_id_fkey] FOREIGN KEY ([poste_emprunt_id]) REFERENCES [dbo].[poste_emprunt]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
COMMIT TRAN;
|
||||||
|
|
||||||
|
END TRY
|
||||||
|
BEGIN CATCH
|
||||||
|
|
||||||
|
IF @@TRANCOUNT > 0
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK TRAN;
|
||||||
|
END;
|
||||||
|
THROW
|
||||||
|
|
||||||
|
END CATCH
|
||||||
@@ -19,6 +19,7 @@ model Campus {
|
|||||||
sallesPret SallePret[]
|
sallesPret SallePret[]
|
||||||
materiels Materiel[]
|
materiels Materiel[]
|
||||||
emprunts Emprunt[]
|
emprunts Emprunt[]
|
||||||
|
historiques Historique[]
|
||||||
|
|
||||||
@@map("campus")
|
@@map("campus")
|
||||||
}
|
}
|
||||||
@@ -34,22 +35,26 @@ model Role {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Utilisateur {
|
model Utilisateur {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
microsoftId String @unique @map("microsoft_id")
|
microsoftId String @unique @map("microsoft_id")
|
||||||
nom String
|
nom String
|
||||||
prenom String
|
prenom String
|
||||||
email String @unique
|
email String @unique
|
||||||
classe String?
|
classe String?
|
||||||
roleId Int @map("role_id")
|
roleId Int @map("role_id")
|
||||||
campusId Int @map("campus_id")
|
campusId Int @map("campus_id")
|
||||||
actif Boolean @default(true)
|
actif Boolean @default(true)
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
campus Campus @relation(fields: [campusId], references: [id])
|
campus Campus @relation(fields: [campusId], references: [id])
|
||||||
role Role @relation(fields: [roleId], references: [id])
|
role Role @relation(fields: [roleId], references: [id])
|
||||||
cartes CarteEtudiante[]
|
cartes CarteEtudiante[]
|
||||||
emprunts Emprunt[]
|
emprunts Emprunt[]
|
||||||
checklists Checklist[]
|
checklists Checklist[]
|
||||||
|
anomaliesConcernees Anomalie[] @relation("AnomalieEtudiant")
|
||||||
|
anomaliesTraitees Anomalie[] @relation("AnomalieResponsable")
|
||||||
|
notifications Notification[]
|
||||||
|
historiques Historique[]
|
||||||
|
|
||||||
@@map("utilisateur")
|
@@map("utilisateur")
|
||||||
}
|
}
|
||||||
@@ -77,20 +82,22 @@ model SallePret {
|
|||||||
campus Campus @relation(fields: [campusId], references: [id])
|
campus Campus @relation(fields: [campusId], references: [id])
|
||||||
postes PosteEmprunt[]
|
postes PosteEmprunt[]
|
||||||
emprunts Emprunt[]
|
emprunts Emprunt[]
|
||||||
|
historiques Historique[]
|
||||||
|
|
||||||
@@map("salle_pret")
|
@@map("salle_pret")
|
||||||
}
|
}
|
||||||
|
|
||||||
model PosteEmprunt {
|
model PosteEmprunt {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
nom String
|
nom String
|
||||||
identifiantPoste String @map("identifiant_poste")
|
identifiantPoste String @map("identifiant_poste")
|
||||||
sallePretId Int @map("salle_pret_id")
|
sallePretId Int @map("salle_pret_id")
|
||||||
actif Boolean @default(true)
|
actif Boolean @default(true)
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
sallePret SallePret @relation(fields: [sallePretId], references: [id])
|
sallePret SallePret @relation(fields: [sallePretId], references: [id])
|
||||||
emprunts Emprunt[]
|
emprunts Emprunt[]
|
||||||
|
historiques Historique[]
|
||||||
|
|
||||||
@@map("poste_emprunt")
|
@@map("poste_emprunt")
|
||||||
}
|
}
|
||||||
@@ -128,6 +135,8 @@ model Materiel {
|
|||||||
campus Campus @relation(fields: [campusId], references: [id])
|
campus Campus @relation(fields: [campusId], references: [id])
|
||||||
accessoires MaterielAccessoire[]
|
accessoires MaterielAccessoire[]
|
||||||
emprunts Emprunt[]
|
emprunts Emprunt[]
|
||||||
|
anomalies Anomalie[]
|
||||||
|
historiques Historique[]
|
||||||
|
|
||||||
@@map("materiel")
|
@@map("materiel")
|
||||||
}
|
}
|
||||||
@@ -180,6 +189,8 @@ model Emprunt {
|
|||||||
sallePret SallePret @relation(fields: [sallePretId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
sallePret SallePret @relation(fields: [sallePretId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
posteEmprunt PosteEmprunt @relation(fields: [posteEmpruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
posteEmprunt PosteEmprunt @relation(fields: [posteEmpruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
checklists Checklist[]
|
checklists Checklist[]
|
||||||
|
anomalies Anomalie[]
|
||||||
|
historiques Historique[]
|
||||||
|
|
||||||
@@map("emprunt")
|
@@map("emprunt")
|
||||||
}
|
}
|
||||||
@@ -215,3 +226,64 @@ model ChecklistElement {
|
|||||||
|
|
||||||
@@map("checklist_element")
|
@@map("checklist_element")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Anomalie {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
empruntId Int @map("emprunt_id")
|
||||||
|
materielId Int @map("materiel_id")
|
||||||
|
utilisateurId Int @map("utilisateur_id")
|
||||||
|
traiteeParId Int? @map("traitee_par_id")
|
||||||
|
type String
|
||||||
|
description String
|
||||||
|
statut String
|
||||||
|
detecteeAutomatiquement Boolean @default(true) @map("detectee_automatiquement")
|
||||||
|
observation String?
|
||||||
|
dateDetection DateTime @map("date_detection")
|
||||||
|
dateResolution DateTime? @map("date_resolution")
|
||||||
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
|
emprunt Emprunt @relation(fields: [empruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
materiel Materiel @relation(fields: [materielId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
etudiant Utilisateur @relation("AnomalieEtudiant", fields: [utilisateurId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
traitePar Utilisateur? @relation("AnomalieResponsable", fields: [traiteeParId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
notifications Notification[]
|
||||||
|
|
||||||
|
@@map("anomalie")
|
||||||
|
}
|
||||||
|
|
||||||
|
model Notification {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
utilisateurId Int @map("utilisateur_id")
|
||||||
|
anomalieId Int? @map("anomalie_id")
|
||||||
|
titre String
|
||||||
|
message String
|
||||||
|
type String
|
||||||
|
lu Boolean @default(false)
|
||||||
|
dateCreation DateTime @default(now()) @map("date_creation")
|
||||||
|
utilisateur Utilisateur @relation(fields: [utilisateurId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
anomalie Anomalie? @relation(fields: [anomalieId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
|
||||||
|
@@map("notification")
|
||||||
|
}
|
||||||
|
|
||||||
|
model Historique {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
utilisateurId Int @map("utilisateur_id")
|
||||||
|
empruntId Int? @map("emprunt_id")
|
||||||
|
materielId Int? @map("materiel_id")
|
||||||
|
campusId Int? @map("campus_id")
|
||||||
|
sallePretId Int? @map("salle_pret_id")
|
||||||
|
posteEmpruntId Int? @map("poste_emprunt_id")
|
||||||
|
action String
|
||||||
|
description String
|
||||||
|
dateAction DateTime @map("date_action")
|
||||||
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
utilisateur Utilisateur @relation(fields: [utilisateurId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
emprunt Emprunt? @relation(fields: [empruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
materiel Materiel? @relation(fields: [materielId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
campus Campus? @relation(fields: [campusId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
sallePret SallePret? @relation(fields: [sallePretId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
posteEmprunt PosteEmprunt? @relation(fields: [posteEmpruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
|
|
||||||
|
@@map("historique")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user