예제 #1
0
파일: Program.cs 프로젝트: WillPK/SqlDeploy
        private static void ProcessScript(KeyValuePair <int, FileInfo> sqlScript)
        {
            var fileName = sqlScript.Value.Name;

            try
            {
                // load
                var script = File.ReadAllText(sqlScript.Value.FullName);

                if (string.IsNullOrEmpty(script))
                {
                    throw new ApplicationException("Script is empty");
                }

                // run
                SqlCommandExecutor.ExecuteNonQuery(script);

                // add version
                VersionTableManager.InsertVersion(sqlScript.Key);

                Console.WriteLine($"Ran script successfully: '{fileName}'");
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Failed to run: '{fileName}'", ex);
            }
        }
예제 #2
0
        public void InsertVersion(int version)
        {
            var versionParam = new SqlParameter("@Version", SqlDbType.BigInt)
            {
                Value = version
            };

            var dateParam = new SqlParameter("@Date", SqlDbType.DateTime)
            {
                Value = DateTime.UtcNow
            };

            SqlCommandExecutor.ExecuteNonQuery(sqlScripts.Insert, versionParam, dateParam);
        }
예제 #3
0
        public void EnsureExists()
        {
            if (Exists())
            {
                Console.WriteLine("Version table exists.");
                return;
            }

            Console.WriteLine("Version table does not exists, creating...");

            SqlCommandExecutor.ExecuteNonQuery(sqlScripts.Create);

            Console.WriteLine("Created the version table successfully.");
        }