public IEnumerable<DatabaseAction> GetActions(RequestedDatabaseAction requestedDatabaseAction) { if (requestedDatabaseAction == RequestedDatabaseAction.Create) { return new DatabaseAction[] {DatabaseAction.Create, DatabaseAction.Update}; } else if (requestedDatabaseAction == RequestedDatabaseAction.Drop) { return new DatabaseAction[] {DatabaseAction.Drop}; } else if (requestedDatabaseAction == RequestedDatabaseAction.Rebuild) { return new DatabaseAction[] { DatabaseAction.Drop, DatabaseAction.Create, DatabaseAction.Update }; } else if (requestedDatabaseAction == RequestedDatabaseAction.TestData) { return new DatabaseAction[] { DatabaseAction.TestData }; } else if (requestedDatabaseAction == RequestedDatabaseAction.Baseline) { return new DatabaseAction[] { DatabaseAction.Baseline }; } else { return new DatabaseAction[] { DatabaseAction.Update }; } }
public bool UpdateDatabase(ConnectionSettings settings, string scriptDirectory, RequestedDatabaseAction action) { var manager = new SqlDatabaseManager(); var taskAttributes = new TaskAttributes(settings, scriptDirectory) { RequestedDatabaseAction = action, }; try { manager.Upgrade(taskAttributes, this); foreach (var property in _properties) { Log(property.Key +": " + property.Value); } return true; } catch (Exception exception) { var ex = exception; do { Log("Failure: " + ex.Message); ex = ex.InnerException; } while (ex!=null); //Log(exception.ToString()); } return false; }
public IEnumerable <DatabaseAction> GetActions(RequestedDatabaseAction requestedDatabaseAction) { if (requestedDatabaseAction == RequestedDatabaseAction.Create) { return(new DatabaseAction[] { DatabaseAction.Create, DatabaseAction.Update }); } else if (requestedDatabaseAction == RequestedDatabaseAction.Drop) { return(new DatabaseAction[] { DatabaseAction.Drop }); } else if (requestedDatabaseAction == RequestedDatabaseAction.Rebuild) { return(new DatabaseAction[] { DatabaseAction.Drop, DatabaseAction.Create, DatabaseAction.Update }); } else if (requestedDatabaseAction == RequestedDatabaseAction.TestData) { return(new DatabaseAction[] { DatabaseAction.TestData }); } else if (requestedDatabaseAction == RequestedDatabaseAction.Baseline) { return(new DatabaseAction[] { DatabaseAction.Baseline }); } else { return(new DatabaseAction[] { DatabaseAction.Update }); } }
public IEnumerable <IDatabaseActionExecutor> GetExecutors(RequestedDatabaseAction requestedDatabaseAction) { IEnumerable <DatabaseAction> actions = _resolver.GetActions(requestedDatabaseAction); foreach (DatabaseAction action in actions) { IDatabaseActionExecutor instance = _locator.CreateInstance(action); yield return(instance); } }
public IEnumerable<IDatabaseActionExecutor> GetExecutors(RequestedDatabaseAction requestedDatabaseAction) { IEnumerable<DatabaseAction> actions = _resolver.GetActions(requestedDatabaseAction); foreach (DatabaseAction action in actions) { IDatabaseActionExecutor instance = _locator.CreateInstance<IDatabaseActionExecutor>(action.ToString()); yield return instance; } }
/// <summary> /// <para>Runs AliaSQL against a database</para> /// <para>Default action is Update but it can be set to other AliaSQL actions</para> /// <para>Default script directory is ~/App_Data/scripts/ but it can bet set to any physical path</para> /// <para>-If database does not exist it will be created</para> /// <para>-Script directory path must exist</para> /// <para>Returns an object with a success boolean and a result string</para> /// </summary> /// <param name="connectionString"></param> /// <param name="action"></param> /// <param name="scriptDirectory"></param> /// <returns>Returns an object with a success boolean and a result string</returns> public AliaSqlResult UpdateDatabase(string connectionString, RequestedDatabaseAction action = RequestedDatabaseAction.Update, string scriptDirectory = "") { if (scriptDirectory == "") { scriptDirectory = Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "scripts"); } if (!Directory.Exists(scriptDirectory)) { throw new ArgumentException("There are no scripts in the defined data directory."); } if (action == RequestedDatabaseAction.Update && !PendingChanges(connectionString, scriptDirectory).Any()) { return(new AliaSqlResult { Result = "No pending changes", Success = true }); } var result = new AliaSqlResult { Success = true }; var manager = new SqlDatabaseManager(); var taskAttributes = new TaskAttributes(_connectionStringGenerator.GetConnectionSettings(connectionString), scriptDirectory) { RequestedDatabaseAction = action, }; try { manager.Upgrade(taskAttributes, this); foreach (var property in _properties) { Log(property.Key + ": " + property.Value); } result.Result = sb.ToString(); } catch (Exception exception) { result.Success = false; var ex = exception; do { Log("Failure: " + ex.Message); if (ex.Data["Custom"] != null) { Log(ex.Data["Custom"].ToString()); } ex = ex.InnerException; } while (ex != null); } result.Result = sb.ToString(); return(result); }
/// <summary> /// <para>Runs AliaSQL against a database</para> /// <para>Default action is Update but it can be set to other AliaSQL actions</para> /// <para>Default script directory is ~/App_Data/scripts/ but it can bet set to any physical path</para> /// <para>-If database does not exist it will be created</para> /// <para>-Script directory path must exist</para> /// <para>Returns an object with a success boolean and a result string</para> /// </summary> /// <param name="connectionString"></param> /// <param name="action"></param> /// <param name="scriptDirectory"></param> /// <returns>Returns an object with a success boolean and a result string</returns> public AliaSqlResult UpdateDatabase(string connectionString, RequestedDatabaseAction action = RequestedDatabaseAction.Update, string scriptDirectory = "") { if (scriptDirectory == "") { scriptDirectory = Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "scripts"); } if (!Directory.Exists(scriptDirectory)) { throw new ArgumentException("There are no scripts in the defined data directory."); } if (action == RequestedDatabaseAction.Update && !PendingChanges(connectionString, scriptDirectory).Any()) { return new AliaSqlResult { Result = "No pending changes", Success = true }; } var result = new AliaSqlResult { Success = true }; var manager = new SqlDatabaseManager(); var taskAttributes = new TaskAttributes(_connectionStringGenerator.GetConnectionSettings(connectionString), scriptDirectory) { RequestedDatabaseAction = action, }; try { manager.Upgrade(taskAttributes, this); foreach (var property in _properties) { Log(property.Key + ": " + property.Value); } result.Result = sb.ToString(); } catch (Exception exception) { result.Success = false; var ex = exception; do { Log("Failure: " + ex.Message); if (ex.Data["Custom"] != null) Log(ex.Data["Custom"].ToString()); ex = ex.InnerException; } while (ex != null); } result.Result = sb.ToString(); return result; }
private static void Main(string[] args) { System.Console.Title = "AliaSQL Database Deployment Tool"; RequestedDatabaseAction requestedDatabaseAction = RequestedDatabaseAction.Default; if (args.Length > 0) { Enum.TryParse(args[0], true, out requestedDatabaseAction); } if ((args.Length != 4 && args.Length != 6) || requestedDatabaseAction == RequestedDatabaseAction.Default) { InvalidArguments(); return; } ConnectionSettings settings = null; var deployer = new ConsoleAliaSQL(); var action = requestedDatabaseAction; string server = args[1]; string database = args[2]; string scriptDirectory = args[3]; if (args.Length == 4) { settings = new ConnectionSettings(server, database, true, null, null); } else if (args.Length == 6) { string username = args[4]; string password = args[5]; settings = new ConnectionSettings(server, database, false, username, password); } if (deployer.UpdateDatabase(settings, scriptDirectory, action)) { if (Debugger.IsAttached) { System.Console.ReadLine(); } return; } Environment.ExitCode = 1; }
public bool UpdateDatabase(ConnectionSettings settings, string scriptDirectory, RequestedDatabaseAction action) { var manager = new SqlDatabaseManager(); var taskAttributes = new TaskAttributes(settings, scriptDirectory) { RequestedDatabaseAction = action, }; try { manager.Upgrade(taskAttributes, this); foreach (var property in _properties) { Log(property.Key + ": " + property.Value); } return(true); } catch (Exception exception) { var ex = exception; do { Log("Failure: " + ex.Message); if (ex.Data["Custom"] != null) { Log(ex.Data["Custom"].ToString()); } ex = ex.InnerException; } while (ex != null); } if (Debugger.IsAttached) { System.Console.ReadLine(); } return(false); }