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); } }
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); }
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."); }