feat: add user db model & migrations
This commit is contained in:
parent
210d299f0e
commit
352a5c89ba
@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DTO" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
11
DatabaseModels/Plain/ScoreboardRecord.cs
Normal file
11
DatabaseModels/Plain/ScoreboardRecord.cs
Normal file
@ -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; }
|
||||
}
|
12
DatabaseModels/Plain/User.cs
Normal file
12
DatabaseModels/Plain/User.cs
Normal file
@ -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<ScoreboardRecord> ScoreboardRecords { get; set; } = 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; }
|
||||
}
|
@ -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<ServerDbContext> options) : base(options) { }
|
||||
|
||||
public DbSet<User> Users { get; set; } = null!;
|
||||
public DbSet<ScoreboardRecord> Scoreboard { get; set; } = null!;
|
||||
}
|
85
Server/Migrations/20220716101730_User.Designer.cs
generated
Normal file
85
Server/Migrations/20220716101730_User.Designer.cs
generated
Normal file
@ -0,0 +1,85 @@
|
||||
// <auto-generated />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("PostTime")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Score")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Scoreboard");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseModels.Plain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PasswordSalt")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("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
|
||||
}
|
||||
}
|
||||
}
|
106
Server/Migrations/20220716101730_User.cs
Normal file
106
Server/Migrations/20220716101730_User.cs
Normal file
@ -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<int>(
|
||||
name: "Id",
|
||||
table: "Scoreboard",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0)
|
||||
.Annotation("Sqlite:Autoincrement", true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
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<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Username = table.Column<string>(type: "TEXT", nullable: false),
|
||||
PasswordHash = table.Column<string>(type: "TEXT", nullable: false),
|
||||
PasswordSalt = table.Column<string>(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<string>(
|
||||
name: "Username",
|
||||
table: "Scoreboard",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_Scoreboard",
|
||||
table: "Scoreboard",
|
||||
column: "Username");
|
||||
}
|
||||
}
|
||||
}
|
@ -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<string>("Username")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("PostTime")
|
||||
.HasColumnType("TEXT");
|
||||
@ -28,10 +29,54 @@ namespace Server.Migrations
|
||||
b.Property<int>("Score")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Username");
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Scoreboard");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseModels.Plain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PasswordSalt")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user