fix: database upgrade and added basic timer
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace gaseous_tools
|
||||
@@ -84,10 +85,44 @@ namespace gaseous_tools
|
||||
File.WriteAllText(ConfigurationFilePath, configRaw);
|
||||
}
|
||||
|
||||
private static string ReadSetting(string SettingName, string DefaultValue)
|
||||
{
|
||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string sql = "SELECT * FROM settings WHERE setting = @settingname";
|
||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("settingname", SettingName);
|
||||
dbDict.Add("value", DefaultValue);
|
||||
|
||||
DataTable dbResponse = db.ExecuteCMD(sql, dbDict);
|
||||
if (dbResponse.Rows.Count == 0)
|
||||
{
|
||||
// no value with that name stored - respond with the default value
|
||||
return DefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (string)dbResponse.Rows[0][0];
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetSetting(string SettingName, string Value)
|
||||
{
|
||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string sql = "REPLACE INTO settings (setting, value) VALUES (@settingname, @value)";
|
||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("settingname", SettingName);
|
||||
dbDict.Add("value", Value);
|
||||
|
||||
db.ExecuteCMD(sql, dbDict);
|
||||
}
|
||||
|
||||
public class ConfigFile
|
||||
{
|
||||
public Database DatabaseConfiguration = new Database();
|
||||
|
||||
[JsonIgnore]
|
||||
public Library LibraryConfiguration = new Library();
|
||||
|
||||
public class Database
|
||||
{
|
||||
public string HostName = "localhost";
|
||||
@@ -106,6 +141,45 @@ namespace gaseous_tools
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Library
|
||||
{
|
||||
public string LibraryRootDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return ReadSetting("LibraryRootDirectory", Path.Combine(Config.ConfigurationPath, "Data"));
|
||||
}
|
||||
set
|
||||
{
|
||||
SetSetting("LibraryRootDirectory", value);
|
||||
}
|
||||
}
|
||||
|
||||
public string LibraryUploadDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(LibraryRootDirectory, "Upload");
|
||||
}
|
||||
}
|
||||
|
||||
public string LibraryImportDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(LibraryRootDirectory, "Import");
|
||||
}
|
||||
}
|
||||
|
||||
public string LibraryDataDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(LibraryRootDirectory, "Library");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -91,6 +91,7 @@ namespace gaseous_tools
|
||||
|
||||
// apply script
|
||||
sql = "SELECT schema_version FROM schema_version;";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
DataTable SchemaVersion = ExecuteCMD(sql, dbDict);
|
||||
if (SchemaVersion.Rows.Count == 0)
|
||||
{
|
||||
@@ -106,6 +107,7 @@ namespace gaseous_tools
|
||||
ExecuteCMD(dbScript, dbDict);
|
||||
|
||||
sql = "UPDATE schema_version SET schema_version=@schemaver";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("schemaver", i);
|
||||
ExecuteCMD(sql, dbDict);
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ CREATE TABLE `signatures_games` (
|
||||
KEY `ingest_idx` (`name`,`year`,`publisherid`,`systemid`,`country`,`language`) USING BTREE,
|
||||
CONSTRAINT `publisher` FOREIGN KEY (`publisherid`) REFERENCES `signatures_publishers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `system` FOREIGN KEY (`systemid`) REFERENCES `signatures_platforms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1466355 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -58,7 +58,7 @@ CREATE TABLE `signatures_platforms` (
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `idsignatures_platforms_UNIQUE` (`id`),
|
||||
KEY `platforms_idx` (`platform`,`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1231 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -74,7 +74,7 @@ CREATE TABLE `signatures_publishers` (
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `publisher_idx` (`publisher`,`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=97693 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -104,7 +104,7 @@ CREATE TABLE `signatures_roms` (
|
||||
KEY `sha1_idx` (`sha1`) USING BTREE,
|
||||
KEY `flags_idx` ((cast(`flags` as char(255) array))),
|
||||
CONSTRAINT `gameid` FOREIGN KEY (`gameid`) REFERENCES `signatures_games` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3350963 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -131,7 +131,7 @@ CREATE TABLE `signatures_sources` (
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `sourcemd5_idx` (`sourcemd5`,`id`) USING BTREE,
|
||||
KEY `sourcesha1_idx` (`sourcesha1`,`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=7573 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
|
@@ -1,8 +1,4 @@
|
||||
CREATE
|
||||
ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `view_signatures_games` AS
|
||||
CREATE VIEW `view_signatures_games` AS
|
||||
SELECT
|
||||
`signatures_games`.`id` AS `id`,
|
||||
`signatures_games`.`name` AS `name`,
|
||||
|
6
gaseous-tools/Database/MySQL/gaseous-1002.sql
Normal file
6
gaseous-tools/Database/MySQL/gaseous-1002.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE `gaseous`.`settings` (
|
||||
`setting` VARCHAR(45) NOT NULL,
|
||||
`value` LONGTEXT NULL,
|
||||
UNIQUE INDEX `setting_UNIQUE` (`setting` ASC) VISIBLE,
|
||||
PRIMARY KEY (`setting`));
|
||||
|
@@ -16,6 +16,7 @@
|
||||
<None Remove="Database\MySQL\" />
|
||||
<None Remove="Database\MySQL\gaseous-1000.sql" />
|
||||
<None Remove="Database\MySQL\gaseous-1001.sql" />
|
||||
<None Remove="Database\MySQL\gaseous-1002.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Database\" />
|
||||
@@ -24,5 +25,6 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Database\MySQL\gaseous-1000.sql" />
|
||||
<EmbeddedResource Include="Database\MySQL\gaseous-1001.sql" />
|
||||
<EmbeddedResource Include="Database\MySQL\gaseous-1002.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user