Ejemplo n.º 1
0
        /// <summary>
        /// Compara os scritps aplicados e os scripts que se encontram no diretório e retorna uma lista dos scripts pendentes de execução
        /// </summary>
        /// <param name="lastChangeToApply"></param>
        /// <returns></returns>
        public IList <ChangeScript> ObterScriptsPendenteExecucao(UniqueChange lastChangeToApply)
        {
            var scriptsAplicados = ObterScriptsAplicados();
            var todosScripts     = ObterTodosOsScripts();

            return(IdentificarScriptsQueFaltamExecutar(lastChangeToApply, todosScripts, scriptsAplicados));
        }
Ejemplo n.º 2
0
        private IList <ChangeScript> IdentificarScriptsQueFaltamExecutar(UniqueChange lastChangeToApply, IEnumerable <ChangeScript> scripts, IList <ChangeEntry> aplicados)
        {
            var listaScriptsParaAplicar = new List <ChangeScript>();

            // Re-run any scripts that have not been run, or are failed or resolved.
            // The check to exit on previous failure is done before this call.
            foreach (var script in scripts)
            {
                // If script has not been run yet, add it to the list.
                bool applyScript = false;
                var  changeEntry = aplicados.FirstOrDefault(a => a.CompareTo(script) == 0);
                if (changeEntry == null)
                {
                    applyScript = true;
                }
                else
                {
                    // If the script has already been run check if it should be run again.
                    if (!changeEntry.ExecutedSuccessfully)
                    {
                        // Assign the ID so the record can be updated.
                        script.ChangeId = changeEntry.ChangeId;
                        applyScript     = true;
                    }
                }

                if (applyScript)
                {
                    // Just add script if there is no cap specified.
                    if (lastChangeToApply == null)
                    {
                        listaScriptsParaAplicar.Add(script);
                    }
                    else if (script.CompareTo(lastChangeToApply) <= 0)
                    {
                        // Script is less than last change to apply.
                        listaScriptsParaAplicar.Add(script);
                    }
                    else
                    {
                        // Stop adding scripts as last change to apply has been met.
                        break;
                    }
                }
            }
            return(listaScriptsParaAplicar);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes the change scripts.
        /// </summary>
        /// <param name="lastChangeToApply">The last change to apply.</param>
        /// <param name="forceUpdate">if set to <c>true</c> any previously failed scripts will be retried.</param>
        public void ProcessChangeScripts(UniqueChange lastChangeToApply, bool forceUpdate = false)
        {
            if (lastChangeToApply != null)
            {
                Info("\nOnly applying changes up to and including change script '{0}'.\n", lastChangeToApply);
            }
            
            var applied = repositorioScripts.ObterScriptsAplicados();

            // If force update is not set, than if there are any previous script runs that failed it should stop.
            if (!forceUpdate)
            {
                this.CheckForFailedScripts(applied);
            }

            var scripts = repositorioScripts.ObterTodosOsScripts();
            var toApply = repositorioScripts.ObterScriptsPendenteExecucao(lastChangeToApply);

            this.LogStatus(scripts, applied, toApply);

            var includeChangeLogTable = this.createChangeLogTable && !this.databaseSchemaVersionManager.ChangeLogTableExists();
            this.doApplier.Apply(toApply, includeChangeLogTable);

            if (this.undoApplier != null)
            {
                Info("Generating undo scripts...");

                var toUndoApply = new List<ChangeScript>(toApply);
                toUndoApply.Reverse();

                this.undoApplier.Apply(toUndoApply, false);
            }

            if (toApply.Any())
            {
                Info("All scripts applied successfully.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes the change scripts.
        /// </summary>
        /// <param name="lastChangeToApply">The last change to apply.</param>
        /// <param name="forceUpdate">if set to <c>true</c> any previously failed scripts will be retried.</param>
        public void ProcessChangeScripts(UniqueChange lastChangeToApply, bool forceUpdate = false)
        {
            if (lastChangeToApply != null)
            {
                Info("\nOnly applying changes up to and including change script '{0}'.\n", lastChangeToApply);
            }
            
            var applied = this.appliedChangesProvider.GetAppliedChanges();

            // If force update is not set, than if there are any previous script runs that failed it should stop.
            if (!forceUpdate)
            {
                this.CheckForFailedScripts(applied);
            }

            var scripts = this.availableChangeScriptsProvider.GetAvailableChangeScripts();
            var toApply = this.IdentifyChangesToApply(lastChangeToApply, scripts, applied);

            this.LogStatus(scripts, applied, toApply);

            var includeChangeLogTable = this.createChangeLogTable && !this.appliedChangesProvider.ChangeLogTableExists();
            this.doApplier.Apply(toApply, includeChangeLogTable);

            if (this.undoApplier != null)
            {
                Info("Generating undo scripts...");

                var toUndoApply = new List<ChangeScript>(toApply);
                toUndoApply.Reverse();

                this.undoApplier.Apply(toUndoApply, false);
            }

            if (toApply.Any())
            {
                Info("All scripts applied successfully.");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Identifies the changes to apply to the database.
        /// </summary>
        /// <param name="lastChangeToApply">The last change to apply.</param>
        /// <param name="scripts">The scripts.</param>
        /// <param name="applied">The applied changes.</param>
        /// <returns>List of changes to apply.</returns>
        private IList<ChangeScript> IdentifyChangesToApply(UniqueChange lastChangeToApply, IEnumerable<ChangeScript> scripts, IList<ChangeEntry> applied)
        {
            var changes = new List<ChangeScript>();

            // Re-run any scripts that have not been run, or are failed or resolved.
            // The check to exit on previous failure is done before this call.
            foreach (var script in scripts)
            {
                // If script has not been run yet, add it to the list.
                bool applyScript = false;
                var changeEntry = applied.FirstOrDefault(a => a.CompareTo(script) == 0);
                if (changeEntry == null)
                {
                    applyScript = true;
                }
                else
                {
                    // If the script has already been run check if it should be run again.
                    if (changeEntry.Status != ScriptStatus.Success)
                    {
                        // Assign the ID so the record can be updated.
                        script.ChangeId = changeEntry.ChangeId;
                        applyScript = true;
                    }
                }

                if (applyScript)
                {
                    // Just add script if there is no cap specified.
                    if (lastChangeToApply == null)
                    {
                        changes.Add(script);
                    }
                    else if (script.CompareTo(lastChangeToApply) <= 0)
                    {
                        // Script is less than last change to apply.
                        changes.Add(script);
                    }
                    else
                    {
                        // Stop adding scripts as last change to apply has been met.
                        break;
                    }
                }
            }

            return changes;
        }