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 static string CreateApplyLogScriptFor(ChangeScriptFile script) { return("INSERT INTO " + ChangesTableName + $"(scriptfile) VALUES ('{script.RelativeName}');"); }