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

[DEVOPS-1218] Add dryrun mode to MsSqlMigratorUtility (#3795)

* Add dryrun mode to MsSqlMigratorUtility

* Fix

* Update util/MsSqlMigratorUtility/Program.cs

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>

* Update util/MsSqlMigratorUtility/Program.cs

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>

* Update util/MsSqlMigratorUtility/Program.cs

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>

* Fixes

* Fix using

* Format

* Update util/MsSqlMigratorUtility/Program.cs

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>

* Fixes

* Fix after merge

* Fix

* Fix

* Remove unnecessary param name

---------

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
Michał Chęciński
2024-03-25 15:22:02 +01:00
committed by GitHub
parent 03fe077ec8
commit fd71ed8584
2 changed files with 24 additions and 6 deletions

View File

@ -1,5 +1,6 @@
using System.Data;
using System.Reflection;
using System.Text;
using Bit.Core;
using DbUp;
using DbUp.Helpers;
@ -22,6 +23,7 @@ public class DbMigrator
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true,
bool repeatable = false,
string folderName = MigratorConstants.DefaultMigrationsFolderName,
bool dryRun = false,
CancellationToken cancellationToken = default)
{
var attempt = 1;
@ -31,7 +33,7 @@ public class DbMigrator
{
PrepareDatabase(cancellationToken);
var success = MigrateDatabase(enableLogging, repeatable, folderName, cancellationToken);
var success = MigrateDatabase(enableLogging, repeatable, folderName, dryRun, cancellationToken);
return success;
}
catch (SqlException ex)
@ -99,6 +101,7 @@ public class DbMigrator
private bool MigrateDatabase(bool enableLogging = true,
bool repeatable = false,
string folderName = MigratorConstants.DefaultMigrationsFolderName,
bool dryRun = false,
CancellationToken cancellationToken = default)
{
if (enableLogging)
@ -130,6 +133,19 @@ public class DbMigrator
}
var upgrader = builder.Build();
if (dryRun)
{
var scriptsToExec = upgrader.GetScriptsToExecute();
var stringBuilder = new StringBuilder("Scripts that will be applied:");
foreach (var script in scriptsToExec)
{
stringBuilder.AppendLine(script.Name);
}
_logger.LogInformation(Constants.BypassFiltersEventId, stringBuilder.ToString());
return true;
}
var result = upgrader.PerformUpgrade();
if (enableLogging)