Skip to content

Commit

Permalink
Add non transaction - which does not work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamid Mayeli committed Jan 21, 2023
1 parent b626345 commit fd51e24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion SimpleDbUp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
var connectionString = new Option<string>(new[] { "-c", "--connection-string" }, description: "Connection string to target database");
connectionString.IsRequired = true;

var nonTransactional = new Option<bool>(new[] { "--non-transactional" }, "Create a transaction per scripts");

command.AddOption(connectionString);
command.AddOption(scriptDirectory);
command.AddOption(nonTransactional);

command.SetHandler(EmptyClass.Run, connectionString, scriptDirectory);
command.SetHandler(Worker.Run, connectionString, scriptDirectory, nonTransactional);

var parser = new CommandLineBuilder(command)
.UseHelp()
Expand Down
25 changes: 20 additions & 5 deletions SimpleDbUp/EmptyClass.cs → SimpleDbUp/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@

namespace SimpleDbUp;

public class EmptyClass
public class Worker
{
public static void Run(string connectionString, string scriptsPath)
public static void Run(
string connectionString,
string scriptsPath,
bool nonTransactional
)
{
Console.WriteLine("Running the upgrade using" +
$"{Environment.NewLine}\tConnection String: {connectionString.Length} chars" +
$"{Environment.NewLine}\tScripts Path: {new DirectoryInfo(scriptsPath).Name}" +
$"{Environment.NewLine}\tNon transactional: {nonTransactional}");

try
{
EnsureDatabase.For.MySqlDatabase(connectionString);
Expand All @@ -18,7 +27,7 @@ public static void Run(string connectionString, string scriptsPath)
ExitWithError(exception);
}

var upgrade = DeployChanges.To
var builder = DeployChanges.To
.MySqlDatabase(connectionString)
.WithScriptsFromFileSystem(
scriptsPath,
Expand All @@ -28,8 +37,14 @@ public static void Run(string connectionString, string scriptsPath)
ScriptType = DbUp.Support.ScriptType.RunOnce
})
.LogToConsole()
.LogScriptOutput()
.Build();
.LogScriptOutput();

if (nonTransactional)
builder.WithTransactionPerScript();
else
builder.WithTransaction();

var upgrade = builder.Build();

var result = upgrade.PerformUpgrade();

Expand Down

0 comments on commit fd51e24

Please sign in to comment.