diff --git a/MoonlightServers.ApiServer/Database/Entities/Allocation.cs b/MoonlightServers.ApiServer/Database/Entities/Allocation.cs new file mode 100644 index 0000000..7ec1b38 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/Allocation.cs @@ -0,0 +1,13 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class Allocation +{ + public int Id { get; set; } + + // Relations + public Node Node { get; set; } + public Server? Server { get; set; } + + public string IpAddress { get; set; } + public int Port { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/Node.cs b/MoonlightServers.ApiServer/Database/Entities/Node.cs new file mode 100644 index 0000000..c63aac6 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/Node.cs @@ -0,0 +1,23 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class Node +{ + public int Id { get; set; } + + // Relations + public List Servers { get; set; } = new(); + public List Allocations { get; set; } = new(); + + // Meta + public string Name { get; set; } + + // Connection details + public string Fqdn { get; set; } + public string Token { get; set; } + public int HttpPort { get; set; } + public int FtpPort { get; set; } + + // Misc + public bool EnableTransparentMode { get; set; } + public bool EnableDynamicFirewall { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/Server.cs b/MoonlightServers.ApiServer/Database/Entities/Server.cs new file mode 100644 index 0000000..c25fedf --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/Server.cs @@ -0,0 +1,26 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class Server +{ + public int Id { get; set; } + + // Relations + public Star Star { get; set; } + public Node Node { get; set; } + public List Allocations { get; set; } = new(); + + // Meta + public string Name { get; set; } + public int OwnerId { get; set; } + + // Star specific stuff + public string? StartupOverride { get; set; } + public int DockerImageIndex { get; set; } + + // Resources and limits + public int Cpu { get; set; } + public int Memory { get; set; } + public int Disk { get; set; } + public bool UseVirtualDisk { get; set; } + public int Bandwidth { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/ServerBackup.cs b/MoonlightServers.ApiServer/Database/Entities/ServerBackup.cs new file mode 100644 index 0000000..361d152 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/ServerBackup.cs @@ -0,0 +1,13 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class ServerBackup +{ + public int Id { get; set; } + + public DateTime CreatedAt { get; set; } + public DateTime CompletedAt { get; set; } + + public long Size { get; set; } + public bool Successful { get; set; } + public bool Completed { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/ServerVariable.cs b/MoonlightServers.ApiServer/Database/Entities/ServerVariable.cs new file mode 100644 index 0000000..96cf5f9 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/ServerVariable.cs @@ -0,0 +1,12 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class ServerVariable +{ + public int Id { get; set; } + + // Relations + public Server Server { get; set; } + + public string Key { get; set; } + public string Value { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/Star.cs b/MoonlightServers.ApiServer/Database/Entities/Star.cs new file mode 100644 index 0000000..163c1e7 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/Star.cs @@ -0,0 +1,31 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class Star +{ + public int Id { get; set; } + + // References + public List Variables { get; set; } = new(); + public List DockerImages { get; set; } = new(); + + // Meta + public string Name { get; set; } + public string Author { get; set; } + public string? UpdateUrl { get; set; } + public string? DonateUrl { get; set; } + + // Start and stop + public string StartupCommand { get; set; } + public string StopCommand { get; set; } + public string OnlineDetection { get; set; } + + // Install + public string InstallShell { get; set; } + public string InstallDockerImage { get; set; } + public string InstallScript { get; set; } + + // Misc + public int RequiredAllocations { get; set; } + public bool AllowDockerImageChange { get; set; } + public string ParseConfiguration { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/StarDockerImage.cs b/MoonlightServers.ApiServer/Database/Entities/StarDockerImage.cs new file mode 100644 index 0000000..6d8bc2e --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/StarDockerImage.cs @@ -0,0 +1,11 @@ +namespace MoonlightServers.ApiServer.Database.Entities; + +public class StarDockerImage +{ + public int Id { get; set; } + public Star Star { get; set; } + + public string DisplayName { get; set; } + public string Identifier { get; set; } + public bool AutoPulling { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Entities/StarVariable.cs b/MoonlightServers.ApiServer/Database/Entities/StarVariable.cs new file mode 100644 index 0000000..70552ef --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Entities/StarVariable.cs @@ -0,0 +1,21 @@ +using MoonlightServers.Shared.Enums; + +namespace MoonlightServers.ApiServer.Database.Entities; + +public class StarVariable +{ + public int Id { get; set; } + public Star Star { get; set; } + + public string Name { get; set; } + public string Description { get; set; } + + public string Key { get; set; } + public string DefaultValue { get; set; } + + public bool AllowViewing { get; set; } + public bool AllowEditing { get; set; } + + public StarVariableType Type { get; set; } + public string? Filter { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/Migrations/20241205154432_AddedBaseModels.Designer.cs b/MoonlightServers.ApiServer/Database/Migrations/20241205154432_AddedBaseModels.Designer.cs new file mode 100644 index 0000000..1eacfe9 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/20241205154432_AddedBaseModels.Designer.cs @@ -0,0 +1,427 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MoonlightServers.ApiServer.Database; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + [DbContext(typeof(ServersDataContext))] + [Migration("20241205154432_AddedBaseModels")] + partial class AddedBaseModels + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Servers") + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("IpAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("ServerId"); + + b.ToTable("Allocations", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("EnableDynamicFirewall") + .HasColumnType("tinyint(1)"); + + b.Property("EnableTransparentMode") + .HasColumnType("tinyint(1)"); + + b.Property("Fqdn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FtpPort") + .HasColumnType("int"); + + b.Property("HttpPort") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Token") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Bandwidth") + .HasColumnType("int"); + + b.Property("Cpu") + .HasColumnType("int"); + + b.Property("Disk") + .HasColumnType("int"); + + b.Property("DockerImageIndex") + .HasColumnType("int"); + + b.Property("Memory") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("StartupOverride") + .HasColumnType("longtext"); + + b.Property("UseVirtualDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("StarId"); + + b.ToTable("Servers", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Completed") + .HasColumnType("tinyint(1)"); + + b.Property("CompletedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Size") + .HasColumnType("bigint"); + + b.Property("Successful") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("ServerBackups", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowDockerImageChange") + .HasColumnType("tinyint(1)"); + + b.Property("Author") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DonateUrl") + .HasColumnType("longtext"); + + b.Property("InstallDockerImage") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallScript") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallShell") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OnlineDetection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ParseConfiguration") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RequiredAllocations") + .HasColumnType("int"); + + b.Property("StartupCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StopCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdateUrl") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Stars", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AutoPulling") + .HasColumnType("tinyint(1)"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Identifier") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarDockerImages", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowEditing") + .HasColumnType("tinyint(1)"); + + b.Property("AllowViewing") + .HasColumnType("tinyint(1)"); + + b.Property("DefaultValue") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Filter") + .HasColumnType("longtext"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node") + .WithMany("Allocations") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany("Allocations") + .HasForeignKey("ServerId"); + + b.Navigation("Node"); + + b.Navigation("Server"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node") + .WithMany("Servers") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany() + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Node"); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany() + .HasForeignKey("ServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Server"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany("DockerImages") + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany("Variables") + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Navigation("Allocations"); + + b.Navigation("Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Navigation("Allocations"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MoonlightServers.ApiServer/Database/Migrations/20241205154432_AddedBaseModels.cs b/MoonlightServers.ApiServer/Database/Migrations/20241205154432_AddedBaseModels.cs new file mode 100644 index 0000000..af09afa --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/20241205154432_AddedBaseModels.cs @@ -0,0 +1,342 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + /// + public partial class AddedBaseModels : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "Servers"); + + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Nodes", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Fqdn = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Token = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HttpPort = table.Column(type: "int", nullable: false), + FtpPort = table.Column(type: "int", nullable: false), + EnableTransparentMode = table.Column(type: "tinyint(1)", nullable: false), + EnableDynamicFirewall = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Nodes", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "ServerBackups", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + CompletedAt = table.Column(type: "datetime(6)", nullable: false), + Size = table.Column(type: "bigint", nullable: false), + Successful = table.Column(type: "tinyint(1)", nullable: false), + Completed = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ServerBackups", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Stars", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Author = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + UpdateUrl = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + DonateUrl = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + StartupCommand = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + StopCommand = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + OnlineDetection = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + InstallShell = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + InstallDockerImage = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + InstallScript = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + RequiredAllocations = table.Column(type: "int", nullable: false), + AllowDockerImageChange = table.Column(type: "tinyint(1)", nullable: false), + ParseConfiguration = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Stars", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Servers", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + StarId = table.Column(type: "int", nullable: false), + NodeId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + OwnerId = table.Column(type: "int", nullable: false), + StartupOverride = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + DockerImageIndex = table.Column(type: "int", nullable: false), + Cpu = table.Column(type: "int", nullable: false), + Memory = table.Column(type: "int", nullable: false), + Disk = table.Column(type: "int", nullable: false), + UseVirtualDisk = table.Column(type: "tinyint(1)", nullable: false), + Bandwidth = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Servers", x => x.Id); + table.ForeignKey( + name: "FK_Servers_Nodes_NodeId", + column: x => x.NodeId, + principalSchema: "Servers", + principalTable: "Nodes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Servers_Stars_StarId", + column: x => x.StarId, + principalSchema: "Servers", + principalTable: "Stars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "StarDockerImages", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + StarId = table.Column(type: "int", nullable: false), + DisplayName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Identifier = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AutoPulling = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StarDockerImages", x => x.Id); + table.ForeignKey( + name: "FK_StarDockerImages_Stars_StarId", + column: x => x.StarId, + principalSchema: "Servers", + principalTable: "Stars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "StarVariables", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + StarId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Key = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DefaultValue = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AllowViewing = table.Column(type: "tinyint(1)", nullable: false), + AllowEditing = table.Column(type: "tinyint(1)", nullable: false), + Type = table.Column(type: "int", nullable: false), + Filter = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_StarVariables", x => x.Id); + table.ForeignKey( + name: "FK_StarVariables_Stars_StarId", + column: x => x.StarId, + principalSchema: "Servers", + principalTable: "Stars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Allocations", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + NodeId = table.Column(type: "int", nullable: false), + ServerId = table.Column(type: "int", nullable: true), + IpAddress = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Port = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Allocations", x => x.Id); + table.ForeignKey( + name: "FK_Allocations_Nodes_NodeId", + column: x => x.NodeId, + principalSchema: "Servers", + principalTable: "Nodes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Allocations_Servers_ServerId", + column: x => x.ServerId, + principalSchema: "Servers", + principalTable: "Servers", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "ServerVariables", + schema: "Servers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + ServerId = table.Column(type: "int", nullable: false), + Key = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Value = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_ServerVariables", x => x.Id); + table.ForeignKey( + name: "FK_ServerVariables_Servers_ServerId", + column: x => x.ServerId, + principalSchema: "Servers", + principalTable: "Servers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Allocations_NodeId", + schema: "Servers", + table: "Allocations", + column: "NodeId"); + + migrationBuilder.CreateIndex( + name: "IX_Allocations_ServerId", + schema: "Servers", + table: "Allocations", + column: "ServerId"); + + migrationBuilder.CreateIndex( + name: "IX_Servers_NodeId", + schema: "Servers", + table: "Servers", + column: "NodeId"); + + migrationBuilder.CreateIndex( + name: "IX_Servers_StarId", + schema: "Servers", + table: "Servers", + column: "StarId"); + + migrationBuilder.CreateIndex( + name: "IX_ServerVariables_ServerId", + schema: "Servers", + table: "ServerVariables", + column: "ServerId"); + + migrationBuilder.CreateIndex( + name: "IX_StarDockerImages_StarId", + schema: "Servers", + table: "StarDockerImages", + column: "StarId"); + + migrationBuilder.CreateIndex( + name: "IX_StarVariables_StarId", + schema: "Servers", + table: "StarVariables", + column: "StarId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Allocations", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "ServerBackups", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "ServerVariables", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "StarDockerImages", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "StarVariables", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "Servers", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "Nodes", + schema: "Servers"); + + migrationBuilder.DropTable( + name: "Stars", + schema: "Servers"); + } + } +} diff --git a/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs b/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs new file mode 100644 index 0000000..cedcf20 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/Migrations/ServersDataContextModelSnapshot.cs @@ -0,0 +1,424 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MoonlightServers.ApiServer.Database; + +#nullable disable + +namespace MoonlightServers.ApiServer.Database.Migrations +{ + [DbContext(typeof(ServersDataContext))] + partial class ServersDataContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Servers") + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("IpAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("ServerId"); + + b.ToTable("Allocations", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("EnableDynamicFirewall") + .HasColumnType("tinyint(1)"); + + b.Property("EnableTransparentMode") + .HasColumnType("tinyint(1)"); + + b.Property("Fqdn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FtpPort") + .HasColumnType("int"); + + b.Property("HttpPort") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Token") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Bandwidth") + .HasColumnType("int"); + + b.Property("Cpu") + .HasColumnType("int"); + + b.Property("Disk") + .HasColumnType("int"); + + b.Property("DockerImageIndex") + .HasColumnType("int"); + + b.Property("Memory") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("StartupOverride") + .HasColumnType("longtext"); + + b.Property("UseVirtualDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("StarId"); + + b.ToTable("Servers", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerBackup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Completed") + .HasColumnType("tinyint(1)"); + + b.Property("CompletedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Size") + .HasColumnType("bigint"); + + b.Property("Successful") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("ServerBackups", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowDockerImageChange") + .HasColumnType("tinyint(1)"); + + b.Property("Author") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DonateUrl") + .HasColumnType("longtext"); + + b.Property("InstallDockerImage") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallScript") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallShell") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OnlineDetection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ParseConfiguration") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RequiredAllocations") + .HasColumnType("int"); + + b.Property("StartupCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StopCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdateUrl") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Stars", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AutoPulling") + .HasColumnType("tinyint(1)"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Identifier") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarDockerImages", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AllowEditing") + .HasColumnType("tinyint(1)"); + + b.Property("AllowViewing") + .HasColumnType("tinyint(1)"); + + b.Property("DefaultValue") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Filter") + .HasColumnType("longtext"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StarId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StarId"); + + b.ToTable("StarVariables", "Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node") + .WithMany("Allocations") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany("Allocations") + .HasForeignKey("ServerId"); + + b.Navigation("Node"); + + b.Navigation("Server"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node") + .WithMany("Servers") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany() + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Node"); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server") + .WithMany() + .HasForeignKey("ServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Server"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany("DockerImages") + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b => + { + b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star") + .WithMany("Variables") + .HasForeignKey("StarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Star"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b => + { + b.Navigation("Allocations"); + + b.Navigation("Servers"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b => + { + b.Navigation("Allocations"); + }); + + modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MoonlightServers.ApiServer/Database/MoonlightServersDataContext.cs b/MoonlightServers.ApiServer/Database/MoonlightServersDataContext.cs deleted file mode 100644 index 03552a2..0000000 --- a/MoonlightServers.ApiServer/Database/MoonlightServersDataContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Moonlight.ApiServer.Configuration; -using Moonlight.ApiServer.Helpers; - -namespace MoonlightServers.ApiServer.Database; - -public class MoonlightServersDataContext : DatabaseContext -{ - public override string Prefix { get; } = "MoonlightServers"; - - public MoonlightServersDataContext(AppConfiguration configuration) : base(configuration) - { - } -} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Database/ServersDataContext.cs b/MoonlightServers.ApiServer/Database/ServersDataContext.cs new file mode 100644 index 0000000..91e8f20 --- /dev/null +++ b/MoonlightServers.ApiServer/Database/ServersDataContext.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Moonlight.ApiServer.Configuration; +using Moonlight.ApiServer.Helpers; +using MoonlightServers.ApiServer.Database.Entities; + +namespace MoonlightServers.ApiServer.Database; + +public class ServersDataContext : DatabaseContext +{ + public override string Prefix { get; } = "Servers"; + + public DbSet Allocations { get; set; } + public DbSet Nodes { get; set; } + public DbSet Servers { get; set; } + public DbSet ServerBackups { get; set; } + public DbSet ServerVariables { get; set; } + public DbSet Stars { get; set; } + public DbSet StarDockerImages { get; set; } + public DbSet StarVariables { get; set; } + + public ServersDataContext(AppConfiguration configuration) : base(configuration) + { + } +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/ExampleController.cs b/MoonlightServers.ApiServer/Http/Controllers/ExampleController.cs deleted file mode 100644 index 1a4b4b9..0000000 --- a/MoonlightServers.ApiServer/Http/Controllers/ExampleController.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using MoonlightServers.ApiServer.Services; -using MoonlightServers.Shared.Http.Responses; - -namespace MoonlightServers.ApiServer.Http.Controllers; - -[ApiController] -[Route("api/example")] -public class ExampleController : Controller -{ - private readonly ExampleService ExampleService; - - public ExampleController(ExampleService exampleService) - { - ExampleService = exampleService; - } - - [HttpGet] - public async Task Get() - { - var val = await ExampleService.GetValue(); - - return new ExampleResponse() - { - Number = val - }; - } -} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj b/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj index cf02fcf..2eb0575 100644 --- a/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj +++ b/MoonlightServers.ApiServer/MoonlightServers.ApiServer.csproj @@ -18,9 +18,9 @@ - + diff --git a/MoonlightServers.ApiServer/Startup/DatabaseStartup.cs b/MoonlightServers.ApiServer/Startup/DatabaseStartup.cs index 68ed678..75f8e80 100644 --- a/MoonlightServers.ApiServer/Startup/DatabaseStartup.cs +++ b/MoonlightServers.ApiServer/Startup/DatabaseStartup.cs @@ -8,7 +8,7 @@ public class DatabaseStartup : IDatabaseStartup { public Task ConfigureDatabase(DatabaseContextCollection collection) { - collection.Add(); + collection.Add(); return Task.CompletedTask; } diff --git a/MoonlightServers.ApiServer/Startup/PluginStartup.cs b/MoonlightServers.ApiServer/Startup/PluginStartup.cs index 323b366..09e1a4b 100644 --- a/MoonlightServers.ApiServer/Startup/PluginStartup.cs +++ b/MoonlightServers.ApiServer/Startup/PluginStartup.cs @@ -14,8 +14,6 @@ public class PluginStartup : IAppStartup public Task BuildApp(IHostApplicationBuilder builder) { - Logger.LogInformation("Elo World from MoonlightServers"); - // Scan the current plugin assembly for di services builder.Services.AutoAddServices(); diff --git a/MoonlightServers.Frontend/Implementations/SidebarImplementation.cs b/MoonlightServers.Frontend/Implementations/SidebarImplementation.cs index 871dc20..6b3edf8 100644 --- a/MoonlightServers.Frontend/Implementations/SidebarImplementation.cs +++ b/MoonlightServers.Frontend/Implementations/SidebarImplementation.cs @@ -11,11 +11,11 @@ public class SidebarImplementation : ISidebarItemProvider [ new SidebarItem() { - Name = "Example", - Path = "/example", - Icon = "icon-moon", - Group = "MoonlightServers", - Priority = 1 + Name = "Servers", + Path = "/admin/servers", + Icon = "icon-server", + Group = "Admin", + Priority = 4 } ]; } diff --git a/MoonlightServers.Frontend/UI/Views/Admin/Index.razor b/MoonlightServers.Frontend/UI/Views/Admin/Index.razor new file mode 100644 index 0000000..d475c95 --- /dev/null +++ b/MoonlightServers.Frontend/UI/Views/Admin/Index.razor @@ -0,0 +1,2 @@ +@page "/admin/servers" + diff --git a/MoonlightServers.Frontend/UI/Views/Example.razor b/MoonlightServers.Frontend/UI/Views/Example.razor deleted file mode 100644 index a859c82..0000000 --- a/MoonlightServers.Frontend/UI/Views/Example.razor +++ /dev/null @@ -1,25 +0,0 @@ -@page "/example" - -@using MoonCore.Helpers -@using MoonCore.Blazor.Tailwind.Components -@using MoonlightServers.Shared.Http.Responses - -@inject HttpApiClient ApiClient - -

Welcome to this example page

- - -

- @Response.Number -

-
- -@code -{ - private ExampleResponse Response; - - private async Task Load(LazyLoader _) - { - Response = await ApiClient.GetJson("api/example"); - } -} \ No newline at end of file diff --git a/MoonlightServers.Shared/Enums/StarVariableType.cs b/MoonlightServers.Shared/Enums/StarVariableType.cs new file mode 100644 index 0000000..638148e --- /dev/null +++ b/MoonlightServers.Shared/Enums/StarVariableType.cs @@ -0,0 +1,9 @@ +namespace MoonlightServers.Shared.Enums; + +public enum StarVariableType +{ + Text = 0, + Number = 1, + Toggle = 2, + Select = 3 +} \ No newline at end of file