public int CompareTo(IndexItem other) { var file = _fileNameComparer.Compare(File, other.File); var member = _fileNameComparer.Compare(Member, other.Member); var position = Position.CompareTo(other.Position); if (file != 0) { return(file); } else if (member != 0) { return(member); } else { return(position); } }
//--------------------------------------------------------------------------------------------------------------------- /// <summary>Runs the latest database cleanup scripts corresponding to the last upgrades for this software item.</summary> public virtual bool Cleanup() { if (Tool.LastFailurePhase > ProcessPhaseType.Cleanup) { return(false); } if (Tool.LastFailurePhase == ProcessPhaseType.Cleanup && !Tool.AfterFailureCheckpoint) { return(false); } bool isFailureItem = Tool.LastFailurePhase == ProcessPhaseType.Cleanup && this == Tool.LastFailureItem; string dir = String.Format("{0}{1}db", BaseDir, Path.DirectorySeparatorChar); if (!Directory.Exists(dir)) { return(false); } string[] files = Directory.GetFiles(dir, "db-*c.sql"); Array.Sort(files, new FileNameComparer()); int count = 0; foreach (string file in files) { Match match = Regex.Match(file, @"db-([\d\.]+)c\.sql$"); if (!match.Success) { continue; } string currentFileVersion = match.Groups[1].Value; // Process file only if current file version is greater than last CleanupVersion, otherwise skip file if (FileNameComparer.Compare(currentFileVersion, CleanupVersion) <= 0 && (!isFailureItem || currentFileVersion != Tool.LastFailureItemVersion)) { continue; } // Skip if current file is beyond Version if (FileNameComparer.Compare(currentFileVersion, Version) > 0) { continue; } CleanupVersion = currentFileVersion; Tool.WriteSeparator(); if (Tool.Interactive) { Console.WriteLine("Run {0} cleanup for version {1}{2}\n({3}):", ItemsCaption, CleanupVersion, isFailureItem && !Tool.AfterFailureCheckpoint ? String.Format(" (recovering from {0})", Tool.CheckpointText) : String.Empty, file); } Tool.ExecuteSqlScript(file, this); RegisterCleanupVersion(); count++; } return(count != 0); }
//--------------------------------------------------------------------------------------------------------------------- /// <summary>Runs the latest database upgrade scripts for this software item.</summary> public virtual bool Upgrade() { if (Tool.LastFailurePhase > ProcessPhaseType.InstallAndUpgrade) { return(false); } if (Tool.LastFailurePhase == ProcessPhaseType.InstallAndUpgrade && !Tool.AfterFailureCheckpoint && this != Tool.LastFailureItem) { return(false); } bool isFailureItem = Tool.LastFailurePhase == ProcessPhaseType.InstallAndUpgrade && this == Tool.LastFailureItem; string dir = String.Format("{0}{1}db", BaseDir, Path.DirectorySeparatorChar); if (!Directory.Exists(dir)) { return(false); } List <string> files = new List <string>(Directory.GetFiles(dir, "db-*#.sql")); files.Sort(new FileNameComparer()); int count = 0; // Execute only scripts with version > PreviousVersion or, in case of failure in the previous run for the current, item foreach (string file in files) { Match match = Regex.Match(file, @"db-([\d\.]+)#\.sql$"); if (!match.Success) { continue; } string currentFileVersion = match.Groups[1].Value; if (FileNameComparer.Compare(currentFileVersion, Version) <= 0 && (!isFailureItem || currentFileVersion != Tool.LastFailureItemVersion)) { continue; } if (isFailureItem && Tool.AfterFailureCheckpoint) { continue; } Version = currentFileVersion; Tool.WriteSeparator(); if (Tool.Interactive) { Console.WriteLine("Upgrade {0} to version {1}{2}\n({3}):", ItemsCaption, Version, isFailureItem && !Tool.AfterFailureCheckpoint ? String.Format(" (recovering from {0})", Tool.CheckpointText) : String.Empty, file); } Tool.ExecuteSqlScript(file, this); RegisterVersion(); count++; if (isFailureItem) { break; } } return(count != 0); }