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:
parent
6641290290
commit
0381a48ec9
@ -227,7 +227,9 @@ namespace Bit.Setup
|
|||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MigrateDatabase()
|
private static void MigrateDatabase(int attempt = 1)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Migrating database.");
|
Console.WriteLine("Migrating database.");
|
||||||
|
|
||||||
@ -240,8 +242,8 @@ namespace Bit.Setup
|
|||||||
using(var connection = new SqlConnection(masterConnectionString))
|
using(var connection = new SqlConnection(masterConnectionString))
|
||||||
{
|
{
|
||||||
var command = new SqlCommand(
|
var command = new SqlCommand(
|
||||||
"IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = 'vault') = 0) CREATE DATABASE [vault];",
|
"IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = 'vault') = 0) " +
|
||||||
connection);
|
"CREATE DATABASE [vault];", connection);
|
||||||
command.Connection.Open();
|
command.Connection.Open();
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@ -266,6 +268,20 @@ namespace Bit.Setup
|
|||||||
Console.WriteLine("Migration failed.");
|
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()
|
private static bool ValidateInstallation()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user