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); } }
private bool Exists() { Console.WriteLine($"Version table name is {sqlScripts.VersionTableName}"); var result = SqlCommandExecutor.ExecuteScalar(sqlScripts.CheckExists); if (result == null || result == DBNull.Value) { return(false); } return(true); }
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."); }
public int?GetLastVersion() { var result = SqlCommandExecutor.ExecuteScalar(sqlScripts.GetLatest); if (result == null || result == DBNull.Value) { Console.WriteLine("No existing version number was found."); return(null); } int lastVersion = Convert.ToInt16(result);; Console.WriteLine("Latest version: " + lastVersion); return(lastVersion); }