Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Dr96 optional version param #69

Merged
merged 2 commits into from

2 participants

Commits on Jun 15, 2012
  1. @yurigorokhov
  2. @yurigorokhov
This page is out of date. Refresh to see the latest.
View
51 src/mindtouch.db/updateDb.cs
@@ -125,7 +125,6 @@ internal class DBConnection {
// 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");
}
@@ -220,34 +219,32 @@ internal class DBConnection {
}
// 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;
}
}
}
View
17 src/mindtouch.dream/Data/ADataUpdater.cs
@@ -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);
@@ -115,10 +112,7 @@ public abstract class ADataUpdater : IDataUpdater {
/// <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);
@@ -171,11 +165,6 @@ public abstract class ADataUpdater : IDataUpdater {
/// <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();
@@ -205,7 +194,7 @@ public abstract class ADataUpdater : IDataUpdater {
} 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));
}
View
20 src/tests/DreamMisc/DataUpdaterTests.cs
@@ -257,5 +257,25 @@ public class DataUpdaterTests {
}
}
+
+ [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");
+ }
}
}
Something went wrong with that request. Please try again.