Пример #1
0
        public override IEnumerable <string> Execute(SqlConnection connection)
        {
            var scripts = new List <string>();

            var statement = string.Format(
                "select scripts.* from [{0}] scripts",
                ScriptsRunInfo.GetTableName());

            var executedScripts =
                connection
                .Query <ScriptsRunInfo>(statement)
                .Select(si => new ScriptsRunInfo {
                ScriptName = si.ScriptName
            })
                .Distinct()
                .ToList();

            if (executedScripts.Any())
            {
                scripts.AddRange(FindScriptsThatHaveNotBeenExecutedBefore(executedScripts));
                scripts.AddRange(FindScriptsThatHaveExecutedButChanged(connection, executedScripts));
            }
            else
            {
                scripts.AddRange(FoundScripts);
            }

            return(scripts
                   .Distinct()
                   .ToList());
        }
Пример #2
0
        private bool IsScriptRunInfoTablePresent()
        {
            var statement = string.Format(
                @"SELECT Present = Count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{0}]') AND type in (N'U')",
                ScriptsRunInfo.GetTableName());

            using (var connection = _configuration.GetConnection())
            {
                return(connection.Query <int>(statement).FirstOrDefault() > 0);
            }
        }
Пример #3
0
        private void UpdateScriptInfoWithDeploymentId(ScriptsRunDeployInfo deployInfo, ScriptsRunInfo runInfo)
        {
            var statement = string.Format("update [{0}] set [DeployInfoId] = {1} where [Id] = {2}",
                                          ScriptsRunInfo.GetTableName(),
                                          deployInfo.Id.ToString(),
                                          runInfo.Id.ToString());

            using (var connection = _configuration.GetConnection())
            {
                connection.Execute(statement);
            }
        }
Пример #4
0
        private void UpdateScriptForVersion(ScriptsRunInfo info, long?versionId = null)
        {
            if (!versionId.HasValue)
            {
                return;
            }

            var update = string.Format("update [{0}] set [versioninfoid] = {1} where id = {2}",
                                       ScriptsRunInfo.GetTableName(),
                                       versionId,
                                       info.Id.ToString());

            using (var connection = _configuration.GetConnection())
            {
                connection.Execute(update);
            }
        }
Пример #5
0
        private IEnumerable <ScriptsRunInfo> GetAllScriptsForCurrentVersion(out VersionInfo versionInfo)
        {
            versionInfo = GetMaxVersion();

            if (versionInfo == null)
            {
                return(new List <ScriptsRunInfo>());
            }

            var statement = string.Format("select s.* from [{0}] s where [VersionInfoId] ='{1}'",
                                          ScriptsRunInfo.GetTableName(),
                                          versionInfo.Id);

            using (var connection = _configuration.GetConnection())
            {
                var scripts = connection.Query <ScriptsRunInfo>(statement).ToList();
                return(scripts);
            }
        }
Пример #6
0
        protected IEnumerable <ScriptsRunInfo> GetExecutedScriptsFromHistory()
        {
            var statement = string.Format(
                @"select scripts.ScriptName, scripts.ScriptHash 
                from [{0}] scripts
                group by scripts.ScriptName, scripts.ScriptHash",
                ScriptsRunInfo.GetTableName());

            using (var connection = Configuration.GetConnection())
            {
                return(connection
                       .Query <ScriptsRunInfo>(statement)
                       .Select(si => new ScriptsRunInfo
                {
                    ScriptName = si.ScriptName,
                    ScriptHash = si.ScriptHash
                })
                       .Distinct()
                       .ToList());
            }
        }
Пример #7
0
 private void CheckForScriptsRunInfoTable()
 {
     Logger.InfoFormat("Creating [{0}] table, if it does not exist..", ScriptsRunInfo.GetTableName());
     CreateInfoTable("scriptsruninfo_create.sql");
 }