feat(db): add Materiel, Accessoire and MaterielAccessoire models

This commit is contained in:
SaidSoighiri94
2026-06-04 14:18:21 +02:00
parent dfa73cdab0
commit 0774ee3669
2 changed files with 117 additions and 1 deletions
@@ -0,0 +1,68 @@
BEGIN TRY
BEGIN TRAN;
-- CreateTable
CREATE TABLE [dbo].[materiel] (
[id] INT NOT NULL IDENTITY(1,1),
[nom] NVARCHAR(1000) NOT NULL,
[marque] NVARCHAR(1000) NOT NULL,
[modele] NVARCHAR(1000) NOT NULL,
[reference] NVARCHAR(1000) NOT NULL,
[numero_inventaire] NVARCHAR(1000) NOT NULL,
[numero_serie] NVARCHAR(1000) NOT NULL,
[statut] NVARCHAR(1000) NOT NULL,
[etat_general] NVARCHAR(1000) NOT NULL,
[categorie_id] INT NOT NULL,
[campus_id] INT NOT NULL,
[actif] BIT NOT NULL CONSTRAINT [materiel_actif_df] DEFAULT 1,
[created_at] DATETIME2 NOT NULL CONSTRAINT [materiel_created_at_df] DEFAULT CURRENT_TIMESTAMP,
[updated_at] DATETIME2 NOT NULL,
CONSTRAINT [materiel_pkey] PRIMARY KEY CLUSTERED ([id])
);
-- CreateTable
CREATE TABLE [dbo].[accessoire] (
[id] INT NOT NULL IDENTITY(1,1),
[nom] NVARCHAR(1000) NOT NULL,
[description] NVARCHAR(1000) NOT NULL,
[actif] BIT NOT NULL CONSTRAINT [accessoire_actif_df] DEFAULT 1,
[created_at] DATETIME2 NOT NULL CONSTRAINT [accessoire_created_at_df] DEFAULT CURRENT_TIMESTAMP,
[updated_at] DATETIME2 NOT NULL,
CONSTRAINT [accessoire_pkey] PRIMARY KEY CLUSTERED ([id])
);
-- CreateTable
CREATE TABLE [dbo].[materiel_accessoire] (
[id] INT NOT NULL IDENTITY(1,1),
[materiel_id] INT NOT NULL,
[accessoire_id] INT NOT NULL,
[quantite_attendue] INT NOT NULL,
[obligatoire] BIT NOT NULL,
CONSTRAINT [materiel_accessoire_pkey] PRIMARY KEY CLUSTERED ([id])
);
-- AddForeignKey
ALTER TABLE [dbo].[materiel] ADD CONSTRAINT [materiel_categorie_id_fkey] FOREIGN KEY ([categorie_id]) REFERENCES [dbo].[categorie_materiel]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE [dbo].[materiel] ADD CONSTRAINT [materiel_campus_id_fkey] FOREIGN KEY ([campus_id]) REFERENCES [dbo].[campus]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE [dbo].[materiel_accessoire] ADD CONSTRAINT [materiel_accessoire_materiel_id_fkey] FOREIGN KEY ([materiel_id]) REFERENCES [dbo].[materiel]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE [dbo].[materiel_accessoire] ADD CONSTRAINT [materiel_accessoire_accessoire_id_fkey] FOREIGN KEY ([accessoire_id]) REFERENCES [dbo].[accessoire]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
COMMIT TRAN;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRAN;
END;
THROW
END CATCH
+48
View File
@@ -17,6 +17,7 @@ model Campus {
updatedAt DateTime @updatedAt @map("updated_at") updatedAt DateTime @updatedAt @map("updated_at")
utilisateurs Utilisateur[] utilisateurs Utilisateur[]
sallesPret SallePret[] sallesPret SallePret[]
materiels Materiel[]
@@map("campus") @@map("campus")
} }
@@ -57,6 +58,7 @@ model CategorieMateriel {
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")
materiels Materiel[]
@@map("categorie_materiel") @@map("categorie_materiel")
} }
@@ -101,3 +103,49 @@ model CarteEtudiante {
@@map("carte_etudiante") @@map("carte_etudiante")
} }
model Materiel {
id Int @id @default(autoincrement())
nom String
marque String
modele String
reference String
numeroInventaire String @map("numero_inventaire")
numeroSerie String @map("numero_serie")
statut String
etatGeneral String @map("etat_general")
categorieId Int @map("categorie_id")
campusId Int @map("campus_id")
actif Boolean @default(true)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
categorie CategorieMateriel @relation(fields: [categorieId], references: [id])
campus Campus @relation(fields: [campusId], references: [id])
accessoires MaterielAccessoire[]
@@map("materiel")
}
model Accessoire {
id Int @id @default(autoincrement())
nom String
description String
actif Boolean @default(true)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
materiels MaterielAccessoire[]
@@map("accessoire")
}
model MaterielAccessoire {
id Int @id @default(autoincrement())
materielId Int @map("materiel_id")
accessoireId Int @map("accessoire_id")
quantiteAttendue Int @map("quantite_attendue")
obligatoire Boolean
materiel Materiel @relation(fields: [materielId], references: [id])
accessoire Accessoire @relation(fields: [accessoireId], references: [id])
@@map("materiel_accessoire")
}