Represents a logged change to the database.
Inheritance: Net.Sf.Dbdeploy.Database.UniqueChange
示例#1
0
 /// <summary>
 /// Asserts the change properties.
 /// </summary>
 /// <param name="expected">The expected.</param>
 /// <param name="retrieved">The retrieved.</param>
 private static void AssertChangeProperties(ChangeEntry expected, ChangeEntry retrieved)
 {
     Assert.AreEqual(expected.Folder, retrieved.Folder, "Folder does not match.");
     Assert.AreEqual(expected.ScriptNumber, retrieved.ScriptNumber, "ScriptNumber does not match.");
     Assert.AreEqual(expected.ChangeId, retrieved.ChangeId, "ChangeId does not match.");
     Assert.AreEqual(expected.ScriptName, retrieved.ScriptName, "ScriptName does not match.");
     Assert.AreEqual(expected.Status, retrieved.Status, "ScriptStatus does not match.");
     Assert.AreEqual(expected.Output, retrieved.Output, "ScriptOutput does not match.");
 }
示例#2
0
        /// <summary>
        /// Gets the applied changes from the database..
        /// </summary>
        /// <returns>List of applied changes.</returns>
        /// <exception cref="SchemaVersionTrackingException">Could not retrieve change log from database because:  + e.Message</exception>
        public virtual IList <ChangeEntry> GetAppliedChanges()
        {
            if (!this.ChangeLogTableExists())
            {
                return(new List <ChangeEntry>());
            }

            var changes = new List <ChangeEntry>();

            try
            {
                // Find all changes that are not resolved.
                string sql = string.Format(CultureInfo.InvariantCulture, "SELECT ChangeId, Folder, ScriptNumber, ScriptName, ScriptStatus, ScriptOutput FROM {0}", this.changeLogTableName);

                using (var reader = this.queryExecuter.ExecuteQuery(sql))
                {
                    while (reader.Read())
                    {
                        var folder       = GetValue <string>(reader, "Folder");
                        var scriptNumber = GetValue <short>(reader, "ScriptNumber");
                        var changeEntry  = new ChangeEntry(folder, scriptNumber);
                        changeEntry.ChangeId   = GetValue <int>(reader, "ChangeId");
                        changeEntry.ScriptName = GetValue <string>(reader, "ScriptName");
                        // SQL Server, PGSQL use byte, but mysql uses sbyte,
                        // so use Convert instead of cast to work with both cases
                        changeEntry.Status = (ScriptStatus)Convert.ToByte(GetValue <object>(reader, "ScriptStatus"));
                        changeEntry.Output = GetValue <string>(reader, "ScriptOutput");

                        changes.Add(changeEntry);
                    }
                }

                // Make sure everything is in correct ordering.
                changes.Sort();

                return(changes);
            }
            catch (DbException e)
            {
                throw new SchemaVersionTrackingException(
                          "Could not retrieve change log from database because: " + e.Message, e);
            }
        }
        public void obter_scripts_pedente_execucao_e_marcados_como_resolvido()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);
            scriptAplicado1.ScriptName = "8.Create Product Table.sql";
            scriptAplicado1.Status = ScriptStatus.ProblemResolved;
            
            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);
            scriptAplicado2.ScriptName = "09.Add Product Data.sql";
            scriptAplicado2.Status = ScriptStatus.Success;

            var scriptAplicado3 = new ChangeEntry("2.0.0.0", 10);
            scriptAplicado2.ScriptName = "10.Add Product Data.sql";
            scriptAplicado2.Status = ScriptStatus.SucessRevisedUser;

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List<ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2,
                scriptAplicado3,
            });

            var changeScript1 = new ChangeScript("2.0.0.0", 8, "8.Create Product Table.sql");
            var changeScript2 = new ChangeScript("2.0.0.0", 9, "09.Add Product Data.sql");
            var changeScript3 = new ChangeScript("2.10.0.0", 1, "1.SQLCMD Add Customer Table.sql");

            changeScriptRepository.Setup(x => x.GetAvailableChangeScripts()).Returns(new List<ChangeScript>
            {
                changeScript1,
                changeScript2,
                changeScript3
            });

            var listaChangeScripts = repositorioScripts.ObterScriptsPendenteExecucao(null);

            listaChangeScripts.Should().NotBeEmpty();
            listaChangeScripts.Count.Should().Be(2);

            listaChangeScripts.Should().NotContain(x => x.ScriptName == "09.Add Product Data.sql" && x.Folder == "2.0.0.0");
            listaChangeScripts.Should().NotContain(x => x.ScriptName == "10.Add Product Data.sql" && x.Folder == "2.0.0.0");
            listaChangeScripts.Should().Contain(x => x.ScriptName == "8.Create Product Table.sql" && x.Folder == "2.0.0.0");
            listaChangeScripts.Should().Contain(x => x.ScriptName == "1.SQLCMD Add Customer Table.sql" && x.Folder == "2.10.0.0");
        }
