feat(db): add Anomalie, Notification and Historique tracking models
This commit is contained in:
@@ -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[]
|
||||
materiels Materiel[]
|
||||
emprunts Emprunt[]
|
||||
historiques Historique[]
|
||||
|
||||
@@map("campus")
|
||||
}
|
||||
@@ -34,22 +35,26 @@ model Role {
|
||||
}
|
||||
|
||||
model Utilisateur {
|
||||
id Int @id @default(autoincrement())
|
||||
microsoftId String @unique @map("microsoft_id")
|
||||
nom String
|
||||
prenom String
|
||||
email String @unique
|
||||
classe String?
|
||||
roleId Int @map("role_id")
|
||||
campusId Int @map("campus_id")
|
||||
actif Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
role Role @relation(fields: [roleId], references: [id])
|
||||
cartes CarteEtudiante[]
|
||||
emprunts Emprunt[]
|
||||
checklists Checklist[]
|
||||
id Int @id @default(autoincrement())
|
||||
microsoftId String @unique @map("microsoft_id")
|
||||
nom String
|
||||
prenom String
|
||||
email String @unique
|
||||
classe String?
|
||||
roleId Int @map("role_id")
|
||||
campusId Int @map("campus_id")
|
||||
actif Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
role Role @relation(fields: [roleId], references: [id])
|
||||
cartes CarteEtudiante[]
|
||||
emprunts Emprunt[]
|
||||
checklists Checklist[]
|
||||
anomaliesConcernees Anomalie[] @relation("AnomalieEtudiant")
|
||||
anomaliesTraitees Anomalie[] @relation("AnomalieResponsable")
|
||||
notifications Notification[]
|
||||
historiques Historique[]
|
||||
|
||||
@@map("utilisateur")
|
||||
}
|
||||
@@ -77,20 +82,22 @@ model SallePret {
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
postes PosteEmprunt[]
|
||||
emprunts Emprunt[]
|
||||
historiques Historique[]
|
||||
|
||||
@@map("salle_pret")
|
||||
}
|
||||
|
||||
model PosteEmprunt {
|
||||
id Int @id @default(autoincrement())
|
||||
id Int @id @default(autoincrement())
|
||||
nom String
|
||||
identifiantPoste String @map("identifiant_poste")
|
||||
sallePretId Int @map("salle_pret_id")
|
||||
actif Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
sallePret SallePret @relation(fields: [sallePretId], references: [id])
|
||||
identifiantPoste String @map("identifiant_poste")
|
||||
sallePretId Int @map("salle_pret_id")
|
||||
actif Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
sallePret SallePret @relation(fields: [sallePretId], references: [id])
|
||||
emprunts Emprunt[]
|
||||
historiques Historique[]
|
||||
|
||||
@@map("poste_emprunt")
|
||||
}
|
||||
@@ -128,6 +135,8 @@ model Materiel {
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
accessoires MaterielAccessoire[]
|
||||
emprunts Emprunt[]
|
||||
anomalies Anomalie[]
|
||||
historiques Historique[]
|
||||
|
||||
@@map("materiel")
|
||||
}
|
||||
@@ -180,6 +189,8 @@ model Emprunt {
|
||||
sallePret SallePret @relation(fields: [sallePretId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
posteEmprunt PosteEmprunt @relation(fields: [posteEmpruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
checklists Checklist[]
|
||||
anomalies Anomalie[]
|
||||
historiques Historique[]
|
||||
|
||||
@@map("emprunt")
|
||||
}
|
||||
@@ -215,3 +226,64 @@ model ChecklistElement {
|
||||
|
||||
@@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