1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-22 05:25:10 -05:00

re-attempt db migrate on update mode failure

This commit is contained in:
Kyle Spearrin 2018-03-27 15:12:28 -04:00
parent 6641290290
commit 0381a48ec9

View File

@ -227,7 +227,9 @@ namespace Bit.Setup
Console.WriteLine("\n");
}
private static void MigrateDatabase()
private static void MigrateDatabase(int attempt = 1)
{
try
{
Console.WriteLine("Migrating database.");
@ -240,8 +242,8 @@ namespace Bit.Setup
using(var connection = new SqlConnection(masterConnectionString))
{
var command = new SqlCommand(
"IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = 'vault') = 0) CREATE DATABASE [vault];",
connection);
"IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = 'vault') = 0) " +
"CREATE DATABASE [vault];", connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
@ -266,6 +268,20 @@ namespace Bit.Setup
Console.WriteLine("Migration failed.");
}
}
catch(SqlException e)
{
if(e.Message.Contains("Server is in script upgrade mode") && attempt < 3)
{
var nextAttempt = attempt + 1;
Console.WriteLine("Database is in script upgrade mode. " +
"Trying again (attempt #{0})...", nextAttempt);
MigrateDatabase(nextAttempt);
return;
}
throw e;
}
}
private static bool ValidateInstallation()
{