Пример #1
0
        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();
            }
        }
Пример #2
0
        public void ConfiguredVariablesAreReplaced()
        {
            var variables = new Dictionary <string, string>
            {
                ["one"] = "1",
                ["two"] = "2"
            };

            const string content = "$$one$-$two$-$two$-$three$";
            var          result  = ChangeScriptVariableProcessor.InsertVariables(content, variables);

            Assert.Equal("$1-2-2-$three$", result);
        }