mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 08:28:39 +00:00
Add database support
This commit is contained in:
parent
f7c4f09fc7
commit
b3532fa57d
7 changed files with 77 additions and 4 deletions
11
.run/Development Database.run.xml
Normal file
11
.run/Development Database.run.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Development Database" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
|
||||||
|
<deployment type="docker-compose.yml">
|
||||||
|
<settings>
|
||||||
|
<option name="envFilePath" value="" />
|
||||||
|
<option name="sourceFilePath" value="docker-compose.yml" />
|
||||||
|
</settings>
|
||||||
|
</deployment>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
12
ProjectLighthouse/Database.cs
Normal file
12
ProjectLighthouse/Database.cs
Normal file
|
@ -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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,10 +6,14 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ProjectLighthouse.Types;
|
||||||
|
|
||||||
namespace ProjectLighthouse {
|
namespace ProjectLighthouse {
|
||||||
public class Program {
|
public static class Program {
|
||||||
public static void Main(string[] args) {
|
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();
|
CreateHostBuilder(args).Build().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.10" />
|
||||||
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
"dotnetRunMessages": "true",
|
"dotnetRunMessages": "true",
|
||||||
"applicationUrl": "http://localhost:10060;https://localhost:10061",
|
"applicationUrl": "http://localhost:10060;https://localhost:10061",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"LIGHTHOUSE_DB_CONNECTION_STRING": "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,34 @@
|
||||||
|
#nullable enable
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace ProjectLighthouse.Types {
|
namespace ProjectLighthouse.Types {
|
||||||
public static class ServerSettings {
|
public static class ServerSettings {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum amount of slots allowed on users' earth
|
/// The maximum amount of slots allowed on users' earth
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
19
docker-compose.yml
Normal file
19
docker-compose.yml
Normal file
|
@ -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:
|
Loading…
Add table
Add a link
Reference in a new issue