static void ApplyChangeScript(NpgsqlConnection connection, ChangeScriptFile script, IReadOnlyDictionary <string, string> variables) { var content = File.ReadAllText(script.FullPath); var directives = ChangeScriptDirectiveParser.Parse(content); var commandText = new StringBuilder(); if (directives.IsTransacted) { commandText.AppendLine("START TRANSACTION ISOLATION LEVEL REPEATABLE READ;"); } commandText.AppendLine(ChangeScriptVariableProcessor.InsertVariables(content, variables)); commandText.AppendLine(";"); commandText.AppendLine(AppliedChangeScriptLog.CreateApplyLogScriptFor(script)); if (directives.IsTransacted) { commandText.AppendLine("COMMIT TRANSACTION;"); } using (var command = new NpgsqlCommand(commandText.ToString(), connection)) { command.ExecuteNonQuery(); } }
public void ByDefaultScriptsAreTransacted() { var directives = ChangeScriptDirectiveParser.Parse("INSERT INTO foo (id) VALUES (1)"); Assert.True(directives.IsTransacted); }
public void DirectiveCanSpecifyNoTransaction() { var directives = ChangeScriptDirectiveParser.Parse("-- PIGGY NO TRANSACTION\nINSERT INTO foo (id) VALUES (1)"); Assert.False(directives.IsTransacted); }