public DeployExecutor(ScriptStore scriptStore, SchemaHistory schemaHistory, Database database, Clock clock, Feedback feedback) { if (scriptStore == null) { throw new ArgumentNullException("scriptStore"); } if (schemaHistory == null) { throw new ArgumentNullException("schemaHistory"); } if (database == null) { throw new ArgumentNullException("database"); } if (clock == null) { throw new ArgumentNullException("clock"); } if (feedback == null) { throw new ArgumentNullException("feedback"); } this.scriptStore = scriptStore; this.schemaHistory = schemaHistory; this.database = database; this.clock = clock; this.feedback = feedback; }
public Factory(CmdLineArgs args) { if (args == null) { throw new ArgumentNullException("args"); } feedback = new ConsoleFeedback(); clock = new SystemClock(); scriptStore = new DiskScriptStore(args.ScriptLocation); if (!string.Equals(args.DbType, "SqlServer", StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Don't recognise DB type: " + args.DbType); } SqlServerDatabase sqlDatabase = new SqlServerDatabase(args.DbConnectionString); database = sqlDatabase; schemaHistory = sqlDatabase; if (string.Equals("deploy", args.Mode, StringComparison.InvariantCultureIgnoreCase)) { planner = new DeployPlanner(scriptStore, schemaHistory); executor = new DeployExecutor(scriptStore, schemaHistory, database, clock, feedback); } else if (string.Equals("rollback", args.Mode, StringComparison.InvariantCultureIgnoreCase)) { planner = new RollbackPlanner(scriptStore, schemaHistory); executor = new RollbackExecutor(scriptStore, schemaHistory, database, clock, feedback); } else { throw new Exception("Don't recognise mode: " + args.Mode); } }
public RollbackPlanner(ScriptStore scriptStore, SchemaHistory schemaHistory) { if (scriptStore == null) { throw new ArgumentNullException("scriptStore"); } if (schemaHistory == null) { throw new ArgumentNullException("schemaHistory"); } this.scriptStore = scriptStore; this.schemaHistory = schemaHistory; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var currentDir = Path.GetDirectoryName(Application.ExecutablePath) + "\\"; var logsFolder = currentDir + "Logs\\"; try { var scriptsFilePath = ConfigurationManager.AppSettings["ScriptsConfigFilePath"]; if (string.IsNullOrEmpty(Path.GetDirectoryName(scriptsFilePath))) { scriptsFilePath = currentDir + scriptsFilePath; } var runnersFilePath = ConfigurationManager.AppSettings["RunnersConfigFilePath"]; if (string.IsNullOrEmpty(Path.GetDirectoryName(runnersFilePath))) { runnersFilePath = currentDir + runnersFilePath; } ILogger logger = new Logger(logsFolder); IConfigFile <Scripts> scriptsConfig = new ConfigFile <Scripts>(scriptsFilePath); IScriptStore scriptStore = new ScriptStore(scriptsConfig); IConfigFile <Runners> runnersConfig = new ConfigFile <Runners>(runnersFilePath); IScriptRunnerFactory scriptRunner = new ScriptRunnerFactory(runnersConfig); IScriptHubModel model = new ScriptHubModel(scriptStore, logger, scriptRunner); Application.Run(new MainForm(model)); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
/// <summary> /// Scans the manifest resources in the specified assembly for versioned database scripts and puts them in the /// scriptStore. /// </summary> /// <param name="scriptStore">The script store where scanned scripts are stored.</param> /// <param name="assembly">The assembly to scan.</param> /// <remarks> /// For a resource to be considered a valid database script it must be named in the form (y).(t)._(a)._(b)._(c)._(d).(s)-(x).sql /// where /// (y) is any string (can contain dots). /// (t) is one of Create, Update or Finalize. /// (a), (b), (c) and (d) are non-negative integers and represent the script version. NOTE: Leading zeroes are allowed for readability. /// (s) is a non-negative integer and represents the sequence number of the script within the version. /// (x) is a descriptive name of the script and must not contain any dots. /// </remarks> public static void Scan(ScriptStore scriptStore, Assembly assembly) { if (scriptStore == null) { throw new ArgumentNullException("scriptStore"); } if (assembly == null) { throw new ArgumentNullException("assembly"); } foreach (string resourceName in assembly.GetManifestResourceNames()) { Debug.WriteLine(resourceName); var script = CreateScriptFromResourceName(resourceName); if (script != null) { script.ScriptText = LoadScriptText(assembly, resourceName); switch (script.ScriptType) { case ScriptType.Create: scriptStore.CreateScripts.Add(script); break; case ScriptType.Update: scriptStore.UpdateScripts.Add(script); break; case ScriptType.Finalize: scriptStore.FinalizeScripts.Add(script); break; default: throw new NotImplementedException("Implementation missing for ScriptType." + script.ScriptType.ToString()); } } } }