diff --git a/DatabaseModels/DatabaseModels.csproj b/DatabaseModels/DatabaseModels.csproj
index eb2460e..2437130 100644
--- a/DatabaseModels/DatabaseModels.csproj
+++ b/DatabaseModels/DatabaseModels.csproj
@@ -6,4 +6,8 @@
enable
+
+
+
+
diff --git a/DatabaseModels/Plain/ScoreboardRecord.cs b/DatabaseModels/Plain/ScoreboardRecord.cs
new file mode 100644
index 0000000..965c379
--- /dev/null
+++ b/DatabaseModels/Plain/ScoreboardRecord.cs
@@ -0,0 +1,11 @@
+namespace DatabaseModels.Plain;
+
+public class ScoreboardRecord
+{
+ public int Id { get; set; }
+
+ public int Score { get; set; }
+ public DateTime PostTime { get; set; }
+
+ public User User { get; set; }
+}
\ No newline at end of file
diff --git a/DatabaseModels/Plain/User.cs b/DatabaseModels/Plain/User.cs
new file mode 100644
index 0000000..49a1f6e
--- /dev/null
+++ b/DatabaseModels/Plain/User.cs
@@ -0,0 +1,12 @@
+namespace DatabaseModels.Plain;
+
+public class User
+{
+ public int Id { get; set; }
+
+ public string Username { get; set; } = null!;
+ public string PasswordHash { get; set; } = null!;
+ public string PasswordSalt { get; set; } = null!;
+
+ public ICollection ScoreboardRecords { get; set; } = null!;
+}
\ No newline at end of file
diff --git a/DatabaseModels/ScoreboardRecord.cs b/DatabaseModels/ScoreboardRecord.cs
deleted file mode 100644
index 10c91ab..0000000
--- a/DatabaseModels/ScoreboardRecord.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System.ComponentModel.DataAnnotations;
-
-namespace DatabaseModels;
-
-public class ScoreboardRecord
-{
- [Key]
- public string Username { get; set; }
- public int Score { get; set; }
-
- public DateTime PostTime { get; set; }
-}
\ No newline at end of file
diff --git a/Server/Data/ServerDbContext.cs b/Server/Data/ServerDbContext.cs
index a684580..13285a0 100644
--- a/Server/Data/ServerDbContext.cs
+++ b/Server/Data/ServerDbContext.cs
@@ -1,4 +1,4 @@
-using DatabaseModels;
+using DatabaseModels.Plain;
using Microsoft.EntityFrameworkCore;
namespace Server.Data;
@@ -7,5 +7,6 @@ public class ServerDbContext : DbContext
{
public ServerDbContext(DbContextOptions options) : base(options) { }
+ public DbSet Users { get; set; } = null!;
public DbSet Scoreboard { get; set; } = null!;
}
\ No newline at end of file
diff --git a/Server/Migrations/20220716101730_User.Designer.cs b/Server/Migrations/20220716101730_User.Designer.cs
new file mode 100644
index 0000000..53ae3e7
--- /dev/null
+++ b/Server/Migrations/20220716101730_User.Designer.cs
@@ -0,0 +1,85 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Server.Data;
+
+#nullable disable
+
+namespace Server.Migrations
+{
+ [DbContext(typeof(ServerDbContext))]
+ [Migration("20220716101730_User")]
+ partial class User
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "6.0.6");
+
+ modelBuilder.Entity("DatabaseModels.Plain.ScoreboardRecord", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("PostTime")
+ .HasColumnType("TEXT");
+
+ b.Property("Score")
+ .HasColumnType("INTEGER");
+
+ b.Property("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Scoreboard");
+ });
+
+ modelBuilder.Entity("DatabaseModels.Plain.User", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("PasswordHash")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("PasswordSalt")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Username")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Users");
+ });
+
+ modelBuilder.Entity("DatabaseModels.Plain.ScoreboardRecord", b =>
+ {
+ b.HasOne("DatabaseModels.Plain.User", "User")
+ .WithMany("ScoreboardRecords")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("DatabaseModels.Plain.User", b =>
+ {
+ b.Navigation("ScoreboardRecords");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Server/Migrations/20220716101730_User.cs b/Server/Migrations/20220716101730_User.cs
new file mode 100644
index 0000000..7175e6a
--- /dev/null
+++ b/Server/Migrations/20220716101730_User.cs
@@ -0,0 +1,106 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace Server.Migrations
+{
+ public partial class User : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropPrimaryKey(
+ name: "PK_Scoreboard",
+ table: "Scoreboard");
+
+ migrationBuilder.DropColumn(
+ name: "Username",
+ table: "Scoreboard");
+
+ migrationBuilder.AddColumn(
+ name: "Id",
+ table: "Scoreboard",
+ type: "INTEGER",
+ nullable: false,
+ defaultValue: 0)
+ .Annotation("Sqlite:Autoincrement", true);
+
+ migrationBuilder.AddColumn(
+ name: "UserId",
+ table: "Scoreboard",
+ type: "INTEGER",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddPrimaryKey(
+ name: "PK_Scoreboard",
+ table: "Scoreboard",
+ column: "Id");
+
+ migrationBuilder.CreateTable(
+ name: "Users",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Username = table.Column(type: "TEXT", nullable: false),
+ PasswordHash = table.Column(type: "TEXT", nullable: false),
+ PasswordSalt = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Users", x => x.Id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Scoreboard_UserId",
+ table: "Scoreboard",
+ column: "UserId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Scoreboard_Users_UserId",
+ table: "Scoreboard",
+ column: "UserId",
+ principalTable: "Users",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Scoreboard_Users_UserId",
+ table: "Scoreboard");
+
+ migrationBuilder.DropTable(
+ name: "Users");
+
+ migrationBuilder.DropPrimaryKey(
+ name: "PK_Scoreboard",
+ table: "Scoreboard");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Scoreboard_UserId",
+ table: "Scoreboard");
+
+ migrationBuilder.DropColumn(
+ name: "Id",
+ table: "Scoreboard");
+
+ migrationBuilder.DropColumn(
+ name: "UserId",
+ table: "Scoreboard");
+
+ migrationBuilder.AddColumn(
+ name: "Username",
+ table: "Scoreboard",
+ type: "TEXT",
+ nullable: false,
+ defaultValue: "");
+
+ migrationBuilder.AddPrimaryKey(
+ name: "PK_Scoreboard",
+ table: "Scoreboard",
+ column: "Username");
+ }
+ }
+}
diff --git a/Server/Migrations/ServerDbContextModelSnapshot.cs b/Server/Migrations/ServerDbContextModelSnapshot.cs
index c7435ec..6a38932 100644
--- a/Server/Migrations/ServerDbContextModelSnapshot.cs
+++ b/Server/Migrations/ServerDbContextModelSnapshot.cs
@@ -17,10 +17,11 @@ namespace Server.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.6");
- modelBuilder.Entity("DatabaseModels.ScoreboardRecord", b =>
+ modelBuilder.Entity("DatabaseModels.Plain.ScoreboardRecord", b =>
{
- b.Property("Username")
- .HasColumnType("TEXT");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
b.Property("PostTime")
.HasColumnType("TEXT");
@@ -28,10 +29,54 @@ namespace Server.Migrations
b.Property("Score")
.HasColumnType("INTEGER");
- b.HasKey("Username");
+ b.Property("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
b.ToTable("Scoreboard");
});
+
+ modelBuilder.Entity("DatabaseModels.Plain.User", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("PasswordHash")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("PasswordSalt")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Username")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Users");
+ });
+
+ modelBuilder.Entity("DatabaseModels.Plain.ScoreboardRecord", b =>
+ {
+ b.HasOne("DatabaseModels.Plain.User", "User")
+ .WithMany("ScoreboardRecords")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("DatabaseModels.Plain.User", b =>
+ {
+ b.Navigation("ScoreboardRecords");
+ });
#pragma warning restore 612, 618
}
}