From 7f0007b1e22fef93d74d36c13f8661f07279bde3 Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Tue, 17 Jun 2025 18:54:43 +0200 Subject: [PATCH] =?UTF-8?q?Auswahl=20zwischen=20MySQL=20und=20Sqlite=20m?= =?UTF-8?q?=C3=B6glich,=20Datenbank=20kompletter=20Reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 + Watcher/Controllers/AuthController.cs | 59 +- Watcher/Controllers/MonitoringController.cs | 2 +- Watcher/Data/AppDbContext.cs | 34 +- .../20250613213714_InitialCreate.Designer.cs | 57 -- .../20250613213714_InitialCreate.cs | 48 -- .../20250613215617_ModelsAdded.Designer.cs | 57 -- .../Migrations/20250613215617_ModelsAdded.cs | 22 - ...0250614153746_ServerModelAdded.Designer.cs | 87 -- .../20250614153746_ServerModelAdded.cs | 45 - ...50614154943_InitialModelsAdded.Designer.cs | 87 -- .../20250614154943_InitialModelsAdded.cs | 22 - ...614155203_InitialModelsAdded_1.Designer.cs | 271 ------ .../20250614173150_UserChanges.Designer.cs | 278 ------- .../Migrations/20250614173150_UserChanges.cs | 79 -- ...rver-Container-IsRunning-Value.Designer.cs | 284 ------- ...183243_Server-Container-IsRunning-Value.cs | 40 - ...224113_Container-Server-Update.Designer.cs | 290 ------- .../20250614224113_Container-Server-Update.cs | 29 - ...20250615102649_ServerAnpassung.Designer.cs | 293 ------- .../20250615102649_ServerAnpassung.cs | 30 - .../20250615114821_ServerCleanUp.cs | 51 -- .../20250616181808_Server-Hardware-Infos.cs | 62 -- ...250617153602_InitialMigration.Designer.cs} | 4 +- ....cs => 20250617153602_InitialMigration.cs} | 232 +++--- ...250617165126_ServerPrimaryKey.Designer.cs} | 100 ++- .../20250617165126_ServerPrimaryKey.cs | 785 ++++++++++++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 92 +- Watcher/Models/Server.cs | 5 + Watcher/Program.cs | 47 +- Watcher/ViewModels/LoginViewModel.cs | 15 + Watcher/Views/Auth/Login.cshtml | 33 +- Watcher/Watcher.csproj | 4 +- Watcher/appsettings.json | 11 +- 34 files changed, 1199 insertions(+), 2360 deletions(-) delete mode 100644 Watcher/Migrations/20250613213714_InitialCreate.Designer.cs delete mode 100644 Watcher/Migrations/20250613213714_InitialCreate.cs delete mode 100644 Watcher/Migrations/20250613215617_ModelsAdded.Designer.cs delete mode 100644 Watcher/Migrations/20250613215617_ModelsAdded.cs delete mode 100644 Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs delete mode 100644 Watcher/Migrations/20250614153746_ServerModelAdded.cs delete mode 100644 Watcher/Migrations/20250614154943_InitialModelsAdded.Designer.cs delete mode 100644 Watcher/Migrations/20250614154943_InitialModelsAdded.cs delete mode 100644 Watcher/Migrations/20250614155203_InitialModelsAdded_1.Designer.cs delete mode 100644 Watcher/Migrations/20250614173150_UserChanges.Designer.cs delete mode 100644 Watcher/Migrations/20250614173150_UserChanges.cs delete mode 100644 Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.Designer.cs delete mode 100644 Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.cs delete mode 100644 Watcher/Migrations/20250614224113_Container-Server-Update.Designer.cs delete mode 100644 Watcher/Migrations/20250614224113_Container-Server-Update.cs delete mode 100644 Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs delete mode 100644 Watcher/Migrations/20250615102649_ServerAnpassung.cs delete mode 100644 Watcher/Migrations/20250615114821_ServerCleanUp.cs delete mode 100644 Watcher/Migrations/20250616181808_Server-Hardware-Infos.cs rename Watcher/Migrations/{20250616181808_Server-Hardware-Infos.Designer.cs => 20250617153602_InitialMigration.Designer.cs} (99%) rename Watcher/Migrations/{20250614155203_InitialModelsAdded_1.cs => 20250617153602_InitialMigration.cs} (59%) rename Watcher/Migrations/{20250615114821_ServerCleanUp.Designer.cs => 20250617165126_ServerPrimaryKey.Designer.cs} (73%) create mode 100644 Watcher/Migrations/20250617165126_ServerPrimaryKey.cs create mode 100644 Watcher/ViewModels/LoginViewModel.cs diff --git a/.gitignore b/.gitignore index cc031e3..beb2f17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Per-Use special Files and Directories +/persistance/*.db +/logs + # Build-Ordner bin/ obj/ diff --git a/Watcher/Controllers/AuthController.cs b/Watcher/Controllers/AuthController.cs index 971a3ff..029ea39 100644 --- a/Watcher/Controllers/AuthController.cs +++ b/Watcher/Controllers/AuthController.cs @@ -1,29 +1,78 @@ +using System.Security.Claims; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Watcher.ViewModels; namespace Watcher.Controllers; public class AuthController : Controller { - public IActionResult Login() + private readonly IConfiguration _config; + + public AuthController(IConfiguration config) { - return View(); + _config = config; } - public IActionResult SignIn() + [HttpGet] + public IActionResult Login(string? returnUrl = null) { + var vm = new LoginViewModel { ReturnUrl = returnUrl }; + return View(vm); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Login(LoginViewModel model) + { + if (!ModelState.IsValid) + return View(model); + + // Beispielhafte, harte lokale Benutzerprüfung + if (model.Username == "admin" && model.Password == "password") + { + var claims = new List + { + new Claim(ClaimTypes.Name, model.Username), + new Claim(ClaimTypes.Role, "Admin") + }; + + var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); + var principal = new ClaimsPrincipal(identity); + + await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); + + return Redirect(model.ReturnUrl ?? "/"); + } + + ModelState.AddModelError("", "Ungültiger Benutzername oder Passwort"); + return View(model); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult SignIn(string? returnUrl = null) + { + var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Auth", new { returnUrl }); return Challenge(new AuthenticationProperties { - RedirectUri = "/" + RedirectUri = redirectUrl }, "oidc"); } + [HttpGet] + public IActionResult ExternalLoginCallback(string? returnUrl = null) + { + return Redirect(returnUrl ?? "/"); + } + [HttpPost] [ValidateAntiForgeryToken] public async Task Logout() { - await HttpContext.SignOutAsync(); + await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return RedirectToAction("Index", "Home"); } diff --git a/Watcher/Controllers/MonitoringController.cs b/Watcher/Controllers/MonitoringController.cs index eb13256..3f53df3 100644 --- a/Watcher/Controllers/MonitoringController.cs +++ b/Watcher/Controllers/MonitoringController.cs @@ -52,7 +52,7 @@ public class MetricDto } [ApiController] -[Route("[monitoring]")] +[Route("[controller]")] public class MonitoringController : Controller { private readonly AppDbContext _context; diff --git a/Watcher/Data/AppDbContext.cs b/Watcher/Data/AppDbContext.cs index 8fbcc52..c88df1b 100644 --- a/Watcher/Data/AppDbContext.cs +++ b/Watcher/Data/AppDbContext.cs @@ -1,11 +1,18 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Watcher.Models; namespace Watcher.Data; public class AppDbContext : DbContext { - public AppDbContext(DbContextOptions options) : base(options) { } + private readonly IConfiguration _configuration; + + public AppDbContext(DbContextOptions options, IConfiguration configuration) + : base(options) + { + _configuration = configuration; + } public DbSet Containers { get; set; } @@ -21,6 +28,29 @@ public class AppDbContext : DbContext public DbSet Users { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + var provider = _configuration["Database:Provider"]; + + if (provider == "MySql") + { + var connStr = _configuration.GetConnectionString("MySql") + ?? _configuration["Database:ConnectionStrings:MySql"]; + optionsBuilder.UseMySql(connStr, ServerVersion.AutoDetect(connStr)); + } + else if (provider == "Sqlite") + { + var connStr = _configuration.GetConnectionString("Sqlite") + ?? _configuration["Database:ConnectionStrings:Sqlite"]; + optionsBuilder.UseSqlite(connStr); + } + else + { + throw new Exception("Unsupported database provider configured."); + } + } + } } - diff --git a/Watcher/Migrations/20250613213714_InitialCreate.Designer.cs b/Watcher/Migrations/20250613213714_InitialCreate.Designer.cs deleted file mode 100644 index 502ab4a..0000000 --- a/Watcher/Migrations/20250613213714_InitialCreate.Designer.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250613213714_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Containers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250613213714_InitialCreate.cs b/Watcher/Migrations/20250613213714_InitialCreate.cs deleted file mode 100644 index cc04d1f..0000000 --- a/Watcher/Migrations/20250613213714_InitialCreate.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterDatabase() - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "Containers", - 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"), - Status = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - CreatedAt = table.Column(type: "datetime(6)", nullable: false), - Hostname = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Type = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_Containers", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Containers"); - } - } -} diff --git a/Watcher/Migrations/20250613215617_ModelsAdded.Designer.cs b/Watcher/Migrations/20250613215617_ModelsAdded.Designer.cs deleted file mode 100644 index cd3d6b3..0000000 --- a/Watcher/Migrations/20250613215617_ModelsAdded.Designer.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250613215617_ModelsAdded")] - partial class ModelsAdded - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Containers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250613215617_ModelsAdded.cs b/Watcher/Migrations/20250613215617_ModelsAdded.cs deleted file mode 100644 index 95e1fde..0000000 --- a/Watcher/Migrations/20250613215617_ModelsAdded.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ModelsAdded : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs b/Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs deleted file mode 100644 index a43aa0d..0000000 --- a/Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs +++ /dev/null @@ -1,87 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250614153746_ServerModelAdded")] - partial class ServerModelAdded - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250614153746_ServerModelAdded.cs b/Watcher/Migrations/20250614153746_ServerModelAdded.cs deleted file mode 100644 index e63f373..0000000 --- a/Watcher/Migrations/20250614153746_ServerModelAdded.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ServerModelAdded : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "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"), - Status = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - CreatedAt = table.Column(type: "datetime(6)", nullable: false), - Hostname = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Type = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_Servers", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Servers"); - } - } -} diff --git a/Watcher/Migrations/20250614154943_InitialModelsAdded.Designer.cs b/Watcher/Migrations/20250614154943_InitialModelsAdded.Designer.cs deleted file mode 100644 index 513374c..0000000 --- a/Watcher/Migrations/20250614154943_InitialModelsAdded.Designer.cs +++ /dev/null @@ -1,87 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250614154943_InitialModelsAdded")] - partial class InitialModelsAdded - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250614154943_InitialModelsAdded.cs b/Watcher/Migrations/20250614154943_InitialModelsAdded.cs deleted file mode 100644 index 0991d75..0000000 --- a/Watcher/Migrations/20250614154943_InitialModelsAdded.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class InitialModelsAdded : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/Watcher/Migrations/20250614155203_InitialModelsAdded_1.Designer.cs b/Watcher/Migrations/20250614155203_InitialModelsAdded_1.Designer.cs deleted file mode 100644 index cfe2942..0000000 --- a/Watcher/Migrations/20250614155203_InitialModelsAdded_1.Designer.cs +++ /dev/null @@ -1,271 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250614155203_InitialModelsAdded_1")] - partial class InitialModelsAdded_1 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ImageId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.HasIndex("TagId"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.Property("Tag") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("Level") - .HasColumnType("longtext"); - - b.Property("Message") - .HasColumnType("longtext"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("LogEvents"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.Property("Type") - .HasColumnType("longtext"); - - b.Property("Value") - .HasColumnType("double"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("Metrics"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("TagId"); - - b.ToTable("Servers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("Watcher.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("PocketId") - .HasColumnType("longtext"); - - b.Property("Role") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.HasOne("Watcher.Models.Image", null) - .WithMany("Containers") - .HasForeignKey("ImageId"); - - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Containers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Servers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Navigation("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Navigation("Containers"); - - b.Navigation("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250614173150_UserChanges.Designer.cs b/Watcher/Migrations/20250614173150_UserChanges.Designer.cs deleted file mode 100644 index dd22ffb..0000000 --- a/Watcher/Migrations/20250614173150_UserChanges.Designer.cs +++ /dev/null @@ -1,278 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250614173150_UserChanges")] - partial class UserChanges - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ImageId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.HasIndex("TagId"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.Property("Tag") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("Level") - .HasColumnType("longtext"); - - b.Property("Message") - .HasColumnType("longtext"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("LogEvents"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.Property("Type") - .HasColumnType("longtext"); - - b.Property("Value") - .HasColumnType("double"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("Metrics"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("TagId"); - - b.ToTable("Servers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("Watcher.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Email") - .HasColumnType("longtext"); - - b.Property("LastLogin") - .HasColumnType("datetime(6)"); - - b.Property("PocketId") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PreferredUsername") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.HasOne("Watcher.Models.Image", null) - .WithMany("Containers") - .HasForeignKey("ImageId"); - - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Containers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Servers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Navigation("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Navigation("Containers"); - - b.Navigation("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250614173150_UserChanges.cs b/Watcher/Migrations/20250614173150_UserChanges.cs deleted file mode 100644 index e288a35..0000000 --- a/Watcher/Migrations/20250614173150_UserChanges.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class UserChanges : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "Role", - table: "Users", - newName: "PreferredUsername"); - - migrationBuilder.UpdateData( - table: "Users", - keyColumn: "PocketId", - keyValue: null, - column: "PocketId", - value: ""); - - migrationBuilder.AlterColumn( - name: "PocketId", - table: "Users", - type: "longtext", - nullable: false, - oldClrType: typeof(string), - oldType: "longtext", - oldNullable: true) - .Annotation("MySql:CharSet", "utf8mb4") - .OldAnnotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "Email", - table: "Users", - type: "longtext", - nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "LastLogin", - table: "Users", - type: "datetime(6)", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Email", - table: "Users"); - - migrationBuilder.DropColumn( - name: "LastLogin", - table: "Users"); - - migrationBuilder.RenameColumn( - name: "PreferredUsername", - table: "Users", - newName: "Role"); - - migrationBuilder.AlterColumn( - name: "PocketId", - table: "Users", - type: "longtext", - nullable: true, - oldClrType: typeof(string), - oldType: "longtext") - .Annotation("MySql:CharSet", "utf8mb4") - .OldAnnotation("MySql:CharSet", "utf8mb4"); - } - } -} diff --git a/Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.Designer.cs b/Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.Designer.cs deleted file mode 100644 index 60f4cfb..0000000 --- a/Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.Designer.cs +++ /dev/null @@ -1,284 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250614183243_Server-Container-IsRunning-Value")] - partial class ServerContainerIsRunningValue - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ImageId") - .HasColumnType("int"); - - b.Property("IsRunning") - .HasColumnType("tinyint(1)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.HasIndex("TagId"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.Property("Tag") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("Level") - .HasColumnType("longtext"); - - b.Property("Message") - .HasColumnType("longtext"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("LogEvents"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.Property("Type") - .HasColumnType("longtext"); - - b.Property("Value") - .HasColumnType("double"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("Metrics"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("IsOnline") - .HasColumnType("tinyint(1)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("TagId"); - - b.ToTable("Servers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("Watcher.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Email") - .HasColumnType("longtext"); - - b.Property("LastLogin") - .HasColumnType("datetime(6)"); - - b.Property("PocketId") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PreferredUsername") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.HasOne("Watcher.Models.Image", null) - .WithMany("Containers") - .HasForeignKey("ImageId"); - - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Containers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Servers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Navigation("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Navigation("Containers"); - - b.Navigation("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.cs b/Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.cs deleted file mode 100644 index e6c9cab..0000000 --- a/Watcher/Migrations/20250614183243_Server-Container-IsRunning-Value.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ServerContainerIsRunningValue : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IsOnline", - table: "Servers", - type: "tinyint(1)", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "IsRunning", - table: "Containers", - type: "tinyint(1)", - nullable: false, - defaultValue: false); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "IsOnline", - table: "Servers"); - - migrationBuilder.DropColumn( - name: "IsRunning", - table: "Containers"); - } - } -} diff --git a/Watcher/Migrations/20250614224113_Container-Server-Update.Designer.cs b/Watcher/Migrations/20250614224113_Container-Server-Update.Designer.cs deleted file mode 100644 index 0ac9bbe..0000000 --- a/Watcher/Migrations/20250614224113_Container-Server-Update.Designer.cs +++ /dev/null @@ -1,290 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250614224113_Container-Server-Update")] - partial class ContainerServerUpdate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ImageId") - .HasColumnType("int"); - - b.Property("IsRunning") - .HasColumnType("tinyint(1)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.HasIndex("TagId"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.Property("Tag") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("Level") - .HasColumnType("longtext"); - - b.Property("Message") - .HasColumnType("longtext"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("LogEvents"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.Property("Type") - .HasColumnType("longtext"); - - b.Property("Value") - .HasColumnType("double"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("Metrics"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("IPAddress") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("IsOnline") - .HasColumnType("tinyint(1)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("TagId"); - - b.ToTable("Servers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("Watcher.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Email") - .HasColumnType("longtext"); - - b.Property("LastLogin") - .HasColumnType("datetime(6)"); - - b.Property("PocketId") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PreferredUsername") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.HasOne("Watcher.Models.Image", "Image") - .WithMany("Containers") - .HasForeignKey("ImageId"); - - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Containers") - .HasForeignKey("TagId"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Servers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Navigation("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Navigation("Containers"); - - b.Navigation("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250614224113_Container-Server-Update.cs b/Watcher/Migrations/20250614224113_Container-Server-Update.cs deleted file mode 100644 index b485dfd..0000000 --- a/Watcher/Migrations/20250614224113_Container-Server-Update.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ContainerServerUpdate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IPAddress", - table: "Servers", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "IPAddress", - table: "Servers"); - } - } -} diff --git a/Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs b/Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs deleted file mode 100644 index acd59d2..0000000 --- a/Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs +++ /dev/null @@ -1,293 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Watcher.Data; - -#nullable disable - -namespace Watcher.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20250615102649_ServerAnpassung")] - partial class ServerAnpassung - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ImageId") - .HasColumnType("int"); - - b.Property("IsRunning") - .HasColumnType("tinyint(1)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.HasIndex("TagId"); - - b.ToTable("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.Property("Tag") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("Level") - .HasColumnType("longtext"); - - b.Property("Message") - .HasColumnType("longtext"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("LogEvents"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ContainerId") - .HasColumnType("int"); - - b.Property("ServerId") - .HasColumnType("int"); - - b.Property("Timestamp") - .HasColumnType("datetime(6)"); - - b.Property("Type") - .HasColumnType("longtext"); - - b.Property("Value") - .HasColumnType("double"); - - b.HasKey("Id"); - - b.HasIndex("ContainerId"); - - b.HasIndex("ServerId"); - - b.ToTable("Metrics"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)"); - - b.Property("Hostname") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("IPAddress") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("IsOnline") - .HasColumnType("tinyint(1)"); - - b.Property("LastSeen") - .HasColumnType("datetime(6)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TagId") - .HasColumnType("int"); - - b.Property("Type") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("TagId"); - - b.ToTable("Servers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("Watcher.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("Email") - .HasColumnType("longtext"); - - b.Property("LastLogin") - .HasColumnType("datetime(6)"); - - b.Property("PocketId") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PreferredUsername") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Watcher.Models.Container", b => - { - b.HasOne("Watcher.Models.Image", "Image") - .WithMany("Containers") - .HasForeignKey("ImageId"); - - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Containers") - .HasForeignKey("TagId"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("Watcher.Models.LogEvent", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Metric", b => - { - b.HasOne("Watcher.Models.Container", "Container") - .WithMany() - .HasForeignKey("ContainerId"); - - b.HasOne("Watcher.Models.Server", "Server") - .WithMany() - .HasForeignKey("ServerId"); - - b.Navigation("Container"); - - b.Navigation("Server"); - }); - - modelBuilder.Entity("Watcher.Models.Server", b => - { - b.HasOne("Watcher.Models.Tag", null) - .WithMany("Servers") - .HasForeignKey("TagId"); - }); - - modelBuilder.Entity("Watcher.Models.Image", b => - { - b.Navigation("Containers"); - }); - - modelBuilder.Entity("Watcher.Models.Tag", b => - { - b.Navigation("Containers"); - - b.Navigation("Servers"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Watcher/Migrations/20250615102649_ServerAnpassung.cs b/Watcher/Migrations/20250615102649_ServerAnpassung.cs deleted file mode 100644 index c8e9931..0000000 --- a/Watcher/Migrations/20250615102649_ServerAnpassung.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ServerAnpassung : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "LastSeen", - table: "Servers", - type: "datetime(6)", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "LastSeen", - table: "Servers"); - } - } -} diff --git a/Watcher/Migrations/20250615114821_ServerCleanUp.cs b/Watcher/Migrations/20250615114821_ServerCleanUp.cs deleted file mode 100644 index 3d03083..0000000 --- a/Watcher/Migrations/20250615114821_ServerCleanUp.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ServerCleanUp : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Hostname", - table: "Servers"); - - migrationBuilder.DropColumn( - name: "Status", - table: "Servers"); - - migrationBuilder.AddColumn( - name: "Description", - table: "Servers", - type: "longtext", - nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Description", - table: "Servers"); - - migrationBuilder.AddColumn( - name: "Hostname", - table: "Servers", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "Status", - table: "Servers", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - } - } -} diff --git a/Watcher/Migrations/20250616181808_Server-Hardware-Infos.cs b/Watcher/Migrations/20250616181808_Server-Hardware-Infos.cs deleted file mode 100644 index da270ee..0000000 --- a/Watcher/Migrations/20250616181808_Server-Hardware-Infos.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Watcher.Migrations -{ - /// - public partial class ServerHardwareInfos : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "CpuCores", - table: "Servers", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "CpuType", - table: "Servers", - type: "longtext", - nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "GpuType", - table: "Servers", - type: "longtext", - nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "RamSize", - table: "Servers", - type: "double", - nullable: false, - defaultValue: 0.0); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CpuCores", - table: "Servers"); - - migrationBuilder.DropColumn( - name: "CpuType", - table: "Servers"); - - migrationBuilder.DropColumn( - name: "GpuType", - table: "Servers"); - - migrationBuilder.DropColumn( - name: "RamSize", - table: "Servers"); - } - } -} diff --git a/Watcher/Migrations/20250616181808_Server-Hardware-Infos.Designer.cs b/Watcher/Migrations/20250617153602_InitialMigration.Designer.cs similarity index 99% rename from Watcher/Migrations/20250616181808_Server-Hardware-Infos.Designer.cs rename to Watcher/Migrations/20250617153602_InitialMigration.Designer.cs index f3b3e9a..5d549f0 100644 --- a/Watcher/Migrations/20250616181808_Server-Hardware-Infos.Designer.cs +++ b/Watcher/Migrations/20250617153602_InitialMigration.Designer.cs @@ -11,8 +11,8 @@ using Watcher.Data; namespace Watcher.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20250616181808_Server-Hardware-Infos")] - partial class ServerHardwareInfos + [Migration("20250617153602_InitialMigration")] + partial class InitialMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/Watcher/Migrations/20250614155203_InitialModelsAdded_1.cs b/Watcher/Migrations/20250617153602_InitialMigration.cs similarity index 59% rename from Watcher/Migrations/20250614155203_InitialModelsAdded_1.cs rename to Watcher/Migrations/20250617153602_InitialMigration.cs index ac7f668..e8bc8fd 100644 --- a/Watcher/Migrations/20250614155203_InitialModelsAdded_1.cs +++ b/Watcher/Migrations/20250617153602_InitialMigration.cs @@ -7,28 +7,13 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Watcher.Migrations { /// - public partial class InitialModelsAdded_1 : Migration + public partial class InitialMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AddColumn( - name: "TagId", - table: "Servers", - type: "int", - nullable: true); - - migrationBuilder.AddColumn( - name: "ImageId", - table: "Containers", - type: "int", - nullable: true); - - migrationBuilder.AddColumn( - name: "TagId", - table: "Containers", - type: "int", - nullable: true); + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Images", @@ -47,6 +32,112 @@ namespace Watcher.Migrations }) .Annotation("MySql:CharSet", "utf8mb4"); + migrationBuilder.CreateTable( + name: "Tags", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Tags", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + PocketId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PreferredUsername = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Email = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + LastLogin = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Containers", + 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"), + Status = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ImageId = table.Column(type: "int", nullable: true), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + Hostname = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Type = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsRunning = table.Column(type: "tinyint(1)", nullable: false), + TagId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Containers", x => x.Id); + table.ForeignKey( + name: "FK_Containers_Images_ImageId", + column: x => x.ImageId, + principalTable: "Images", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Containers_Tags_TagId", + column: x => x.TagId, + principalTable: "Tags", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "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"), + IPAddress = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + Type = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsOnline = table.Column(type: "tinyint(1)", nullable: false), + LastSeen = table.Column(type: "datetime(6)", nullable: false), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + CpuType = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + CpuCores = table.Column(type: "int", nullable: false), + GpuType = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + RamSize = table.Column(type: "double", nullable: false), + TagId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Servers", x => x.Id); + table.ForeignKey( + name: "FK_Servers_Tags_TagId", + column: x => x.TagId, + principalTable: "Tags", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + migrationBuilder.CreateTable( name: "LogEvents", columns: table => new @@ -106,43 +197,6 @@ namespace Watcher.Migrations }) .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateTable( - name: "Tags", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - Name = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_Tags", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - PocketId = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - Role = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateIndex( - name: "IX_Servers_TagId", - table: "Servers", - column: "TagId"); - migrationBuilder.CreateIndex( name: "IX_Containers_ImageId", table: "Containers", @@ -173,81 +227,35 @@ namespace Watcher.Migrations table: "Metrics", column: "ServerId"); - migrationBuilder.AddForeignKey( - name: "FK_Containers_Images_ImageId", - table: "Containers", - column: "ImageId", - principalTable: "Images", - principalColumn: "Id"); - - migrationBuilder.AddForeignKey( - name: "FK_Containers_Tags_TagId", - table: "Containers", - column: "TagId", - principalTable: "Tags", - principalColumn: "Id"); - - migrationBuilder.AddForeignKey( - name: "FK_Servers_Tags_TagId", + migrationBuilder.CreateIndex( + name: "IX_Servers_TagId", table: "Servers", - column: "TagId", - principalTable: "Tags", - principalColumn: "Id"); + column: "TagId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropForeignKey( - name: "FK_Containers_Images_ImageId", - table: "Containers"); - - migrationBuilder.DropForeignKey( - name: "FK_Containers_Tags_TagId", - table: "Containers"); - - migrationBuilder.DropForeignKey( - name: "FK_Servers_Tags_TagId", - table: "Servers"); - - migrationBuilder.DropTable( - name: "Images"); - migrationBuilder.DropTable( name: "LogEvents"); migrationBuilder.DropTable( name: "Metrics"); - migrationBuilder.DropTable( - name: "Tags"); - migrationBuilder.DropTable( name: "Users"); - migrationBuilder.DropIndex( - name: "IX_Servers_TagId", - table: "Servers"); + migrationBuilder.DropTable( + name: "Containers"); - migrationBuilder.DropIndex( - name: "IX_Containers_ImageId", - table: "Containers"); + migrationBuilder.DropTable( + name: "Servers"); - migrationBuilder.DropIndex( - name: "IX_Containers_TagId", - table: "Containers"); + migrationBuilder.DropTable( + name: "Images"); - migrationBuilder.DropColumn( - name: "TagId", - table: "Servers"); - - migrationBuilder.DropColumn( - name: "ImageId", - table: "Containers"); - - migrationBuilder.DropColumn( - name: "TagId", - table: "Containers"); + migrationBuilder.DropTable( + name: "Tags"); } } } diff --git a/Watcher/Migrations/20250615114821_ServerCleanUp.Designer.cs b/Watcher/Migrations/20250617165126_ServerPrimaryKey.Designer.cs similarity index 73% rename from Watcher/Migrations/20250615114821_ServerCleanUp.Designer.cs rename to Watcher/Migrations/20250617165126_ServerPrimaryKey.Designer.cs index 98add17..14cf440 100644 --- a/Watcher/Migrations/20250615114821_ServerCleanUp.Designer.cs +++ b/Watcher/Migrations/20250617165126_ServerPrimaryKey.Designer.cs @@ -11,50 +11,48 @@ using Watcher.Data; namespace Watcher.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20250615114821_ServerCleanUp")] - partial class ServerCleanUp + [Migration("20250617165126_ServerPrimaryKey")] + partial class ServerPrimaryKey { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); + modelBuilder.HasAnnotation("ProductVersion", "8.0.6"); modelBuilder.Entity("Watcher.Models.Container", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("CreatedAt") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Hostname") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("ImageId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("IsRunning") - .HasColumnType("tinyint(1)"); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Status") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("TagId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Type") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -69,13 +67,13 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Tag") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -86,22 +84,22 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("ContainerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Level") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Message") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("ServerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Timestamp") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -116,22 +114,22 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("ContainerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("ServerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Timestamp") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Type") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Value") - .HasColumnType("double"); + .HasColumnType("REAL"); b.HasKey("Id"); @@ -146,34 +144,46 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); + + b.Property("CpuCores") + .HasColumnType("INTEGER"); + + b.Property("CpuType") + .HasColumnType("TEXT"); b.Property("CreatedAt") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Description") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); + + b.Property("GpuType") + .HasColumnType("TEXT"); b.Property("IPAddress") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("IsOnline") - .HasColumnType("tinyint(1)"); + .HasColumnType("INTEGER"); b.Property("LastSeen") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Name") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); + + b.Property("RamSize") + .HasColumnType("REAL"); b.Property("TagId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Type") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -186,10 +196,10 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -200,21 +210,21 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Email") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("LastLogin") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("PocketId") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("PreferredUsername") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); diff --git a/Watcher/Migrations/20250617165126_ServerPrimaryKey.cs b/Watcher/Migrations/20250617165126_ServerPrimaryKey.cs new file mode 100644 index 0000000..f258b61 --- /dev/null +++ b/Watcher/Migrations/20250617165126_ServerPrimaryKey.cs @@ -0,0 +1,785 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Watcher.Migrations +{ + /// + public partial class ServerPrimaryKey : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "PreferredUsername", + table: "Users", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "PocketId", + table: "Users", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "LastLogin", + table: "Users", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime(6)"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Users", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Users", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Tags", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Tags", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Servers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "TagId", + table: "Servers", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "RamSize", + table: "Servers", + type: "REAL", + nullable: false, + oldClrType: typeof(double), + oldType: "double"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Servers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "LastSeen", + table: "Servers", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime(6)"); + + migrationBuilder.AlterColumn( + name: "IsOnline", + table: "Servers", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "tinyint(1)"); + + migrationBuilder.AlterColumn( + name: "IPAddress", + table: "Servers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "GpuType", + table: "Servers", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Servers", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Servers", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime(6)"); + + migrationBuilder.AlterColumn( + name: "CpuType", + table: "Servers", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CpuCores", + table: "Servers", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Servers", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Value", + table: "Metrics", + type: "REAL", + nullable: false, + oldClrType: typeof(double), + oldType: "double"); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Metrics", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Timestamp", + table: "Metrics", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime(6)"); + + migrationBuilder.AlterColumn( + name: "ServerId", + table: "Metrics", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ContainerId", + table: "Metrics", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Metrics", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Timestamp", + table: "LogEvents", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime(6)"); + + migrationBuilder.AlterColumn( + name: "ServerId", + table: "LogEvents", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Message", + table: "LogEvents", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Level", + table: "LogEvents", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ContainerId", + table: "LogEvents", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "LogEvents", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Tag", + table: "Images", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Images", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Images", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Containers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "TagId", + table: "Containers", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Containers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Containers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "IsRunning", + table: "Containers", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "tinyint(1)"); + + migrationBuilder.AlterColumn( + name: "ImageId", + table: "Containers", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Hostname", + table: "Containers", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Containers", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime(6)"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Containers", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "PreferredUsername", + table: "Users", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "PocketId", + table: "Users", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "LastLogin", + table: "Users", + type: "datetime(6)", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Users", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Users", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Tags", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Tags", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Servers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "TagId", + table: "Servers", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "RamSize", + table: "Servers", + type: "double", + nullable: false, + oldClrType: typeof(double), + oldType: "REAL"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Servers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "LastSeen", + table: "Servers", + type: "datetime(6)", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "IsOnline", + table: "Servers", + type: "tinyint(1)", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "IPAddress", + table: "Servers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "GpuType", + table: "Servers", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Servers", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Servers", + type: "datetime(6)", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "CpuType", + table: "Servers", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CpuCores", + table: "Servers", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Servers", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Value", + table: "Metrics", + type: "double", + nullable: false, + oldClrType: typeof(double), + oldType: "REAL"); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Metrics", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Timestamp", + table: "Metrics", + type: "datetime(6)", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ServerId", + table: "Metrics", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ContainerId", + table: "Metrics", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Metrics", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Timestamp", + table: "LogEvents", + type: "datetime(6)", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ServerId", + table: "LogEvents", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Message", + table: "LogEvents", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Level", + table: "LogEvents", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ContainerId", + table: "LogEvents", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "LogEvents", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Tag", + table: "Images", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Images", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Images", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Containers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "TagId", + table: "Containers", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Containers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Containers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "IsRunning", + table: "Containers", + type: "tinyint(1)", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "ImageId", + table: "Containers", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Hostname", + table: "Containers", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Containers", + type: "datetime(6)", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Containers", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + } + } +} diff --git a/Watcher/Migrations/AppDbContextModelSnapshot.cs b/Watcher/Migrations/AppDbContextModelSnapshot.cs index f34eaed..48bd63a 100644 --- a/Watcher/Migrations/AppDbContextModelSnapshot.cs +++ b/Watcher/Migrations/AppDbContextModelSnapshot.cs @@ -15,43 +15,41 @@ namespace Watcher.Migrations protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 64); + modelBuilder.HasAnnotation("ProductVersion", "8.0.6"); modelBuilder.Entity("Watcher.Models.Container", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("CreatedAt") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Hostname") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("ImageId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("IsRunning") - .HasColumnType("tinyint(1)"); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Status") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("TagId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Type") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -66,13 +64,13 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Tag") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -83,22 +81,22 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("ContainerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Level") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Message") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("ServerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Timestamp") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -113,22 +111,22 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("ContainerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("ServerId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Timestamp") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Type") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("Value") - .HasColumnType("double"); + .HasColumnType("REAL"); b.HasKey("Id"); @@ -143,46 +141,46 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("CpuCores") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("CpuType") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("CreatedAt") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Description") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("GpuType") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("IPAddress") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("IsOnline") - .HasColumnType("tinyint(1)"); + .HasColumnType("INTEGER"); b.Property("LastSeen") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("Name") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("RamSize") - .HasColumnType("double"); + .HasColumnType("REAL"); b.Property("TagId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Type") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -195,10 +193,10 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -209,21 +207,21 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Email") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("LastLogin") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); b.Property("PocketId") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.Property("PreferredUsername") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); diff --git a/Watcher/Models/Server.cs b/Watcher/Models/Server.cs index 8c0cacd..14121a0 100644 --- a/Watcher/Models/Server.cs +++ b/Watcher/Models/Server.cs @@ -1,7 +1,12 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + namespace Watcher.Models; public class Server { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string Name { get; set; } = string.Empty; diff --git a/Watcher/Program.cs b/Watcher/Program.cs index a2e01b4..2feaf50 100644 --- a/Watcher/Program.cs +++ b/Watcher/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Sqlite; using Microsoft.IdentityModel.Tokens; using Watcher.Data; using Watcher.Models; @@ -14,16 +15,39 @@ builder.Services.AddControllersWithViews(); // HttpContentAccessor builder.Services.AddHttpContextAccessor(); -// ---------- Konfiguration laden ---------- +// ---------- Konfiguration ---------- +builder.Configuration + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddEnvironmentVariables(); + +// Konfiguration laden var configuration = builder.Configuration; -// ---------- DB-Kontext mit MySQL ---------- -builder.Services.AddDbContext(options => - options.UseMySql( - configuration.GetConnectionString("DefaultConnection"), - ServerVersion.AutoDetect(configuration.GetConnectionString("DefaultConnection")) - ) -); +// ---------- DB-Kontext ---------- + +var dbProvider = configuration["Database:Provider"] ?? "MySQL"; +var connectionString = configuration["Database:ConnectionString"]; + +builder.Services.AddDbContext((serviceProvider, options) => +{ + var config = serviceProvider.GetRequiredService(); + var provider = config["Database:Provider"]; + + if (provider == "MySql") + { + var connStr = config.GetConnectionString("MySql") ?? config["Database:ConnectionStrings:MySql"]; + options.UseMySql(connStr, ServerVersion.AutoDetect(connStr)); + } + else if (provider == "Sqlite") + { + var connStr = config.GetConnectionString("Sqlite") ?? config["Database:ConnectionStrings:Sqlite"]; + options.UseSqlite(connStr); + } + else + { + throw new Exception("Unsupported database provider configured."); + } +}); // ---------- Authentifizierung konfigurieren ---------- builder.Services.AddAuthentication(options => @@ -101,6 +125,13 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } +// Migrationen anwenden (für SQLite oder andere DBs) +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.Migrate(); +} + app.UseHttpsRedirection(); app.UseRouting(); diff --git a/Watcher/ViewModels/LoginViewModel.cs b/Watcher/ViewModels/LoginViewModel.cs new file mode 100644 index 0000000..d29bbf4 --- /dev/null +++ b/Watcher/ViewModels/LoginViewModel.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace Watcher.ViewModels; + +public class LoginViewModel +{ + [Required] + public string Username { get; set; } = string.Empty; + + [Required] + [DataType(DataType.Password)] + public string Password { get; set; } = string.Empty; + + public string? ReturnUrl { get; set; } +} diff --git a/Watcher/Views/Auth/Login.cshtml b/Watcher/Views/Auth/Login.cshtml index e09cffc..38cdbc4 100644 --- a/Watcher/Views/Auth/Login.cshtml +++ b/Watcher/Views/Auth/Login.cshtml @@ -1,9 +1,36 @@ +@model Watcher.ViewModels.LoginViewModel + @{ ViewData["Title"] = "Login"; } -

Willkommen beim Watcher

+

Anmelden

-

Bitte melde dich über PocketID an:

+
+
+ + + +
-Mit PocketID anmelden +
+ + + +
+ + + + +
+ +
+ +
+ + +
+ +@section Scripts { + +} diff --git a/Watcher/Watcher.csproj b/Watcher/Watcher.csproj index 8ba7537..afac185 100644 --- a/Watcher/Watcher.csproj +++ b/Watcher/Watcher.csproj @@ -8,7 +8,9 @@ - + + + diff --git a/Watcher/appsettings.json b/Watcher/appsettings.json index 81748ed..6b867fb 100644 --- a/Watcher/appsettings.json +++ b/Watcher/appsettings.json @@ -5,10 +5,17 @@ "Microsoft.AspNetCore": "Warning" } }, + "AllowedHosts": "*", - "ConnectionStrings": { - "DefaultConnection": "server=100.64.0.5;port=3306;database=watcher;user=monitoringuser;password=ssp123;" + + "Database": { + "Provider": "Sqlite", + "ConnectionStrings": { + "MySql": "server=100.64.0.5;port=3306;database=watcher;user=monitoringuser;password=ssp123;", + "Sqlite": "Data Source=./persistence/watcher.db" + } }, + "Authentication": { "PocketID": { "Authority": "https://pocketid.triggermeelmo.com",