diff --git a/.gitignore b/.gitignore index cc031e3..26adfcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# Per-Use special Files and Directories +/persistance/*.db +/logs +*.env + # Build-Ordner bin/ obj/ diff --git a/Watcher/.env b/Watcher/.env new file mode 100644 index 0000000..131f689 --- /dev/null +++ b/Watcher/.env @@ -0,0 +1,8 @@ + +# OIDC Einstellungen +AUTHENTICATION__USELOCAL=false +AUTHENTICATION__POCKETID__ENABLED=true +AUTHENTICATION__POCKETID__AUTHORITY=https://pocketid.triggermeelmo.com +AUTHENTICATION__POCKETID__CLIENTID=629a5f42-ab02-4905-8311-cc7b64165cc0 +AUTHENTICATION__POCKETID__CLIENTSECRET=QHUNaRyK2VVYdZVz1cQqv8FEf2qtL6QH +AUTHENTICATION__POCKETID__CALLBACKPATH=/signin-oidc \ No newline at end of file diff --git a/Watcher/.env.example b/Watcher/.env.example new file mode 100644 index 0000000..032d787 --- /dev/null +++ b/Watcher/.env.example @@ -0,0 +1,8 @@ + +# OIDC Einstellungen +AUTHENTICATION__USELOCAL=true +AUTHENTICATION__POCKETID__ENABLED=false +AUTHENTICATION__POCKETID__AUTHORITY=https://id.domain.app +AUTHENTICATION__POCKETID__CLIENTID= +AUTHENTICATION__POCKETID__CLIENTSECRET= +AUTHENTICATION__POCKETID__CALLBACKPATH=/signin-oidc diff --git a/Watcher/Controllers/AuthController.cs b/Watcher/Controllers/AuthController.cs index 971a3ff..66ff5f1 100644 --- a/Watcher/Controllers/AuthController.cs +++ b/Watcher/Controllers/AuthController.cs @@ -1,16 +1,61 @@ +using System.Security.Claims; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Watcher.Data; +using Watcher.ViewModels; namespace Watcher.Controllers; public class AuthController : Controller { - public IActionResult Login() + private readonly AppDbContext _context; + + public AuthController(AppDbContext context) { - return View(); + _context = context; } + [HttpGet] + public IActionResult Login(string? returnUrl = null) + { + var model = new LoginViewModel + { + ReturnUrl = returnUrl + }; + return View(model); + } + + + [HttpPost] + public async Task Login(LoginViewModel model) + { + if (!ModelState.IsValid) + return View(model); + + var user = await _context.Users.FirstOrDefaultAsync(u => u.PreferredUsername == model.Username); + if (user == null || !BCrypt.Net.BCrypt.Verify(model.Password, user.Password)) + { + ModelState.AddModelError("", "Benutzername oder Passwort ist falsch."); + return View(model); + } + + var claims = new List + { + new Claim(ClaimTypes.Name, user.PreferredUsername), + new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), + }; + + var identity = new ClaimsIdentity(claims, "local"); + var principal = new ClaimsPrincipal(identity); + + await HttpContext.SignInAsync("Cookies", principal); + + return Redirect("Home/Index"); + } + + public IActionResult SignIn() { return Challenge(new AuthenticationProperties @@ -23,10 +68,18 @@ public class AuthController : Controller [ValidateAntiForgeryToken] public async Task Logout() { - await HttpContext.SignOutAsync(); - return RedirectToAction("Index", "Home"); + var props = new AuthenticationProperties + { + RedirectUri = Url.Action("Login", "Auth") + }; + + await HttpContext.SignOutAsync("Cookies"); + await HttpContext.SignOutAsync("oidc", props); + + return Redirect("/"); // nur als Fallback } + [Authorize] public IActionResult Info() { @@ -38,4 +91,46 @@ public class AuthController : Controller return View(); } + + // Edit-Form anzeigen + [Authorize] + [HttpGet] + public IActionResult Edit() + { + var username = User.Identity?.Name; + var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); + if (user == null) return NotFound(); + + var model = new EditUserViewModel + { + Username = user.PreferredUsername + }; + return View(model); + } + + // Edit speichern + [Authorize] + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Edit(EditUserViewModel model) + { + if (!ModelState.IsValid) return View(model); + + var username = User.Identity?.Name; + var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); + if (user == null) return NotFound(); + + user.PreferredUsername = model.Username; + + if (!string.IsNullOrWhiteSpace(model.NewPassword)) + { + user.PreferredUsername = BCrypt.Net.BCrypt.HashPassword(model.NewPassword); + } + + _context.SaveChanges(); + + // Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert + + return RedirectToAction("Index", "Home"); + } } diff --git a/Watcher/Controllers/ContainerController.cs b/Watcher/Controllers/ContainerController.cs index 624a1a8..e65c127 100644 --- a/Watcher/Controllers/ContainerController.cs +++ b/Watcher/Controllers/ContainerController.cs @@ -7,7 +7,7 @@ using Watcher.ViewModels; namespace Watcher.Controllers; - +[Authorize] public class ContainerController : Controller { private readonly AppDbContext _context; 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.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/20250615102649_ServerAnpassung.Designer.cs b/Watcher/Migrations/20250617174242_UserPasswordAdded.Designer.cs similarity index 71% rename from Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs rename to Watcher/Migrations/20250617174242_UserPasswordAdded.Designer.cs index acd59d2..123e1fa 100644 --- a/Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs +++ b/Watcher/Migrations/20250617174242_UserPasswordAdded.Designer.cs @@ -11,50 +11,48 @@ using Watcher.Data; namespace Watcher.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20250615102649_ServerAnpassung")] - partial class ServerAnpassung + [Migration("20250617174242_UserPasswordAdded")] + partial class UserPasswordAdded { /// 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,39 +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("Hostname") - .IsRequired() - .HasColumnType("longtext"); + b.Property("Description") + .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("Status") - .IsRequired() - .HasColumnType("longtext"); + b.Property("RamSize") + .HasColumnType("REAL"); b.Property("TagId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Type") .IsRequired() - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -191,10 +196,10 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -205,21 +210,29 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Email") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); + + b.Property("IdentityProvider") + .IsRequired() + .HasColumnType("TEXT"); b.Property("LastLogin") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .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/20250617174242_UserPasswordAdded.cs b/Watcher/Migrations/20250617174242_UserPasswordAdded.cs new file mode 100644 index 0000000..04ef332 --- /dev/null +++ b/Watcher/Migrations/20250617174242_UserPasswordAdded.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Watcher.Migrations +{ + /// + public partial class UserPasswordAdded : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IdentityProvider", + table: "Users", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Password", + table: "Users", + type: "TEXT", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IdentityProvider", + table: "Users"); + + migrationBuilder.DropColumn( + name: "Password", + table: "Users"); + } + } +} diff --git a/Watcher/Migrations/AppDbContextModelSnapshot.cs b/Watcher/Migrations/AppDbContextModelSnapshot.cs index f34eaed..1231da3 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,29 @@ namespace Watcher.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Email") - .HasColumnType("longtext"); + .HasColumnType("TEXT"); + + b.Property("IdentityProvider") + .IsRequired() + .HasColumnType("TEXT"); b.Property("LastLogin") - .HasColumnType("datetime(6)"); + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .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/Models/User.cs b/Watcher/Models/User.cs index 12903fc..10d0f0c 100644 --- a/Watcher/Models/User.cs +++ b/Watcher/Models/User.cs @@ -1,3 +1,5 @@ +using System.ComponentModel.DataAnnotations; + namespace Watcher.Models; public class User @@ -7,4 +9,11 @@ public class User public string PreferredUsername { get; set; } = null!; public string? Email { get; set; } public DateTime LastLogin { get; set; } + + [Required] + public string IdentityProvider { get; set; } = "local"; + + [Required] + [DataType(DataType.Password)] + public String? Password { get; set; } = string.Empty; } diff --git a/Watcher/Program.cs b/Watcher/Program.cs index a2e01b4..3f301cb 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,85 +15,164 @@ builder.Services.AddControllersWithViews(); // HttpContentAccessor builder.Services.AddHttpContextAccessor(); -// ---------- Konfiguration laden ---------- +// ---------- Konfiguration ---------- +DotNetEnv.Env.Load(); + +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 => { options.DefaultScheme = "Cookies"; - options.DefaultChallengeScheme = "oidc"; + options.DefaultChallengeScheme = "Cookies"; // Nur wenn kein OIDC erzwungen wird }) -.AddCookie("Cookies") -.AddOpenIdConnect("oidc", options => +.AddCookie("Cookies", options => { - var config = builder.Configuration.GetSection("Authentication:PocketID"); - options.Authority = config["Authority"]; - options.ClientId = config["ClientId"]; - options.ClientSecret = config["ClientSecret"]; - options.ResponseType = "code"; - options.CallbackPath = config["CallbackPath"]; - options.SaveTokens = true; - - options.GetClaimsFromUserInfoEndpoint = true; - - options.Scope.Clear(); - options.Scope.Add("openid"); - options.Scope.Add("profile"); - options.Scope.Add("email"); - - options.Events = new OpenIdConnectEvents -{ - OnTokenValidated = async ctx => - { - var db = ctx.HttpContext.RequestServices.GetRequiredService(); - - var principal = ctx.Principal; - var pocketId = principal.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value; - var preferredUsername = principal.FindFirst("preferred_username")?.Value; - var email = principal.FindFirst("email")?.Value; - - if (string.IsNullOrEmpty(pocketId)) - return; - - var user = await db.Users.FirstOrDefaultAsync(u => u.PocketId == pocketId); - - if (user == null) - { - user = new User - { - PocketId = pocketId, - PreferredUsername = preferredUsername ?? "", - Email = email, - LastLogin = DateTime.UtcNow - }; - db.Users.Add(user); - } - else - { - user.LastLogin = DateTime.UtcNow; - user.PreferredUsername = preferredUsername ?? user.PreferredUsername; - user.Email = email ?? user.Email; - db.Users.Update(user); - } - - await db.SaveChangesAsync(); - } -}; - + options.LoginPath = "/Auth/Login"; }); +// PocketID nur konfigurieren, wenn aktiviert +var pocketIdSection = builder.Configuration.GetSection("Authentication:PocketID"); +var pocketIdEnabled = pocketIdSection.GetValue("Enabled"); + +if (pocketIdEnabled) +{ + builder.Services.AddAuthentication() + .AddOpenIdConnect("oidc", options => + { + options.Authority = pocketIdSection["Authority"]; + options.ClientId = pocketIdSection["ClientId"]; + options.ClientSecret = pocketIdSection["ClientSecret"]; + options.ResponseType = "code"; + options.CallbackPath = pocketIdSection["CallbackPath"]; + options.SaveTokens = true; + + options.GetClaimsFromUserInfoEndpoint = true; + + options.Scope.Clear(); + options.Scope.Add("openid"); + options.Scope.Add("profile"); + options.Scope.Add("email"); + + options.Events = new OpenIdConnectEvents + { + OnTokenValidated = async ctx => + { + var db = ctx.HttpContext.RequestServices.GetRequiredService(); + + var principal = ctx.Principal; + var pocketId = principal.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value; + var preferredUsername = principal.FindFirst("preferred_username")?.Value; + var email = principal.FindFirst("email")?.Value; + + if (string.IsNullOrEmpty(pocketId)) + return; + + var user = await db.Users.FirstOrDefaultAsync(u => u.PocketId == pocketId); + + if (user == null) + { + user = new User + { + PocketId = pocketId, + PreferredUsername = preferredUsername ?? "", + Email = email, + LastLogin = DateTime.UtcNow, + IdentityProvider = "oidc", + Password = string.Empty + }; + db.Users.Add(user); + } + else + { + user.LastLogin = DateTime.UtcNow; + user.PreferredUsername = preferredUsername ?? user.PreferredUsername; + user.Email = email ?? user.Email; + db.Users.Update(user); + } + + await db.SaveChangesAsync(); + } + }; + }); +} + + var app = builder.Build(); + + +// Migrationen anwenden (für SQLite oder andere DBs) +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.Migrate(); +} + + +// Standart-User in Datenbank schreiben +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + + Console.WriteLine("Checking for users..."); + + if (!db.Users.Any()) + { + Console.WriteLine("No users found, creating default user..."); + + var defaultUser = new User + { + PocketId = string.Empty, + PreferredUsername = "admin", + Email = string.Empty, + LastLogin = DateTime.UtcNow, + IdentityProvider = "local", + Password = BCrypt.Net.BCrypt.HashPassword("changeme") + }; + db.Users.Add(defaultUser); + db.SaveChanges(); + + Console.WriteLine("Default user created."); + } + else + { + Console.WriteLine("Users already exist."); + } +} + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -101,6 +181,11 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } + + + + + app.UseHttpsRedirection(); app.UseRouting(); @@ -112,7 +197,7 @@ app.UseStaticFiles(); app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}" + pattern: "{controller=Auth}/{action=Login}/" ); diff --git a/Watcher/ViewModels/EditUserViewModel.cs b/Watcher/ViewModels/EditUserViewModel.cs new file mode 100644 index 0000000..30e3fe4 --- /dev/null +++ b/Watcher/ViewModels/EditUserViewModel.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace Watcher.ViewModels; + +public class EditUserViewModel +{ + [Required] + public string? Username { get; set; } + + [Required] + [DataType(DataType.Password)] + public string? NewPassword { get; set; } + + [Required] + [DataType(DataType.Password)] + [Compare("NewPassword", ErrorMessage = "Passwörter stimmen nicht überein.")] + public string? ConfirmPassword { get; set; } +} 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/EditUser.cshtml b/Watcher/Views/Auth/EditUser.cshtml new file mode 100644 index 0000000..e69de29 diff --git a/Watcher/Views/Auth/Info.cshtml b/Watcher/Views/Auth/Info.cshtml index 95f7267..709c002 100644 --- a/Watcher/Views/Auth/Info.cshtml +++ b/Watcher/Views/Auth/Info.cshtml @@ -76,11 +76,29 @@ +@{ -

Alle Claims

-
    -@foreach (var claim in User.Claims) -{ -
  • @claim.Type: @claim.Value
  • } -
\ No newline at end of file +@if (User.Identity.Name == "admin") +{ +

Benutzerdaten ändern

+
+
+ + +
+
+ + +
+
+ + +
+ +
+} +else +{ +

Benutzerdaten können nur für lokal angemeldete Nutzer geändert werden.

+} diff --git a/Watcher/Views/Auth/Login.cshtml b/Watcher/Views/Auth/Login.cshtml index e09cffc..9d5a5c7 100644 --- a/Watcher/Views/Auth/Login.cshtml +++ b/Watcher/Views/Auth/Login.cshtml @@ -1,9 +1,30 @@ +@model Watcher.ViewModels.LoginViewModel @{ ViewData["Title"] = "Login"; } -

Willkommen beim Watcher

+ diff --git a/Watcher/Views/Shared/_Layout.cshtml b/Watcher/Views/Shared/_Layout.cshtml index 9104883..2ccc018 100644 --- a/Watcher/Views/Shared/_Layout.cshtml +++ b/Watcher/Views/Shared/_Layout.cshtml @@ -62,10 +62,10 @@

Watcher