diff --git a/.run/Development Database.run.xml b/.run/Development Database.run.xml
new file mode 100644
index 00000000..12a3e5fe
--- /dev/null
+++ b/.run/Development Database.run.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs
new file mode 100644
index 00000000..25ba5bbd
--- /dev/null
+++ b/ProjectLighthouse/Database.cs
@@ -0,0 +1,12 @@
+using System;
+using Microsoft.EntityFrameworkCore;
+using ProjectLighthouse.Types;
+
+namespace ProjectLighthouse {
+ public class Database : DbContext {
+ protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseMySql(
+ ServerSettings.DbConnectionString,
+ MySqlServerVersion.LatestSupportedServerVersion
+ );
+ }
+}
\ No newline at end of file
diff --git a/ProjectLighthouse/Program.cs b/ProjectLighthouse/Program.cs
index a7d7791b..3da6c5f2 100644
--- a/ProjectLighthouse/Program.cs
+++ b/ProjectLighthouse/Program.cs
@@ -6,10 +6,14 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
+using ProjectLighthouse.Types;
namespace ProjectLighthouse {
- public class Program {
+ public static class Program {
public static void Main(string[] args) {
+ Console.WriteLine("Welcome to Project Lighthouse!");
+ Console.WriteLine(ServerSettings.DbConnected ? "Connected to the database." : "Database unavailable. Starting in stateless mode.");
+
CreateHostBuilder(args).Build().Run();
}
diff --git a/ProjectLighthouse/ProjectLighthouse.csproj b/ProjectLighthouse/ProjectLighthouse.csproj
index c33c9b6b..e2d21a43 100644
--- a/ProjectLighthouse/ProjectLighthouse.csproj
+++ b/ProjectLighthouse/ProjectLighthouse.csproj
@@ -6,6 +6,8 @@
+
+
diff --git a/ProjectLighthouse/Properties/launchSettings.json b/ProjectLighthouse/Properties/launchSettings.json
index dd129793..d5772d10 100644
--- a/ProjectLighthouse/Properties/launchSettings.json
+++ b/ProjectLighthouse/Properties/launchSettings.json
@@ -20,7 +20,8 @@
"dotnetRunMessages": "true",
"applicationUrl": "http://localhost:10060;https://localhost:10061",
"environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "LIGHTHOUSE_DB_CONNECTION_STRING": "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse"
}
}
}
diff --git a/ProjectLighthouse/Types/ServerSettings.cs b/ProjectLighthouse/Types/ServerSettings.cs
index bf045e2d..0f5de5fa 100644
--- a/ProjectLighthouse/Types/ServerSettings.cs
+++ b/ProjectLighthouse/Types/ServerSettings.cs
@@ -1,10 +1,34 @@
+#nullable enable
+using System;
+
namespace ProjectLighthouse.Types {
public static class ServerSettings {
///
/// The maximum amount of slots allowed on users' earth
///
- public static int EntitledSlots = 20;
+ public const int EntitledSlots = 20;
- public static int ListsQuota = 20;
+ public const int ListsQuota = 20;
+
+ private static string? dbConnectionString;
+ public static string DbConnectionString {
+ get {
+ if(dbConnectionString == null) {
+ return dbConnectionString = Environment.GetEnvironmentVariable("LIGHTHOUSE_DB_CONNECTION_STRING") ?? "";
+ };
+ return dbConnectionString;
+ }
+ }
+
+ public static bool DbConnected {
+ get {
+ try {
+ return new Database().Database.CanConnect();
+ }
+ catch {
+ return false;
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..973902f2
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,19 @@
+# MySQL Docker compose file for development purposes. DO NOT USE IN PRODUCTION!
+
+version: '3'
+
+services:
+ lighthouse-db:
+ image: mysql
+ environment:
+ MYSQL_DATABASE: 'lighthouse'
+ MYSQL_ROOT_PASSWORD: 'lighthouse'
+ ports:
+ - '3306:3306'
+ expose:
+ - '3306' # Expose port to localhost:3306
+ volumes:
+ - lighthouse-db:/var/lib/mysql
+
+volumes:
+ lighthouse-db:
\ No newline at end of file