feat(db): add Emprunt, Checklist and ChecklistElement transaction models
This commit is contained in:
@@ -116,12 +116,12 @@ erDiagram
|
||||
int poste_emprunt_id FK
|
||||
datetime date_emprunt
|
||||
datetime date_retour_prevue
|
||||
datetime date_retour_reelle
|
||||
datetime date_retour_reelle "nullable"
|
||||
string statut
|
||||
string mode_identification_emprunt
|
||||
string mode_identification_retour
|
||||
string commentaire_depart
|
||||
string commentaire_retour
|
||||
string mode_identification_retour "nullable"
|
||||
string commentaire_depart "nullable"
|
||||
string commentaire_retour "nullable"
|
||||
datetime created_at
|
||||
datetime updated_at
|
||||
}
|
||||
@@ -132,7 +132,7 @@ erDiagram
|
||||
int utilisateur_id FK
|
||||
string type
|
||||
datetime date_verification
|
||||
string commentaire
|
||||
string commentaire "nullable"
|
||||
datetime created_at
|
||||
datetime updated_at
|
||||
}
|
||||
@@ -140,11 +140,11 @@ erDiagram
|
||||
CHECKLIST_ELEMENT {
|
||||
int id PK
|
||||
int checklist_id FK
|
||||
int accessoire_id FK
|
||||
int accessoire_id FK "nullable"
|
||||
string nom_element
|
||||
string etat
|
||||
int quantite_constatee
|
||||
string commentaire
|
||||
string commentaire "nullable"
|
||||
datetime created_at
|
||||
datetime updated_at
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
BEGIN TRY
|
||||
|
||||
BEGIN TRAN;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE [dbo].[emprunt] (
|
||||
[id] INT NOT NULL IDENTITY(1,1),
|
||||
[utilisateur_id] INT NOT NULL,
|
||||
[materiel_id] INT NOT NULL,
|
||||
[campus_id] INT NOT NULL,
|
||||
[salle_pret_id] INT NOT NULL,
|
||||
[poste_emprunt_id] INT NOT NULL,
|
||||
[date_emprunt] DATETIME2 NOT NULL,
|
||||
[date_retour_prevue] DATETIME2 NOT NULL,
|
||||
[date_retour_reelle] DATETIME2,
|
||||
[statut] NVARCHAR(1000) NOT NULL,
|
||||
[mode_identification_emprunt] NVARCHAR(1000) NOT NULL,
|
||||
[mode_identification_retour] NVARCHAR(1000),
|
||||
[commentaire_depart] NVARCHAR(1000),
|
||||
[commentaire_retour] NVARCHAR(1000),
|
||||
[created_at] DATETIME2 NOT NULL CONSTRAINT [emprunt_created_at_df] DEFAULT CURRENT_TIMESTAMP,
|
||||
[updated_at] DATETIME2 NOT NULL,
|
||||
CONSTRAINT [emprunt_pkey] PRIMARY KEY CLUSTERED ([id])
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE [dbo].[checklist] (
|
||||
[id] INT NOT NULL IDENTITY(1,1),
|
||||
[emprunt_id] INT NOT NULL,
|
||||
[utilisateur_id] INT NOT NULL,
|
||||
[type] NVARCHAR(1000) NOT NULL,
|
||||
[date_verification] DATETIME2 NOT NULL,
|
||||
[commentaire] NVARCHAR(1000),
|
||||
[created_at] DATETIME2 NOT NULL CONSTRAINT [checklist_created_at_df] DEFAULT CURRENT_TIMESTAMP,
|
||||
[updated_at] DATETIME2 NOT NULL,
|
||||
CONSTRAINT [checklist_pkey] PRIMARY KEY CLUSTERED ([id])
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE [dbo].[checklist_element] (
|
||||
[id] INT NOT NULL IDENTITY(1,1),
|
||||
[checklist_id] INT NOT NULL,
|
||||
[accessoire_id] INT,
|
||||
[nom_element] NVARCHAR(1000) NOT NULL,
|
||||
[etat] NVARCHAR(1000) NOT NULL,
|
||||
[quantite_constatee] INT NOT NULL,
|
||||
[commentaire] NVARCHAR(1000),
|
||||
[created_at] DATETIME2 NOT NULL CONSTRAINT [checklist_element_created_at_df] DEFAULT CURRENT_TIMESTAMP,
|
||||
[updated_at] DATETIME2 NOT NULL,
|
||||
CONSTRAINT [checklist_element_pkey] PRIMARY KEY CLUSTERED ([id])
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[emprunt] ADD CONSTRAINT [emprunt_utilisateur_id_fkey] FOREIGN KEY ([utilisateur_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[emprunt] ADD CONSTRAINT [emprunt_materiel_id_fkey] FOREIGN KEY ([materiel_id]) REFERENCES [dbo].[materiel]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[emprunt] ADD CONSTRAINT [emprunt_campus_id_fkey] FOREIGN KEY ([campus_id]) REFERENCES [dbo].[campus]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[emprunt] ADD CONSTRAINT [emprunt_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].[emprunt] ADD CONSTRAINT [emprunt_poste_emprunt_id_fkey] FOREIGN KEY ([poste_emprunt_id]) REFERENCES [dbo].[poste_emprunt]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[checklist] ADD CONSTRAINT [checklist_emprunt_id_fkey] FOREIGN KEY ([emprunt_id]) REFERENCES [dbo].[emprunt]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[checklist] ADD CONSTRAINT [checklist_utilisateur_id_fkey] FOREIGN KEY ([utilisateur_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[checklist_element] ADD CONSTRAINT [checklist_element_checklist_id_fkey] FOREIGN KEY ([checklist_id]) REFERENCES [dbo].[checklist]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE [dbo].[checklist_element] ADD CONSTRAINT [checklist_element_accessoire_id_fkey] FOREIGN KEY ([accessoire_id]) REFERENCES [dbo].[accessoire]([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
|
||||
@@ -18,6 +18,7 @@ model Campus {
|
||||
utilisateurs Utilisateur[]
|
||||
sallesPret SallePret[]
|
||||
materiels Materiel[]
|
||||
emprunts Emprunt[]
|
||||
|
||||
@@map("campus")
|
||||
}
|
||||
@@ -47,6 +48,8 @@ model Utilisateur {
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
role Role @relation(fields: [roleId], references: [id])
|
||||
cartes CarteEtudiante[]
|
||||
emprunts Emprunt[]
|
||||
checklists Checklist[]
|
||||
|
||||
@@map("utilisateur")
|
||||
}
|
||||
@@ -73,6 +76,7 @@ model SallePret {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
postes PosteEmprunt[]
|
||||
emprunts Emprunt[]
|
||||
|
||||
@@map("salle_pret")
|
||||
}
|
||||
@@ -86,6 +90,7 @@ model PosteEmprunt {
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
sallePret SallePret @relation(fields: [sallePretId], references: [id])
|
||||
emprunts Emprunt[]
|
||||
|
||||
@@map("poste_emprunt")
|
||||
}
|
||||
@@ -122,6 +127,7 @@ model Materiel {
|
||||
categorie CategorieMateriel @relation(fields: [categorieId], references: [id])
|
||||
campus Campus @relation(fields: [campusId], references: [id])
|
||||
accessoires MaterielAccessoire[]
|
||||
emprunts Emprunt[]
|
||||
|
||||
@@map("materiel")
|
||||
}
|
||||
@@ -134,6 +140,7 @@ model Accessoire {
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
materiels MaterielAccessoire[]
|
||||
checklistElements ChecklistElement[]
|
||||
|
||||
@@map("accessoire")
|
||||
}
|
||||
@@ -149,3 +156,62 @@ model MaterielAccessoire {
|
||||
|
||||
@@map("materiel_accessoire")
|
||||
}
|
||||
|
||||
model Emprunt {
|
||||
id Int @id @default(autoincrement())
|
||||
utilisateurId Int @map("utilisateur_id")
|
||||
materielId Int @map("materiel_id")
|
||||
campusId Int @map("campus_id")
|
||||
sallePretId Int @map("salle_pret_id")
|
||||
posteEmpruntId Int @map("poste_emprunt_id")
|
||||
dateEmprunt DateTime @map("date_emprunt")
|
||||
dateRetourPrevue DateTime @map("date_retour_prevue")
|
||||
dateRetourReelle DateTime? @map("date_retour_reelle")
|
||||
statut String
|
||||
modeIdentificationEmprunt String @map("mode_identification_emprunt")
|
||||
modeIdentificationRetour String? @map("mode_identification_retour")
|
||||
commentaireDepart String? @map("commentaire_depart")
|
||||
commentaireRetour String? @map("commentaire_retour")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
utilisateur Utilisateur @relation(fields: [utilisateurId], 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)
|
||||
checklists Checklist[]
|
||||
|
||||
@@map("emprunt")
|
||||
}
|
||||
|
||||
model Checklist {
|
||||
id Int @id @default(autoincrement())
|
||||
empruntId Int @map("emprunt_id")
|
||||
utilisateurId Int @map("utilisateur_id")
|
||||
type String
|
||||
dateVerification DateTime @map("date_verification")
|
||||
commentaire String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
emprunt Emprunt @relation(fields: [empruntId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
utilisateur Utilisateur @relation(fields: [utilisateurId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
elements ChecklistElement[]
|
||||
|
||||
@@map("checklist")
|
||||
}
|
||||
|
||||
model ChecklistElement {
|
||||
id Int @id @default(autoincrement())
|
||||
checklistId Int @map("checklist_id")
|
||||
accessoireId Int? @map("accessoire_id")
|
||||
nomElement String @map("nom_element")
|
||||
etat String
|
||||
quantiteConstatee Int @map("quantite_constatee")
|
||||
commentaire String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
checklist Checklist @relation(fields: [checklistId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
accessoire Accessoire? @relation(fields: [accessoireId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
|
||||
@@map("checklist_element")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user