add migration to make client pair UIDs PK

This commit is contained in:
Stanley Dimant
2022-07-13 02:43:24 +02:00
parent e70f564162
commit 4a83a7dba0
5 changed files with 328 additions and 15 deletions

View File

@@ -24,6 +24,9 @@ namespace MareSynchronosServer.Data
modelBuilder.Entity<User>().ToTable("Users"); modelBuilder.Entity<User>().ToTable("Users");
modelBuilder.Entity<FileCache>().ToTable("FileCaches"); modelBuilder.Entity<FileCache>().ToTable("FileCaches");
modelBuilder.Entity<ClientPair>().ToTable("ClientPairs"); modelBuilder.Entity<ClientPair>().ToTable("ClientPairs");
modelBuilder.Entity<ClientPair>().HasKey(u => new { u.UserUID, u.OtherUserUID });
modelBuilder.Entity<ClientPair>().HasIndex(c => c.UserUID);
modelBuilder.Entity<ClientPair>().HasIndex(c => c.OtherUserUID);
modelBuilder.Entity<ForbiddenUploadEntry>().ToTable("ForbiddenUploadEntries"); modelBuilder.Entity<ForbiddenUploadEntry>().ToTable("ForbiddenUploadEntries");
modelBuilder.Entity<Banned>().ToTable("BannedUsers"); modelBuilder.Entity<Banned>().ToTable("BannedUsers");
} }

View File

@@ -0,0 +1,175 @@
// <auto-generated />
using System;
using MareSynchronosServer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace MareSynchronosServer.Migrations
{
[DbContext(typeof(MareDbContext))]
[Migration("20220712102941_ClientPairKey")]
partial class ClientPairKey
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
{
b.Property<string>("CharacterIdentification")
.HasColumnType("nvarchar(450)");
b.Property<string>("Reason")
.HasColumnType("nvarchar(max)");
b.Property<byte[]>("Timestamp")
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.HasKey("CharacterIdentification");
b.ToTable("BannedUsers", (string)null);
});
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
{
b.Property<string>("UserUID")
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("OtherUserUID")
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<bool>("AllowReceivingMessages")
.HasColumnType("bit");
b.Property<bool>("IsPaused")
.HasColumnType("bit");
b.Property<byte[]>("Timestamp")
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.HasKey("UserUID", "OtherUserUID");
b.HasIndex("OtherUserUID");
b.HasIndex("UserUID");
b.ToTable("ClientPairs", (string)null);
});
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
{
b.Property<string>("Hash")
.HasMaxLength(40)
.HasColumnType("nvarchar(40)");
b.Property<byte[]>("Timestamp")
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<bool>("Uploaded")
.HasColumnType("bit");
b.Property<string>("UploaderUID")
.HasColumnType("nvarchar(10)");
b.HasKey("Hash");
b.HasIndex("UploaderUID");
b.ToTable("FileCaches", (string)null);
});
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
{
b.Property<string>("Hash")
.HasColumnType("nvarchar(450)");
b.Property<string>("ForbiddenBy")
.HasColumnType("nvarchar(max)");
b.Property<byte[]>("Timestamp")
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.HasKey("Hash");
b.ToTable("ForbiddenUploadEntries", (string)null);
});
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
{
b.Property<string>("UID")
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("CharacterIdentification")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsAdmin")
.HasColumnType("bit");
b.Property<bool>("IsModerator")
.HasColumnType("bit");
b.Property<string>("SecretKey")
.HasColumnType("nvarchar(max)");
b.Property<byte[]>("Timestamp")
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.HasKey("UID");
b.ToTable("Users", (string)null);
});
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
{
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
.WithMany()
.HasForeignKey("OtherUserUID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MareSynchronosServer.Models.User", "User")
.WithMany()
.HasForeignKey("UserUID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("OtherUser");
b.Navigation("User");
});
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
{
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
.WithMany()
.HasForeignKey("UploaderUID");
b.Navigation("Uploader");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,132 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MareSynchronosServer.Migrations
{
public partial class ClientPairKey : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ClientPairs_Users_OtherUserUID",
table: "ClientPairs");
migrationBuilder.DropForeignKey(
name: "FK_ClientPairs_Users_UserUID",
table: "ClientPairs");
migrationBuilder.DropPrimaryKey(
name: "PK_ClientPairs",
table: "ClientPairs");
migrationBuilder.DropColumn(
name: "Id",
table: "ClientPairs");
migrationBuilder.AlterColumn<string>(
name: "UserUID",
table: "ClientPairs",
type: "nvarchar(10)",
maxLength: 10,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "nvarchar(10)",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "OtherUserUID",
table: "ClientPairs",
type: "nvarchar(10)",
maxLength: 10,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "nvarchar(10)",
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_ClientPairs",
table: "ClientPairs",
columns: new[] { "UserUID", "OtherUserUID" });
migrationBuilder.AddForeignKey(
name: "FK_ClientPairs_Users_OtherUserUID",
table: "ClientPairs",
column: "OtherUserUID",
principalTable: "Users",
principalColumn: "UID",
onDelete: ReferentialAction.NoAction);
migrationBuilder.AddForeignKey(
name: "FK_ClientPairs_Users_UserUID",
table: "ClientPairs",
column: "UserUID",
principalTable: "Users",
principalColumn: "UID",
onDelete: ReferentialAction.NoAction);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ClientPairs_Users_OtherUserUID",
table: "ClientPairs");
migrationBuilder.DropForeignKey(
name: "FK_ClientPairs_Users_UserUID",
table: "ClientPairs");
migrationBuilder.DropPrimaryKey(
name: "PK_ClientPairs",
table: "ClientPairs");
migrationBuilder.AlterColumn<string>(
name: "OtherUserUID",
table: "ClientPairs",
type: "nvarchar(10)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(10)",
oldMaxLength: 10);
migrationBuilder.AlterColumn<string>(
name: "UserUID",
table: "ClientPairs",
type: "nvarchar(10)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(10)",
oldMaxLength: 10);
migrationBuilder.AddColumn<int>(
name: "Id",
table: "ClientPairs",
type: "int",
nullable: false,
defaultValue: 0)
.Annotation("SqlServer:Identity", "1, 1");
migrationBuilder.AddPrimaryKey(
name: "PK_ClientPairs",
table: "ClientPairs",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_ClientPairs_Users_OtherUserUID",
table: "ClientPairs",
column: "OtherUserUID",
principalTable: "Users",
principalColumn: "UID");
migrationBuilder.AddForeignKey(
name: "FK_ClientPairs_Users_UserUID",
table: "ClientPairs",
column: "UserUID",
principalTable: "Users",
principalColumn: "UID");
}
}
}

