Exemple #1
0
        private static bool ScriptShouldRun(
            SqlScript sqlScript,
            IEnumerable <string> executedScriptNames,
            ScriptNameComparer comparer,
            IEnumerable <ExecutedSqlScript> executedScripts,
            IHasher hasher)
        {
            switch (sqlScript.SqlScriptOptions.ScriptType)
            {
            case ScriptType.RunAlways:
                return(true);

            case ScriptType.RunOnce:
                return(!executedScriptNames.Contains(sqlScript.Name, comparer));

            case ScriptType.RunOnChange:
            {
                if (executedScripts == null)
                {
                    throw new ArgumentNullException(nameof(executedScripts));
                }

                if (hasher == null)
                {
                    throw new ArgumentNullException(nameof(hasher));
                }

                return(DefaultScriptFilter.ScriptIsNewOrChanged(sqlScript, comparer, executedScripts, hasher));
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
 public IEnumerable <SqlScript> Filter(
     IEnumerable <SqlScript> sorted,
     HashSet <string> executedScriptNames,
     ScriptNameComparer comparer)
 {
     return(sorted.Where(sqlScript => DefaultScriptFilter.ScriptShouldRun(sqlScript, executedScriptNames, comparer, null, null)));
 }
Exemple #3
0
 public IEnumerable <SqlScript> Filter(
     IEnumerable <SqlScript> sorted,
     HashSet <string> executedScriptNames,
     ScriptNameComparer comparer)
 {
     return(_sort(sorted).Where(s => !executedScriptNames.Contains(s.Name)));
 }
 public IEnumerable<SqlScript> Filter
 (
     IOrderedEnumerable<SqlScript> sorted, 
     IEnumerable<ExecutedSqlScript> executedScripts, 
     ScriptNameComparer scriptNameComparer,
     IHasher hasher
 )
 {
     // check if script has been already executed based on name and hash
     return sorted.Where(s => !executedScripts.Any(y => scriptNameComparer.Equals(y.Name, s.Name) && (y.Hash == null || y.Hash == hasher.GetHash(s.Contents))));
 }
Exemple #5
0
        public IEnumerable <SqlScript> Filter(
            IOrderedEnumerable <SqlScript> sorted,
            IEnumerable <ExecutedSqlScript> executedScripts,
            ScriptNameComparer comparer,
            IHasher hasher)
        {
            var executedScriptsList = executedScripts.ToList();
            var executedScriptNames = new HashSet <string>(executedScriptsList.Select(x => x.Name), comparer);

            return(sorted.Where(sqlScript => DefaultScriptFilter.ScriptShouldRun(sqlScript, executedScriptNames, comparer, executedScriptsList, hasher)));
        }
Exemple #6
0
        private static bool ScriptIsNewOrChanged(
            SqlScript sqlScript,
            ScriptNameComparer comparer,
            IEnumerable <ExecutedSqlScript> executedScripts,
            IHasher hasher) =>
        !executedScripts.Any(
            executedScript =>
        {
            if (comparer.Equals(executedScript.Name, sqlScript.Name))
            {
                return(executedScript.Hash == null || executedScript.Hash == hasher.GetHash(sqlScript.Contents));
            }

            return(false);
        });
 public IEnumerable <SqlScript> Filter(IEnumerable <SqlScript> sorted, HashSet <string> executedScriptNames, ScriptNameComparer comparer)
 => sorted.Where(s => s.SqlScriptOptions.ScriptType == ScriptType.RunAlways || !executedScriptNames.Contains(s.Name, comparer));
 public IEnumerable<SqlScript> Filter(IEnumerable<SqlScript> sorted, HashSet<string> executedScriptNames, ScriptNameComparer comparer)
      =>  sorted.Where(s => !executedScriptNames.Contains(s.Name, comparer));
Exemple #9
0
        public IEnumerable <SqlScript> Filter(IEnumerable <SqlScript> sorted, HashSet <ExecutedSqlScript> executedScripts, ScriptNameComparer comparer)
        {
            return(sorted.Where(x =>
            {
                var executedScriptsOrdered = executedScripts
                                             .OrderByDescending(d => d.Applied);//order them by most recently applied first, grab the latest one applied.
                IEnumerable <ExecutedSqlScript> executedSqlScripts = executedScriptsOrdered.Where(s => s.Name.Equals(x.Name, StringComparison.OrdinalIgnoreCase));

                ExecutedSqlScript executedSqlScript = executedSqlScripts.FirstOrDefault();
                //if it's a run always script
                //if the script has not been run (executedSqlScript ==null)
                //if the script's hashes do not match
                bool willRun =
                    x.SqlScriptOptions.ScriptType == ScriptType.RunAlways ||
                    executedSqlScript == null ||   // ScriptType.RunOnce
                    (x.SqlScriptOptions.ScriptType == ScriptType.RunHash && executedSqlScript.Hash != x.Hash);
                return willRun;
            }));
        }