1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00

Add rerunable option and script folder name

This commit is contained in:
Michal Checinski
2023-08-28 15:38:44 +02:00
parent 3d65219f3b
commit d82025b236

View File

@ -24,6 +24,8 @@ public class DbMigrator
} }
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true, public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true,
bool rerunable = false,
string folderName = "DbScripts",
CancellationToken cancellationToken = default(CancellationToken)) CancellationToken cancellationToken = default(CancellationToken))
{ {
var attempt = 1; var attempt = 1;
@ -32,7 +34,7 @@ public class DbMigrator
{ {
try try
{ {
var success = MigrateDatabase(enableLogging, cancellationToken); var success = MigrateDatabase(enableLogging, rerunable, folderName, cancellationToken);
return success; return success;
} }
catch (SqlException ex) catch (SqlException ex)
@ -54,6 +56,8 @@ public class DbMigrator
} }
public bool MigrateDatabase(bool enableLogging = true, public bool MigrateDatabase(bool enableLogging = true,
bool rerunable = false,
string folderName = "DbScripts",
CancellationToken cancellationToken = default(CancellationToken)) CancellationToken cancellationToken = default(CancellationToken))
{ {
if (_logger != null) if (_logger != null)
@ -98,9 +102,9 @@ public class DbMigrator
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var builder = DeployChanges.To var builder = DeployChanges.To
.SqlDatabase(_connectionString) .SqlDatabase(_connectionString)
.JournalRerunableToSqlTable("dbo", "Migration") .JournalRerunableToSqlTable("dbo", "Migration", rerunable)
.WithScriptsAndCodeEmbeddedInAssembly(Assembly.GetExecutingAssembly(), .WithScriptsAndCodeEmbeddedInAssembly(Assembly.GetExecutingAssembly(),
s => s.Contains($".DbScripts.") && !s.Contains(".Archive.")) s => s.Contains($".{folderName}.") && !s.Contains(".Archive."))
.WithTransaction() .WithTransaction()
.WithExecutionTimeout(new TimeSpan(0, 5, 0)); .WithExecutionTimeout(new TimeSpan(0, 5, 0));