Added pre and post db upgrade script support, schema version now visible on the about page (#92)
This commit is contained in:
@@ -244,101 +244,5 @@ namespace gaseous_server.SignatureIngestors.XML
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MigrateMetadatVersion() {
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string sql = "";
|
||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
||||
|
||||
// update signature roms to v2
|
||||
sql = "SELECT Id, Flags, Attributes, IngestorVersion FROM Signatures_Roms WHERE IngestorVersion = 1";
|
||||
DataTable data = db.ExecuteCMD(sql);
|
||||
if (data.Rows.Count > 0)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "Signature Ingestor - Database Update", "Updating " + data.Rows.Count + " database entries");
|
||||
int Counter = 0;
|
||||
int LastCounterCheck = 0;
|
||||
foreach (DataRow row in data.Rows)
|
||||
{
|
||||
List<string> Flags = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>((string)Common.ReturnValueIfNull(row["flags"], "[]"));
|
||||
List<KeyValuePair<string, object>> Attributes = new List<KeyValuePair<string, object>>();
|
||||
foreach (string Flag in Flags)
|
||||
{
|
||||
if (Flag.StartsWith("a"))
|
||||
{
|
||||
Attributes.Add(
|
||||
new KeyValuePair<string, object>(
|
||||
"a",
|
||||
Flag
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] FlagCompare = Flag.Split(' ');
|
||||
switch (FlagCompare[0].Trim().ToLower())
|
||||
{
|
||||
case "cr":
|
||||
// cracked
|
||||
case "f":
|
||||
// fixed
|
||||
case "h":
|
||||
// hacked
|
||||
case "m":
|
||||
// modified
|
||||
case "p":
|
||||
// pirated
|
||||
case "t":
|
||||
// trained
|
||||
case "tr":
|
||||
// translated
|
||||
case "o":
|
||||
// overdump
|
||||
case "u":
|
||||
// underdump
|
||||
case "v":
|
||||
// virus
|
||||
case "b":
|
||||
// bad dump
|
||||
case "a":
|
||||
// alternate
|
||||
case "!":
|
||||
// known verified dump
|
||||
// -------------------
|
||||
string shavedToken = Flag.Substring(FlagCompare[0].Trim().Length).Trim();
|
||||
Attributes.Add(new KeyValuePair<string, object>(
|
||||
FlagCompare[0].Trim().ToLower(),
|
||||
shavedToken
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string AttributesJson;
|
||||
if (Attributes.Count > 0)
|
||||
{
|
||||
AttributesJson = Newtonsoft.Json.JsonConvert.SerializeObject(Attributes);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttributesJson = "[]";
|
||||
}
|
||||
|
||||
string updateSQL = "UPDATE Signatures_Roms SET Attributes=@attributes, IngestorVersion=2 WHERE Id=@id";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("attributes", AttributesJson);
|
||||
dbDict.Add("id", (int)row["Id"]);
|
||||
db.ExecuteCMD(updateSQL, dbDict);
|
||||
|
||||
if ((Counter - LastCounterCheck) > 10)
|
||||
{
|
||||
LastCounterCheck = Counter;
|
||||
Logging.Log(Logging.LogType.Information, "Signature Ingestor - Database Update", "Updating " + Counter + " / " + data.Rows.Count + " database entries");
|
||||
}
|
||||
Counter += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -62,7 +62,9 @@ namespace gaseous_server.Controllers
|
||||
[Route("VersionFile")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public FileContentResult GetSystemVersionAsFile() {
|
||||
string ver = "var AppVersion = \"" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\"";
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string ver = "var AppVersion = \"" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\";" + Environment.NewLine +
|
||||
"var DBSchemaVersion = \"" + db.GetDatabaseSchemaVersion() + "\";";
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(ver);
|
||||
return File(bytes, "text/javascript");
|
||||
}
|
||||
|
@@ -144,10 +144,6 @@ gaseous_server.Classes.Metadata.Platforms.GetPlatform(0);
|
||||
// organise library
|
||||
//gaseous_server.Classes.ImportGame.OrganiseLibrary();
|
||||
|
||||
// Migrate signature data if needed
|
||||
XMLIngestor ingestor = new XMLIngestor();
|
||||
ingestor.MigrateMetadatVersion();
|
||||
|
||||
// add background tasks
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.SignatureIngestor, 60));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
|
||||
|
BIN
gaseous-server/wwwroot/images/ProgettoSnaps.gif
Normal file
BIN
gaseous-server/wwwroot/images/ProgettoSnaps.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 MiB |
@@ -15,6 +15,10 @@
|
||||
<th>Server Version</th>
|
||||
<td id="settings_appversion"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Database Schema Version</th>
|
||||
<td id="settings_dbversion"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<h3>Data Sources</h2>
|
||||
@@ -42,13 +46,20 @@
|
||||
The Old School Emulation Center
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://www.progettosnaps.net/index.php" target="_blank"><img src="/images/ProgettoSnaps.gif" style="height: 36px;" /></a>
|
||||
</td>
|
||||
<td>
|
||||
Progetto-Snaps
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<script type="text/javascript">
|
||||
ajaxCall('/api/v1/System/Version', 'GET', function (result) {
|
||||
if (result) {
|
||||
var versionBox = document.getElementById('settings_appversion');
|
||||
versionBox.innerHTML = result;
|
||||
}
|
||||
});
|
||||
var versionBox = document.getElementById('settings_appversion');
|
||||
versionBox.innerHTML = AppVersion;
|
||||
|
||||
var versionBox = document.getElementById('settings_dbversion');
|
||||
versionBox.innerHTML = DBSchemaVersion;
|
||||
</script>
|
@@ -108,14 +108,20 @@ namespace gaseous_tools
|
||||
Logging.Log(Logging.LogType.Information, "Database", "Schema version is " + SchemaVer);
|
||||
if (SchemaVer < i)
|
||||
{
|
||||
// run pre-upgrade code
|
||||
gaseous_tools.DatabaseMigration.PreUpgradeScript(i, _ConnectorType);
|
||||
|
||||
// apply schema!
|
||||
Logging.Log(Logging.LogType.Information, "Database", "Schema update available - applying");
|
||||
Logging.Log(Logging.LogType.Information, "Database", "Updating schema to version " + i);
|
||||
ExecuteCMD(dbScript, dbDict);
|
||||
|
||||
sql = "UPDATE schema_version SET schema_version=@schemaver";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("schemaver", i);
|
||||
ExecuteCMD(sql, dbDict);
|
||||
|
||||
// run post-upgrade code
|
||||
gaseous_tools.DatabaseMigration.PostUpgradeScript(i, _ConnectorType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,6 +184,28 @@ namespace gaseous_tools
|
||||
}
|
||||
}
|
||||
|
||||
public int GetDatabaseSchemaVersion()
|
||||
{
|
||||
switch (_ConnectorType)
|
||||
{
|
||||
case databaseType.MySql:
|
||||
string sql = "SELECT schema_version FROM schema_version;";
|
||||
DataTable SchemaVersion = ExecuteCMD(sql);
|
||||
if (SchemaVersion.Rows.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)SchemaVersion.Rows[0][0];
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class SQLTransactionItem
|
||||
{
|
||||
public SQLTransactionItem()
|
||||
|
123
gaseous-tools/DatabaseMigration.cs
Normal file
123
gaseous-tools/DatabaseMigration.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace gaseous_tools
|
||||
{
|
||||
public static class DatabaseMigration
|
||||
{
|
||||
public static void PreUpgradeScript(int TargetSchemaVersion, gaseous_tools.Database.databaseType? DatabaseType) {
|
||||
|
||||
}
|
||||
|
||||
public static void PostUpgradeScript(int TargetSchemaVersion, gaseous_tools.Database.databaseType? DatabaseType) {
|
||||
switch(DatabaseType)
|
||||
{
|
||||
case gaseous_tools.Database.databaseType.MySql:
|
||||
switch (TargetSchemaVersion)
|
||||
{
|
||||
case 1002:
|
||||
MySql_1002_MigrateMetadataVersion();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void MySql_1002_MigrateMetadataVersion() {
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string sql = "";
|
||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
||||
|
||||
// update signature roms to v2
|
||||
sql = "SELECT Id, Flags, Attributes, IngestorVersion FROM Signatures_Roms WHERE IngestorVersion = 1";
|
||||
DataTable data = db.ExecuteCMD(sql);
|
||||
if (data.Rows.Count > 0)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "Signature Ingestor - Database Update", "Updating " + data.Rows.Count + " database entries");
|
||||
int Counter = 0;
|
||||
int LastCounterCheck = 0;
|
||||
foreach (DataRow row in data.Rows)
|
||||
{
|
||||
List<string> Flags = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>((string)Common.ReturnValueIfNull(row["flags"], "[]"));
|
||||
List<KeyValuePair<string, object>> Attributes = new List<KeyValuePair<string, object>>();
|
||||
foreach (string Flag in Flags)
|
||||
{
|
||||
if (Flag.StartsWith("a"))
|
||||
{
|
||||
Attributes.Add(
|
||||
new KeyValuePair<string, object>(
|
||||
"a",
|
||||
Flag
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] FlagCompare = Flag.Split(' ');
|
||||
switch (FlagCompare[0].Trim().ToLower())
|
||||
{
|
||||
case "cr":
|
||||
// cracked
|
||||
case "f":
|
||||
// fixed
|
||||
case "h":
|
||||
// hacked
|
||||
case "m":
|
||||
// modified
|
||||
case "p":
|
||||
// pirated
|
||||
case "t":
|
||||
// trained
|
||||
case "tr":
|
||||
// translated
|
||||
case "o":
|
||||
// overdump
|
||||
case "u":
|
||||
// underdump
|
||||
case "v":
|
||||
// virus
|
||||
case "b":
|
||||
// bad dump
|
||||
case "a":
|
||||
// alternate
|
||||
case "!":
|
||||
// known verified dump
|
||||
// -------------------
|
||||
string shavedToken = Flag.Substring(FlagCompare[0].Trim().Length).Trim();
|
||||
Attributes.Add(new KeyValuePair<string, object>(
|
||||
FlagCompare[0].Trim().ToLower(),
|
||||
shavedToken
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string AttributesJson;
|
||||
if (Attributes.Count > 0)
|
||||
{
|
||||
AttributesJson = Newtonsoft.Json.JsonConvert.SerializeObject(Attributes);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttributesJson = "[]";
|
||||
}
|
||||
|
||||
string updateSQL = "UPDATE Signatures_Roms SET Attributes=@attributes, IngestorVersion=2 WHERE Id=@id";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("attributes", AttributesJson);
|
||||
dbDict.Add("id", (int)row["Id"]);
|
||||
db.ExecuteCMD(updateSQL, dbDict);
|
||||
|
||||
if ((Counter - LastCounterCheck) > 10)
|
||||
{
|
||||
LastCounterCheck = Counter;
|
||||
Logging.Log(Logging.LogType.Information, "Signature Ingestor - Database Update", "Updating " + Counter + " / " + data.Rows.Count + " database entries");
|
||||
}
|
||||
Counter += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user