/// <summary> /// Checks that the the <see cref="ScriptInformation"/> is valid. /// </summary> /// <param name="info">The info.</param> /// <exception cref="ParachuteException">Aborting. Incorrect Configuration.</exception> private void InformationChecks(ScriptInformation info) { if (info == null) { TraceHelper.Error("Configuration file '{0}' could not be parsed. See example files in GitHub Wiki.", FileName); throw new ParachuteException("Aborting. Incorrect Configuration."); } if (info.ScriptLocations.Count < 0) { TraceHelper.Error("Configuration file '{0}' contains no <scriptLocation> elements.", FileName); throw new ParachuteException("Aborting. Incorrect Configuration."); } if (info.ScriptLocations.Count(l => l.ContainsSchemaScripts) > 1) { TraceHelper.Error("Configuration file '{0}' contains more than one <scriptLocation> with containsSchemaScripts=\"true\".", FileName); throw new ParachuteException("Aborting. Incorrect Configuration."); } }
public void Can_Serialize_ScriptInformation() { var xns = new XmlSerializerNamespaces(); xns.Add("", ""); var v = new Variable { Key = "var1", DefaultValue = "somestring" }; var s = new Script { ScriptName = "test" }; s.Variables.Add(v); var sl = new ScriptLocation { Path = "..\\Some\\Path", Recursive = false, RunOnce = true, ContainsSchemaScripts = true }; sl.Scripts.Add(s); var si = new ScriptInformation(); si.ScriptLocations.Add(sl); si.ScriptLocations.Add(sl); si.ScriptLocations.Add(sl); var xs = new XmlSerializer(typeof(ScriptInformation)); var sb = new StringBuilder(); var sw = new StringWriter(sb); xs.Serialize(sw, si, xns); Debug.WriteLine(sb.ToString()); Assert.AreEqual(strScriptInformationXml, sb.ToString()); }
private void ApplyScriptsToDatabase(SchemaVersion currentVersion, ScriptInformation scriptInfo) { foreach (var location in scriptInfo.ScriptLocations.Where(sl => !sl.ContainsSchemaScripts)) { TraceHelper.Info("Applying Change Scripts In '{0}'", location.Path); TraceHelper.Info("\tRunOnce: '{0}'", location.RunOnce); TraceHelper.Info("\tRecursive: '{0}'", location.Recursive); ApplyScriptsToDatabaseRecursiveDirectoryWalk(currentVersion, location, location.AbsolutePath); } }
private SchemaVersion ApplySchemaChangesToDatabase(SchemaVersion currentVersion, ScriptInformation scriptInfo) { //Query the ScriptInfo Collection & Pull the Script Location for the Schema Directory... var schemaScriptLocation = scriptInfo.ScriptLocations.FirstOrDefault(fd => fd.ContainsSchemaScripts); //If there is one. //Pass that Off for processing. if (schemaScriptLocation != null) { //Ensure the scripts are ordered alphanumerically ascending foreach (var scriptFile in schemaScriptLocation.ScriptFiles.OrderBy(s => s)) { var fileSchemaVersion = scriptFile.ToSchemaVersion(); if (fileSchemaVersion > currentVersion) { var scriptNameToBeLogged = scriptFile.Replace(schemaScriptLocation.AbsolutePath, string.Empty); //If the file's schema version is greater than the currentVersion, TraceHelper.Info("Applying Schema Change '{0}'", scriptNameToBeLogged); var scripts = IOManager.ReadSqlScripts(scriptFile); SqlManager.ExecuteSchemaFile(scripts, scriptNameToBeLogged, fileSchemaVersion); //Set that to be our new Current Version. currentVersion = fileSchemaVersion; } else { TraceHelper.Verbose("Skipping '{0}' - Current Version is '{1}'", scriptFile, currentVersion); } } } //Return the new "Current" Schema Version return currentVersion; }