1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Revert "Revert "[DEVOPS-1215] Build migrator CLI project (#2747)" (#2769)" (#2774)

This reverts commit f8cbd4ef7d.
This commit is contained in:
Michał Chęciński
2023-03-07 14:10:34 +01:00
committed by GitHub
parent 2c8f23ec9b
commit 5e3f4c9bbe
7 changed files with 2912 additions and 34 deletions

View File

@ -23,10 +23,40 @@ public class DbMigrator
}.ConnectionString;
}
public bool MigrateMsSqlDatabase(bool enableLogging = true,
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true,
CancellationToken cancellationToken = default(CancellationToken))
{
if (enableLogging && _logger != null)
var attempt = 1;
while (attempt < 10)
{
try
{
var success = MigrateDatabase(enableLogging, cancellationToken);
return success;
}
catch (SqlException ex)
{
if (ex.Message.Contains("Server is in script upgrade mode"))
{
attempt++;
_logger.LogInformation("Database is in script upgrade mode. " +
$"Trying again (attempt #{attempt})...");
Thread.Sleep(20000);
}
else
{
throw;
}
}
}
return false;
}
public bool MigrateDatabase(bool enableLogging = true,
CancellationToken cancellationToken = default(CancellationToken))
{
if (_logger != null)
{
_logger.LogInformation(Constants.BypassFiltersEventId, "Migrating database.");
}
@ -89,7 +119,7 @@ public class DbMigrator
var upgrader = builder.Build();
var result = upgrader.PerformUpgrade();
if (enableLogging && _logger != null)
if (_logger != null)
{
if (result.Successful)
{