View File

@@ -42,11 +42,13 @@ namespace MareSynchronosServer.Migrations
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b => modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
{ {
b.Property<int>("Id") b.Property<string>("UserUID")
.ValueGeneratedOnAdd() .HasMaxLength(10)
.HasColumnType("int"); .HasColumnType("nvarchar(10)");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); b.Property<string>("OtherUserUID")
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<bool>("AllowReceivingMessages") b.Property<bool>("AllowReceivingMessages")
.HasColumnType("bit"); .HasColumnType("bit");
@@ -54,18 +56,12 @@ namespace MareSynchronosServer.Migrations
b.Property<bool>("IsPaused") b.Property<bool>("IsPaused")
.HasColumnType("bit"); .HasColumnType("bit");
b.Property<string>("OtherUserUID")
.HasColumnType("nvarchar(10)");
b.Property<byte[]>("Timestamp") b.Property<byte[]>("Timestamp")
.IsConcurrencyToken() .IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate() .ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion"); .HasColumnType("rowversion");
b.Property<string>("UserUID") b.HasKey("UserUID", "OtherUserUID");
.HasColumnType("nvarchar(10)");
b.HasKey("Id");
b.HasIndex("OtherUserUID"); b.HasIndex("OtherUserUID");
@@ -77,7 +73,7 @@ namespace MareSynchronosServer.Migrations
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b => modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
{ {
b.Property<string>("Hash") b.Property<string>("Hash")
.HasMaxLength(20) .HasMaxLength(40)
.HasColumnType("nvarchar(40)"); .HasColumnType("nvarchar(40)");
b.Property<byte[]>("Timestamp") b.Property<byte[]>("Timestamp")
@@ -148,11 +144,15 @@ namespace MareSynchronosServer.Migrations
{ {
b.HasOne("MareSynchronosServer.Models.User", "OtherUser") b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
.WithMany() .WithMany()
.HasForeignKey("OtherUserUID"); .HasForeignKey("OtherUserUID")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("MareSynchronosServer.Models.User", "User") b.HasOne("MareSynchronosServer.Models.User", "User")
.WithMany() .WithMany()
.HasForeignKey("UserUID"); .HasForeignKey("UserUID")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("OtherUser"); b.Navigation("OtherUser");

View File

@@ -4,8 +4,11 @@ namespace MareSynchronosServer.Models
{ {
public class ClientPair public class ClientPair
{ {
public int Id { get; set; } [MaxLength(10)]
public string UserUID { get; set; }
public User User { get; set; } public User User { get; set; }
[MaxLength(10)]
public string OtherUserUID { get; set; }
public User OtherUser { get; set; } public User OtherUser { get; set; }
public bool IsPaused { get; set; } public bool IsPaused { get; set; }
public bool AllowReceivingMessages { get; set; } = false; public bool AllowReceivingMessages { get; set; } = false;