BEGIN TRY

BEGIN TRAN;

-- CreateTable
CREATE TABLE [dbo].[salle_pret] (
    [id] INT NOT NULL IDENTITY(1,1),
    [nom] NVARCHAR(1000) NOT NULL,
    [localisation] NVARCHAR(1000) NOT NULL,
    [campus_id] INT NOT NULL,
    [actif] BIT NOT NULL CONSTRAINT [salle_pret_actif_df] DEFAULT 1,
    [created_at] DATETIME2 NOT NULL CONSTRAINT [salle_pret_created_at_df] DEFAULT CURRENT_TIMESTAMP,
    [updated_at] DATETIME2 NOT NULL,
    CONSTRAINT [salle_pret_pkey] PRIMARY KEY CLUSTERED ([id])
);

-- CreateTable
CREATE TABLE [dbo].[poste_emprunt] (
    [id] INT NOT NULL IDENTITY(1,1),
    [nom] NVARCHAR(1000) NOT NULL,
    [identifiant_poste] NVARCHAR(1000) NOT NULL,
    [salle_pret_id] INT NOT NULL,
    [actif] BIT NOT NULL CONSTRAINT [poste_emprunt_actif_df] DEFAULT 1,
    [created_at] DATETIME2 NOT NULL CONSTRAINT [poste_emprunt_created_at_df] DEFAULT CURRENT_TIMESTAMP,
    [updated_at] DATETIME2 NOT NULL,
    CONSTRAINT [poste_emprunt_pkey] PRIMARY KEY CLUSTERED ([id])
);

-- AddForeignKey
ALTER TABLE [dbo].[salle_pret] ADD CONSTRAINT [salle_pret_campus_id_fkey] FOREIGN KEY ([campus_id]) REFERENCES [dbo].[campus]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE [dbo].[poste_emprunt] ADD CONSTRAINT [poste_emprunt_salle_pret_id_fkey] FOREIGN KEY ([salle_pret_id]) REFERENCES [dbo].[salle_pret]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;

COMMIT TRAN;

END TRY
BEGIN CATCH

IF @@TRANCOUNT > 0
BEGIN
    ROLLBACK TRAN;
END;
THROW

END CATCH
