Merge branch 'master' of https://github.com/Swarmops/Swarmops
This commit is contained in:
Generated
+20
@@ -315,6 +315,26 @@ namespace Swarmops.Logic.App_GlobalResources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Swarmops Backend [SwarmopsVersion] on host [HostName] has successfully upgraded the Swarmops database schema to revision [DbVersion].
|
||||
///
|
||||
///This is for information only. You do not need to take action..
|
||||
/// </summary>
|
||||
internal static string System_DatabaseSchemaUpgraded_Body {
|
||||
get {
|
||||
return ResourceManager.GetString("System_DatabaseSchemaUpgraded_Body", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Swarmops database upgraded.
|
||||
/// </summary>
|
||||
internal static string System_DatabaseSchemaUpgraded_Subject {
|
||||
get {
|
||||
return ResourceManager.GetString("System_DatabaseSchemaUpgraded_Subject", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An unhandled exception was thrown in Swarmops:
|
||||
///
|
||||
|
||||
@@ -222,6 +222,14 @@ Please log on to Swarmops at [SystemUrl] to confirm or reject them.</value>
|
||||
<data name="Receipts_Filed_Subject" xml:space="preserve">
|
||||
<value>(ACTION ITEM) [OrganizationName] Receipts Filed - Validation Needed</value>
|
||||
</data>
|
||||
<data name="System_DatabaseSchemaUpgraded_Body" xml:space="preserve">
|
||||
<value>Swarmops Backend [SwarmopsVersion] on host [HostName] has successfully upgraded the Swarmops database schema to revision [DbVersion].
|
||||
|
||||
This is for information only. You do not need to take action.</value>
|
||||
</data>
|
||||
<data name="System_DatabaseSchemaUpgraded_Subject" xml:space="preserve">
|
||||
<value>Swarmops database upgraded</value>
|
||||
</data>
|
||||
<data name="System_Exception_Body" xml:space="preserve">
|
||||
<value>An unhandled exception was thrown in Swarmops:
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ namespace Swarmops.Logic.Communications.Transmission
|
||||
Unknown = 0,
|
||||
System_Startup,
|
||||
System_Exception,
|
||||
System_DatabaseSchemaUpgraded,
|
||||
CashAdvance_Requested,
|
||||
CashAdvance_Attested,
|
||||
CashAdvance_Deattested,
|
||||
|
||||
@@ -5,6 +5,9 @@ using System.Net;
|
||||
using System.Text;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using Swarmops.Database;
|
||||
using System.Globalization;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
|
||||
namespace Swarmops.Logic.Support
|
||||
{
|
||||
@@ -38,7 +41,7 @@ namespace Swarmops.Logic.Support
|
||||
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
sql = client.DownloadString("http://packages.swarmops.com/schemas/initialize.sql"); // Hardcoded as security measure - don't want to pass arbitrary sql in from web layer
|
||||
sql = client.DownloadString("http://packages.swarmops.com/schemata/initialize.sql"); // Hardcoded as security measure - don't want to pass arbitrary sql in from web layer
|
||||
}
|
||||
|
||||
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.)
|
||||
@@ -50,5 +53,40 @@ namespace Swarmops.Logic.Support
|
||||
|
||||
SwarmDb.GetDatabaseForWriting().SetKeyValue("DbVersion", "1"); // We're at baseline
|
||||
}
|
||||
|
||||
static public void UpgradeSchemata()
|
||||
{
|
||||
int currentDbVersion = Int32.Parse(SwarmDb.GetDatabaseForReading().GetKeyValue("DbVersion"));
|
||||
int expectedDbVersion = SwarmDb.DbVersion;
|
||||
string sql;
|
||||
bool upgraded = false;
|
||||
|
||||
while (currentDbVersion < expectedDbVersion)
|
||||
{
|
||||
currentDbVersion++;
|
||||
|
||||
string fileName = String.Format("http://packages.swarmops.com/schemata/upgrade-{0:D4}.sql", currentDbVersion);
|
||||
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
sql = client.DownloadString(fileName);
|
||||
}
|
||||
|
||||
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.)
|
||||
|
||||
foreach (string sqlCommand in sqlCommands)
|
||||
{
|
||||
SwarmDb.GetDatabaseForAdmin().ExecuteAdminCommand(sqlCommand.Trim());
|
||||
}
|
||||
|
||||
upgraded = true;
|
||||
SwarmDb.GetDatabaseForWriting().SetKeyValue("DbVersion", currentDbVersion.ToString(CultureInfo.InvariantCulture)); // Increment after each successful run
|
||||
}
|
||||
|
||||
if (upgraded)
|
||||
{
|
||||
OutboundComm.CreateNotification(null, NotificationResource.System_DatabaseSchemaUpgraded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user