Skip to content

Commit

Permalink
Making -v parameter optional
Browse files Browse the repository at this point in the history
  • Loading branch information
yurigorokhov committed Jun 15, 2012
1 parent a060657 commit 116a673
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
51 changes: 24 additions & 27 deletions src/mindtouch.db/updateDb.cs
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/mindtouch.dream/Data/ADataUpdater.cs
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 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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 116a673

Please sign in to comment.