BEGIN TRY

BEGIN TRAN;

-- CreateTable
CREATE TABLE [dbo].[carte_etudiante] (
    [id] INT NOT NULL IDENTITY(1,1),
    [utilisateur_id] INT NOT NULL,
    [qr_code] NVARCHAR(1000) NOT NULL,
    [date_activation] DATETIME2 NOT NULL,
    [date_expiration] DATETIME2 NOT NULL,
    [actif] BIT NOT NULL CONSTRAINT [carte_etudiante_actif_df] DEFAULT 1,
    [created_at] DATETIME2 NOT NULL CONSTRAINT [carte_etudiante_created_at_df] DEFAULT CURRENT_TIMESTAMP,
    [updated_at] DATETIME2 NOT NULL,
    CONSTRAINT [carte_etudiante_pkey] PRIMARY KEY CLUSTERED ([id])
);

-- AddForeignKey
ALTER TABLE [dbo].[carte_etudiante] ADD CONSTRAINT [carte_etudiante_utilisateur_id_fkey] FOREIGN KEY ([utilisateur_id]) REFERENCES [dbo].[utilisateur]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;

COMMIT TRAN;

END TRY
BEGIN CATCH

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

END CATCH
