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

            using (var connection = _configuration.GetConnection())
            {
                return(connection.Query <int>(statement).FirstOrDefault() > 0);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        protected VersionInfo CreateNewVersion(VersionInfo versionInfo = null)
        {
            if (versionInfo == null)
            {
                versionInfo = new VersionInfo();
            }

            versionInfo.EnteredBy = string.Format(@"{0}\{1}",
                                                  Environment.UserDomainName,
                                                  Environment.UserName);

            versionInfo.EntryDate = DateTime.Now;

            using (var connection = _configuration.GetConnection())
            {
                var id = connection.Insert(versionInfo);
                if (versionInfo.Id == 0)
                {
                    versionInfo.Id = id;
                }
            }

            return(versionInfo);
        }
Пример #5
0
        private string GetDatabaseVersion()
        {
            var statement = string.Format("select top 1 v.* from [{0}] v order by id desc",
                                          VersionInfo.GetTableName());

            using (var connection = _configuration.GetConnection())
            {
                var max = connection.Query <VersionInfo>(statement).FirstOrDefault();
                if (max == null)
                {
                    return(string.Empty);
                }
                else
                {
                    return(max.Version);
                }
            }
        }
Пример #6
0
        private string GetCurrentVersionNumber()
        {
            var statement = string.Format("select top 1 v.* from [{0}] v order by id desc",
                                          VersionInfo.GetTableName());

            using (var connection = _configuration.GetConnection())
            {
                var version = connection.Query <VersionInfo>(statement)
                              .FirstOrDefault();

                if (version == null)
                {
                    return("0");
                }
                else
                {
                    return(version.Version);
                }
            }
        }