Skip to content

Commit fd51e24

Browse files
author
Hamid Mayeli
committed
Add non transaction - which does not work.
1 parent b626345 commit fd51e24

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

SimpleDbUp/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
var connectionString = new Option<string>(new[] { "-c", "--connection-string" }, description: "Connection string to target database");
1111
connectionString.IsRequired = true;
1212

13+
var nonTransactional = new Option<bool>(new[] { "--non-transactional" }, "Create a transaction per scripts");
14+
1315
command.AddOption(connectionString);
1416
command.AddOption(scriptDirectory);
17+
command.AddOption(nonTransactional);
1518

16-
command.SetHandler(EmptyClass.Run, connectionString, scriptDirectory);
19+
command.SetHandler(Worker.Run, connectionString, scriptDirectory, nonTransactional);
1720

1821
var parser = new CommandLineBuilder(command)
1922
.UseHelp()

SimpleDbUp/EmptyClass.cs renamed to SimpleDbUp/Worker.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55

66
namespace SimpleDbUp;
77

8-
public class EmptyClass
8+
public class Worker
99
{
10-
public static void Run(string connectionString, string scriptsPath)
10+
public static void Run(
11+
string connectionString,
12+
string scriptsPath,
13+
bool nonTransactional
14+
)
1115
{
16+
Console.WriteLine("Running the upgrade using" +
17+
$"{Environment.NewLine}\tConnection String: {connectionString.Length} chars" +
18+
$"{Environment.NewLine}\tScripts Path: {new DirectoryInfo(scriptsPath).Name}" +
19+
$"{Environment.NewLine}\tNon transactional: {nonTransactional}");
20+
1221
try
1322
{
1423
EnsureDatabase.For.MySqlDatabase(connectionString);
@@ -18,7 +27,7 @@ public static void Run(string connectionString, string scriptsPath)
1827
ExitWithError(exception);
1928
}
2029

21-
var upgrade = DeployChanges.To
30+
var builder = DeployChanges.To
2231
.MySqlDatabase(connectionString)
2332
.WithScriptsFromFileSystem(
2433
scriptsPath,
@@ -28,8 +37,14 @@ public static void Run(string connectionString, string scriptsPath)
2837
ScriptType = DbUp.Support.ScriptType.RunOnce
2938
})
3039
.LogToConsole()
31-
.LogScriptOutput()
32-
.Build();
40+
.LogScriptOutput();
41+
42+
if (nonTransactional)
43+
builder.WithTransactionPerScript();
44+
else
45+
builder.WithTransaction();
46+
47+
var upgrade = builder.Build();
3348

3449
var result = upgrade.PerformUpgrade();
3550

0 commit comments

Comments
 (0)