Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions src/mindtouch.db/updateDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ static int Main(string[] args) {

// If there are no custom methods specified we need a version number
if(customMethod == null) {
CheckArg(targetVersion, "No version specified");
CheckArg(dbname, "No Database was specified");
}

Expand Down Expand Up @@ -220,34 +219,32 @@ private static void RunUpdate(MysqlDataUpdater site, Assembly dllAssembly, strin
}

// Execute update methods
if(targetVersion != null) {
site.LoadMethods(dllAssembly);
List<string> methods;
if(checkdb) {
methods = site.GetDataIntegrityMethods();
} else {
methods = site.GetMethods();
}
site.LoadMethods(dllAssembly);
List<string> methods;
if(checkdb) {
methods = site.GetDataIntegrityMethods();
} else {
methods = site.GetMethods();
}

// Execute each method
foreach(var method in methods) {
if(verbose) {
Console.WriteLine(String.Format("Executing method: {0}", method));
// Execute each method
foreach(var method in methods) {
if(verbose) {
Console.WriteLine(String.Format("Executing method: {0}", method));
}
if(!dryrun) {
try { site.TestConnection(); } catch(Exception) {
System.Threading.Thread.Sleep(5000);
site.TestConnection();
}
if(!dryrun) {
try { site.TestConnection(); } catch(Exception) {
System.Threading.Thread.Sleep(5000);
site.TestConnection();
}
try {
site.ExecuteMethod(method);
} catch(Exception ex) {
Console.WriteLine(string.Format("\n --- Error occured in method {0}: \n\n{1}", method, ex.StackTrace));
if(checkdb) {
continue;
} else {
break;
}
try {
site.ExecuteMethod(method);
} catch(Exception ex) {
Console.WriteLine(string.Format("\n --- Error occured in method {0}: \n\n{1}", method, ex.StackTrace));
if(checkdb) {
continue;
} else {
break;
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/mindtouch.dream/Data/ADataUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ public abstract class ADataUpdater : IDataUpdater {
/// <returns> The string representation of the target version</returns>
public string TargetVersion {
get {
if(_targetVersion == null) {
return "";
}
return _targetVersion.ToString();
return _targetVersion == null ? "" : _targetVersion.ToString();
}
set {
_targetVersion = new VersionInfo(value);
Expand All @@ -115,10 +112,7 @@ public string TargetVersion {
/// <returns> The string representation of the source version</returns>
public string SourceVersion {
get {
if(_sourceVersion == null) {
return "";
}
return _sourceVersion.ToString();
return _sourceVersion == null ? "" : _sourceVersion.ToString();
}
set {
_sourceVersion = new VersionInfo(value);
Expand Down Expand Up @@ -171,11 +165,6 @@ public List<string> GetDataIntegrityMethods() {
/// <returns></returns>
public virtual void LoadMethods(Assembly updateAssembly) {

// Make sure we have a defined version
if(_targetVersion == null) {
throw new VersionInfoException(_targetVersion);
}

// get all the members of the Assembly
var types = updateAssembly.GetTypes();

Expand Down Expand Up @@ -205,7 +194,7 @@ public virtual void LoadMethods(Assembly updateAssembly) {
} else {
continue;
}
if(version.CompareTo(_targetVersion).Change != VersionChange.Upgrade &&
if( (_targetVersion == null || version.CompareTo(_targetVersion).Change != VersionChange.Upgrade ) &&
(_sourceVersion == null || version.CompareTo(_sourceVersion).Change != VersionChange.Downgrade )) {
_methodList.Add(new DbMethod(methodInfo, version, type));
}
Expand Down
20 changes: 20 additions & 0 deletions src/tests/DreamMisc/DataUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,25 @@ public void get_and_execute_data_integrity_methods() {
}

}

[Test]
public void run_all_methods_without_target_version() {
var types = _testAssembly.GetTypes();
Type dataUpgradeClass = null;
var classTypes = from type in types where type.IsClass select type;
foreach(var type in from type in classTypes from attribute in (from a in System.Attribute.GetCustomAttributes(type) where a is DataUpgradeAttribute select a) select type) {
dataUpgradeClass = type;
}
Assert.IsNotNull(dataUpgradeClass, "Could not read test assembly");
var methods = dataUpgradeClass.GetMethods();
var updateMethodCount = (from m in methods from attributes in (from a in m.GetCustomAttributes(false) where a is EffectiveVersionAttribute select a) select m).Count();
Assert.IsTrue(updateMethodCount > 0, "No upgrade methods found in test assembly");
var dataUpdater = new TestDataUpdater(null);
dataUpdater.LoadMethods(_testAssembly);
foreach(var method in dataUpdater.GetMethods()) {
dataUpdater.ExecuteMethod(method);
}
Assert.AreEqual(updateMethodCount, DummyUpgradeClass.ExecutedMethods.Count, "Not all methods were executed");
}
}
}