Added some debugging code for db upgrades
This commit is contained in:
+4
-4
@@ -25,6 +25,10 @@ namespace Swarmops.Backend
|
||||
|
||||
private static void Main (string[] args)
|
||||
{
|
||||
// Checking for schemata upgrade first of all
|
||||
|
||||
DatabaseMaintenance.UpgradeSchemata();
|
||||
|
||||
testMode = false;
|
||||
|
||||
UnixSignal[] killSignals = null;
|
||||
@@ -154,10 +158,6 @@ namespace Swarmops.Backend
|
||||
|
||||
Console.WriteLine (" * Swarmops Backend starting");
|
||||
|
||||
// Checking for schemata upgrade first of all
|
||||
|
||||
DatabaseMaintenance.UpgradeSchemata();
|
||||
|
||||
BotLog.Write(0, "MainCycle", "Backend STARTING");
|
||||
|
||||
OutboundComm.CreateNotification (null, NotificationResource.System_Startup);
|
||||
|
||||
@@ -64,10 +64,17 @@ namespace Swarmops.Logic.Support
|
||||
string sql;
|
||||
bool upgraded = false;
|
||||
|
||||
if (currentDbVersion < expectedDbVersion)
|
||||
{
|
||||
Console.WriteLine("Swarmops: Current DB version is {0}, but expected is {1}. A schema upgrade will take place.", currentDbVersion, expectedDbVersion);
|
||||
}
|
||||
|
||||
while (currentDbVersion < expectedDbVersion)
|
||||
{
|
||||
currentDbVersion++;
|
||||
|
||||
Console.Write("Schema {0} diff: Fetching...", currentDbVersion);
|
||||
|
||||
string fileName = String.Format ("http://packages.swarmops.com/schemata/upgrade-{0:D4}.sql",
|
||||
currentDbVersion);
|
||||
|
||||
@@ -81,6 +88,7 @@ namespace Swarmops.Logic.Support
|
||||
catch (Exception)
|
||||
{
|
||||
OutboundComm.CreateNotification (null, NotificationResource.System_DatabaseUpgradeFailed);
|
||||
Console.WriteLine(" FAILED! Aborting.");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -88,6 +96,8 @@ namespace Swarmops.Logic.Support
|
||||
string[] sqlCommands = sql.Split ('#');
|
||||
// in the file, the commands are split by a single # sign. (Semicolons are an integral part of storedprocs, so they can't be used.)
|
||||
|
||||
Console.Write(" applying...");
|
||||
|
||||
foreach (string sqlCommand in sqlCommands)
|
||||
{
|
||||
try
|
||||
@@ -101,6 +111,7 @@ namespace Swarmops.Logic.Support
|
||||
new Exception (string.Format ("Exception upgrading to Db{0:D4}", currentDbVersion),
|
||||
exception));
|
||||
|
||||
Console.Write(" EXCEPTION (see log)!");
|
||||
// Continue processing after logging error.
|
||||
// TODO: Throw and abort? Tricky decision
|
||||
}
|
||||
@@ -110,10 +121,13 @@ namespace Swarmops.Logic.Support
|
||||
SwarmDb.GetDatabaseForWriting()
|
||||
.SetKeyValue ("DbVersion", currentDbVersion.ToString (CultureInfo.InvariantCulture));
|
||||
// Increment after each successful run
|
||||
|
||||
Console.WriteLine(" done.");
|
||||
}
|
||||
|
||||
if (upgraded)
|
||||
{
|
||||
Console.WriteLine("Swarmops database schema upgrade completed.\r\n");
|
||||
try
|
||||
{
|
||||
OutboundComm.CreateNotification (null, NotificationResource.System_DatabaseSchemaUpgraded);
|
||||
|
||||
Reference in New Issue
Block a user