From 3d96f55e280561ac2520e52b6f26e4eef831e804 Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Sat, 14 Jun 2025 17:54:01 +0200 Subject: [PATCH] basic Db-Setup done --- Watcher/Data/AppDbContext.cs | 13 + ...0250614153746_ServerModelAdded.Designer.cs | 87 ++++++ .../20250614153746_ServerModelAdded.cs | 45 +++ ...50614154943_InitialModelsAdded.Designer.cs | 87 ++++++ .../20250614154943_InitialModelsAdded.cs | 22 ++ ...614155203_InitialModelsAdded_1.Designer.cs | 271 ++++++++++++++++++ .../20250614155203_InitialModelsAdded_1.cs | 253 ++++++++++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 214 ++++++++++++++ Watcher/Models/Image.cs | 10 + Watcher/Models/LogEvent.cs | 15 + Watcher/Models/Metric.cs | 16 ++ Watcher/Models/Tag.cs | 10 + Watcher/Models/User.cs | 8 + 13 files changed, 1051 insertions(+) create mode 100644 Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs create mode 100644 Watcher/Migrations/20250614153746_ServerModelAdded.cs create mode 100644 Watcher/Migrations/20250614154943_InitialModelsAdded.Designer.cs create mode 100644 Watcher/Migrations/20250614154943_InitialModelsAdded.cs create mode 100644 Watcher/Migrations/20250614155203_InitialModelsAdded_1.Designer.cs create mode 100644 Watcher/Migrations/20250614155203_InitialModelsAdded_1.cs create mode 100644 Watcher/Models/Image.cs create mode 100644 Watcher/Models/LogEvent.cs create mode 100644 Watcher/Models/Metric.cs create mode 100644 Watcher/Models/Tag.cs create mode 100644 Watcher/Models/User.cs diff --git a/Watcher/Data/AppDbContext.cs b/Watcher/Data/AppDbContext.cs index 45f1c51..8fbcc52 100644 --- a/Watcher/Data/AppDbContext.cs +++ b/Watcher/Data/AppDbContext.cs @@ -8,6 +8,19 @@ public class AppDbContext : DbContext public AppDbContext(DbContextOptions options) : base(options) { } public DbSet Containers { get; set; } + + public DbSet Servers { get; set; } + + public DbSet Images { get; set; } + + public DbSet LogEvents { get; set; } + + public DbSet Metrics { get; set; } + + public DbSet Tags { get; set; } + + public DbSet Users { get; set; } + } diff --git a/Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs b/Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs new file mode 100644 index 0000000..a43aa0d --- /dev/null +++ b/Watcher/Migrations/20250614153746_ServerModelAdded.Designer.cs @@ -0,0 +1,87 @@ +// +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 new file mode 100644 index 0000000..e63f373 --- /dev/null +++ b/Watcher/Migrations/20250614153746_ServerModelAdded.cs @@ -0,0 +1,45 @@ +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 new file mode 100644 index 0000000..513374c --- /dev/null +++ b/Watcher/Migrations/20250614154943_InitialModelsAdded.Designer.cs @@ -0,0 +1,87 @@ +// +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 new file mode 100644 index 0000000..0991d75 --- /dev/null +++ b/Watcher/Migrations/20250614154943_InitialModelsAdded.cs @@ -0,0 +1,22 @@ +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 new file mode 100644 index 0000000..cfe2942 --- /dev/null +++ b/Watcher/Migrations/20250614155203_InitialModelsAdded_1.Designer.cs @@ -0,0 +1,271 @@ +// +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/20250614155203_InitialModelsAdded_1.cs b/Watcher/Migrations/20250614155203_InitialModelsAdded_1.cs new file mode 100644 index 0000000..ac7f668 --- /dev/null +++ b/Watcher/Migrations/20250614155203_InitialModelsAdded_1.cs @@ -0,0 +1,253 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Watcher.Migrations +{ + /// + public partial class InitialModelsAdded_1 : 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.CreateTable( + name: "Images", + 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"), + Tag = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Images", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "LogEvents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Timestamp = table.Column(type: "datetime(6)", nullable: false), + Message = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Level = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ServerId = table.Column(type: "int", nullable: true), + ContainerId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_LogEvents", x => x.Id); + table.ForeignKey( + name: "FK_LogEvents_Containers_ContainerId", + column: x => x.ContainerId, + principalTable: "Containers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_LogEvents_Servers_ServerId", + column: x => x.ServerId, + principalTable: "Servers", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Metrics", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Timestamp = table.Column(type: "datetime(6)", nullable: false), + Type = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Value = table.Column(type: "double", nullable: false), + ServerId = table.Column(type: "int", nullable: true), + ContainerId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Metrics", x => x.Id); + table.ForeignKey( + name: "FK_Metrics_Containers_ContainerId", + column: x => x.ContainerId, + principalTable: "Containers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Metrics_Servers_ServerId", + column: x => x.ServerId, + principalTable: "Servers", + principalColumn: "Id"); + }) + .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", + column: "ImageId"); + + migrationBuilder.CreateIndex( + name: "IX_Containers_TagId", + table: "Containers", + column: "TagId"); + + migrationBuilder.CreateIndex( + name: "IX_LogEvents_ContainerId", + table: "LogEvents", + column: "ContainerId"); + + migrationBuilder.CreateIndex( + name: "IX_LogEvents_ServerId", + table: "LogEvents", + column: "ServerId"); + + migrationBuilder.CreateIndex( + name: "IX_Metrics_ContainerId", + table: "Metrics", + column: "ContainerId"); + + migrationBuilder.CreateIndex( + name: "IX_Metrics_ServerId", + 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", + table: "Servers", + column: "TagId", + principalTable: "Tags", + principalColumn: "Id"); + } + + /// + 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.DropIndex( + name: "IX_Containers_ImageId", + table: "Containers"); + + migrationBuilder.DropIndex( + name: "IX_Containers_TagId", + table: "Containers"); + + migrationBuilder.DropColumn( + name: "TagId", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "ImageId", + table: "Containers"); + + migrationBuilder.DropColumn( + name: "TagId", + table: "Containers"); + } + } +} diff --git a/Watcher/Migrations/AppDbContextModelSnapshot.cs b/Watcher/Migrations/AppDbContextModelSnapshot.cs index e1ea63b..7a6f33f 100644 --- a/Watcher/Migrations/AppDbContextModelSnapshot.cs +++ b/Watcher/Migrations/AppDbContextModelSnapshot.cs @@ -32,6 +32,9 @@ namespace Watcher.Migrations .IsRequired() .HasColumnType("longtext"); + b.Property("ImageId") + .HasColumnType("int"); + b.Property("Name") .IsRequired() .HasColumnType("longtext"); @@ -40,14 +43,225 @@ namespace Watcher.Migrations .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/Models/Image.cs b/Watcher/Models/Image.cs new file mode 100644 index 0000000..57f27d3 --- /dev/null +++ b/Watcher/Models/Image.cs @@ -0,0 +1,10 @@ +namespace Watcher.Models; + +public class Image +{ + public int Id { get; set; } + public string? Name { get; set; } // z.B. "nginx", "myapp" + public string? Tag { get; set; } // z.B. "latest", "v1.2.3" + + public List Containers { get; set; } = new(); +} diff --git a/Watcher/Models/LogEvent.cs b/Watcher/Models/LogEvent.cs new file mode 100644 index 0000000..2de7fb6 --- /dev/null +++ b/Watcher/Models/LogEvent.cs @@ -0,0 +1,15 @@ +namespace Watcher.Models; + +public class LogEvent +{ + public int Id { get; set; } + public DateTime Timestamp { get; set; } + public string? Message { get; set; } + public string? Level { get; set; } // Info, Warning, Error + + public int? ServerId { get; set; } + public Server? Server { get; set; } + + public int? ContainerId { get; set; } + public Container? Container { get; set; } +} diff --git a/Watcher/Models/Metric.cs b/Watcher/Models/Metric.cs new file mode 100644 index 0000000..e069057 --- /dev/null +++ b/Watcher/Models/Metric.cs @@ -0,0 +1,16 @@ +namespace Watcher.Models; + +public class Metric +{ + public int Id { get; set; } + public DateTime Timestamp { get; set; } + + public string? Type { get; set; } // z.B. "CPU", "RAM", "Disk", "Network" + public double Value { get; set; } + + public int? ServerId { get; set; } + public Server? Server { get; set; } + + public int? ContainerId { get; set; } + public Container? Container { get; set; } +} diff --git a/Watcher/Models/Tag.cs b/Watcher/Models/Tag.cs new file mode 100644 index 0000000..9bc8445 --- /dev/null +++ b/Watcher/Models/Tag.cs @@ -0,0 +1,10 @@ +namespace Watcher.Models; + +public class Tag +{ + public int Id { get; set; } + public string? Name { get; set; } + + public List? Servers { get; set; } + public List? Containers { get; set; } +} diff --git a/Watcher/Models/User.cs b/Watcher/Models/User.cs new file mode 100644 index 0000000..81395b9 --- /dev/null +++ b/Watcher/Models/User.cs @@ -0,0 +1,8 @@ +namespace Watcher.Models; + +public class User +{ + public int Id { get; set; } + public string? PocketId { get; set; } // z.B. externe ID vom PocketID-Login + public string Role { get; set; } = "User"; // "Admin", "Viewer", etc. +}