Add the PageContent table (entity, DbContext, migration, model snapshot)

This commit is contained in:
Francesco Lorenzo D'Amico
2026-09-11 13:29:15 +02:00
parent ea14d9208e
commit 776d62a724
5 changed files with 195 additions and 4 deletions
@@ -1,9 +1,21 @@
using Microsoft.EntityFrameworkCore;
using BewerbungsSeite.Models;
namespace BewerbungsSeite.Data;
public class RazorPagesMovieContext(DbContextOptions<RazorPagesMovieContext> options) : DbContext(options)
{
public DbSet<BewerbungsSeite.Models.AdminUser> AdminUser { get; set; } = default!;
public DbSet<BewerbungsSeite.Models.ContactMessage> ContactMessage { get; set; } = default!;
}
public DbSet<AdminUser> AdminUser { get; set; } = default!;
public DbSet<ContactMessage> ContactMessage { get; set; } = default!;
public DbSet<PageContentEntity> PageContent { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Es gibt genau eine Zeile mit fester Id, deshalb keine Identity-Spalte.
modelBuilder.Entity<PageContentEntity>()
.Property(p => p.Id)
.ValueGeneratedNever();
}
}
@@ -0,0 +1,108 @@
// <auto-generated />
using System;
using BewerbungsSeite.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BewerbungsSeite.Migrations
{
[DbContext(typeof(RazorPagesMovieContext))]
[Migration("20260909095802_AddPageContent")]
partial class AddPageContent
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.28")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BewerbungsSeite.Models.AdminUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.HasKey("Id");
b.ToTable("AdminUser");
});
modelBuilder.Entity("BewerbungsSeite.Models.ContactMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("Message")
.IsRequired()
.HasMaxLength(5000)
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<bool>("NotificationSent")
.HasColumnType("bit");
b.Property<string>("Phone")
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<DateTime>("SentAt")
.HasColumnType("datetime2");
b.Property<string>("Subject")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.HasKey("Id");
b.ToTable("ContactMessage");
});
modelBuilder.Entity("BewerbungsSeite.Models.PageContentEntity", b =>
{
b.Property<int>("Id")
.HasColumnType("int");
b.Property<byte[]>("Content")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("PageContent");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,35 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BewerbungsSeite.Migrations
{
/// <inheritdoc />
public partial class AddPageContent : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PageContent",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false),
Content = table.Column<byte[]>(type: "varbinary(max)", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PageContent", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PageContent");
}
}
}
@@ -1,10 +1,10 @@
// <auto-generated />
using System;
using BewerbungsSeite.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using BewerbungsSeite.Data;
#nullable disable
@@ -82,6 +82,23 @@ namespace BewerbungsSeite.Migrations
b.ToTable("ContactMessage");
});
modelBuilder.Entity("BewerbungsSeite.Models.PageContentEntity", b =>
{
b.Property<int>("Id")
.HasColumnType("int");
b.Property<byte[]>("Content")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("PageContent");
});
#pragma warning restore 612, 618
}
}
@@ -0,0 +1,19 @@
namespace BewerbungsSeite.Models;
/// <summary>
/// Speicherzeile fuer den gesamten Seiteninhalt. Es existiert genau ein
/// Datensatz mit <see cref="SingletonId"/>; der Inhalt liegt serialisiert
/// als UTF-8-JSON im Feld <see cref="Content"/>.
/// </summary>
public class PageContentEntity
{
/// <summary>Feste Id des einzigen Datensatzes.</summary>
public const int SingletonId = 1;
public int Id { get; set; }
public byte[] Content { get; set; } = Array.Empty<byte>();
/// <summary>Zeitpunkt der letzten Speicherung (UTC).</summary>
public DateTime UpdatedAt { get; set; }
}