示例#4
0
        /// <summary>
        /// Gets the applied changes from the database..
        /// </summary>
        /// <returns>List of applied changes.</returns>
        /// <exception cref="SchemaVersionTrackingException">Could not retrieve change log from database because:  + e.Message</exception>
        public virtual IList <ChangeEntry> GetAppliedChanges()
        {
            if (!ChangeLogTableExists())
            {
                return(new List <ChangeEntry>());
            }

            var changes = new List <ChangeEntry>();

            try
            {
                // Find all changes that are not resolved.
                var sql = string.Format(CultureInfo.InvariantCulture, "SELECT ChangeId, Folder, ScriptNumber, ScriptName, ScriptStatus, ScriptOutput FROM {0}", changeLogTableName);

                using (var reader = queryExecuter.ExecuteQuery(sql))
                {
                    while (reader.Read())
                    {
                        var folder       = GetValue <string>(reader, "Folder");
                        var scriptNumber = GetShort(reader, "ScriptNumber");
                        var changeEntry  = new ChangeEntry(folder, scriptNumber);
                        changeEntry.ChangeId   = GetValue <string>(reader, "ChangeId");
                        changeEntry.ScriptName = GetValue <string>(reader, "ScriptName");
                        changeEntry.Status     = (ScriptStatus)GetByte(reader, "ScriptStatus");
                        changeEntry.Output     = GetValue <string>(reader, "ScriptOutput");

                        changes.Add(changeEntry);
                    }
                }

                // Make sure everything is in correct ordering.
                changes.Sort();

                return(changes);
            }
            catch (DbException e)
            {
                throw new SchemaVersionTrackingException(
                          "Could not retrieve change log from database because: " + e.Message, e);
            }
        }
 /// <summary>
 /// Asserts the change properties.
 /// </summary>
 /// <param name="expected">The expected.</param>
 /// <param name="retrieved">The retrieved.</param>
 private static void AssertChangeProperties(ChangeEntry expected, ChangeEntry retrieved)
 {
     Assert.AreEqual(expected.Folder, retrieved.Folder, "Folder does not match.");
     Assert.AreEqual(expected.ScriptNumber, retrieved.ScriptNumber, "ScriptNumber does not match.");
     Assert.AreEqual(expected.ChangeId, retrieved.ChangeId, "ChangeId does not match.");
     Assert.AreEqual(expected.ScriptName, retrieved.ScriptName, "ScriptName does not match.");
     Assert.AreEqual(expected.Status, retrieved.Status, "ScriptStatus does not match.");
     Assert.AreEqual(expected.Output, retrieved.Output, "ScriptOutput does not match.");
 }
        public void aplicar_mudancas_ate_script_informado()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);
            scriptAplicado1.ScriptName = "8.Create Product Table.sql";
            scriptAplicado1.Status = ScriptStatus.Success;
            
            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);
            scriptAplicado2.ScriptName = "09.Add Product Data.sql";
            scriptAplicado2.Status = ScriptStatus.Success;

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List<ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2
            });

            var changeScript1 = new ChangeScript("2.0.0.0", 8);
            var changeScript2 = new ChangeScript("2.0.0.0", 9);
            var changeScript3 = new ChangeScript("2.10.0.0", 1);
            var changeScript4 = new ChangeScript("2.10.0.0", 2);
            var changeScript5 = new ChangeScript("2.10.0.0", 3);

            changeScriptRepository.Setup(x => x.GetAvailableChangeScripts()).Returns(new List<ChangeScript>
            {
                changeScript1,
                changeScript2,
                changeScript3,
                changeScript4,
                changeScript5
            });

            var pendenteExecucao = repositorioScripts.ObterScriptsPendenteExecucao(new UniqueChange("2.10.0.0", 2));

            pendenteExecucao.Should().NotBeEmpty();
            pendenteExecucao.Count.Should().Be(2);
            pendenteExecucao[0].Folder.Should().Be("2.10.0.0");
            pendenteExecucao[0].ScriptNumber.Should().Be(1);
            pendenteExecucao[1].Folder.Should().Be("2.10.0.0");
            pendenteExecucao[1].ScriptNumber.Should().Be(2);
        }
        public void obter_script_especifico()
        {
            var changeEntryASerRetornado = new ChangeEntry("folder2", 1);
            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List<ChangeEntry>
            {
                new ChangeEntry("folder1", 1),
                new ChangeEntry("folder1", 2),
                changeEntryASerRetornado,
                new ChangeEntry("folder2", 2),
            });
            var changeScript = new ChangeScript("folder2", 1, new FileInfo("script.sql"), Encoding.UTF8);

            var changeEntry = repositorioScripts.ObterScriptExecutado(changeScript);

            changeEntry.Should().NotBeNull();
            changeEntry.Should().Be(changeEntryASerRetornado);
        }
        public void obter_scripts_com_erro()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);
            scriptAplicado1.ScriptName = "8.Create Product Table.sql";
            scriptAplicado1.Status = ScriptStatus.Failure;
            scriptAplicado1.Output = "Ocorreu algum erro ao executar";

            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);
            scriptAplicado2.ScriptName = "09.Add Product Data.sql";
            scriptAplicado2.Status = ScriptStatus.Failure;
            scriptAplicado2.Output = "Insert duplicate ID error";

            var scriptAplicado3 = new ChangeEntry("2.0.0.0", 10);
            scriptAplicado3.ScriptName = "10.Add Product Data.sql";
            scriptAplicado3.Status = ScriptStatus.Success;

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List<ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2,
                scriptAplicado3
            });

            var scripsComErroDeExecucao = repositorioScripts.ObterScritpsExecutadosComErro();

            scripsComErroDeExecucao.Should().NotBeEmpty();
            scripsComErroDeExecucao.Count.Should().Be(2);
            scripsComErroDeExecucao[0].ScriptName.Should().Be("8.Create Product Table.sql");
            scripsComErroDeExecucao[0].Output.Should().Be("Ocorreu algum erro ao executar");
            scripsComErroDeExecucao[1].ScriptName.Should().Be("09.Add Product Data.sql");
            scripsComErroDeExecucao[1].Output.Should().Be("Insert duplicate ID error");
        }
        public void obter_scripts_aplicados()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);
            scriptAplicado1.ScriptName = "8.Create Product Table.sql";

            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);
            scriptAplicado2.ScriptName = "09.Add Product Data.sql";

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List<ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2
            });

            var scriptsAplicados = repositorioScripts.ObterScriptsAplicados();

            scriptsAplicados.Should().NotBeEmpty();
            scriptsAplicados.Count.Should().Be(2);
            scriptsAplicados.Should().Contain(x => x.ScriptName == "8.Create Product Table.sql" && x.Folder == "2.0.0.0");
            scriptsAplicados.Should().Contain(x => x.ScriptName == "09.Add Product Data.sql" && x.Folder == "2.0.0.0");
        }
        public void retorar_que_o_script_nao_foi_executado_com_sucesso()
        {
            var changeEntry = new ChangeEntry("Folder", 1) { Status = ScriptStatus.Failure };

            changeEntry.ExecutedSuccessfully.Should().BeFalse();
        }
        public void retornar_que_script_foi_executado_com_sucesso(ScriptStatus scriptStatus)
        {
            var changeEntry = new ChangeEntry("Folder", 1) { Status = scriptStatus };

            changeEntry.ExecutedSuccessfully.Should().BeTrue();
        }