Represents any unique change.
Inheritance: IComparable
Example #1
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);
        }
Example #2
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.");
            }
        }
Example #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.");
            }
        }