From ad4ee02631fe9dbaba94d594d24b34676b77fcda Mon Sep 17 00:00:00 2001 From: Eveldee Date: Mon, 10 Apr 2023 12:38:11 +0200 Subject: [PATCH] [Activity] Add database backup on migration --- Cocotte/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cocotte/Program.cs b/Cocotte/Program.cs index c33fd66..f8bedf7 100644 --- a/Cocotte/Program.cs +++ b/Cocotte/Program.cs @@ -93,6 +93,12 @@ await using(var scope = host.Services.CreateAsyncScope()) } else { + // Backup database before migrations + if (File.Exists("cocotte.db")) + { + File.Copy("cocotte.db", $"cocotte.{DateTime.UtcNow:s}.db"); + } + // Apply migrations await dbContext.Database.MigrateAsync(); }