add database migration to limit UID and Hash max lengths
This commit is contained in:
@@ -158,7 +158,6 @@ namespace MareSynchronosServer.Hubs
|
|||||||
await DbContext.Files.AddAsync(new FileCache()
|
await DbContext.Files.AddAsync(new FileCache()
|
||||||
{
|
{
|
||||||
Hash = file,
|
Hash = file,
|
||||||
LastAccessTime = DateTime.Now,
|
|
||||||
Uploaded = false,
|
Uploaded = false,
|
||||||
Uploader = DbContext.Users.Single(u => u.UID == userId)
|
Uploader = DbContext.Users.Single(u => u.UID == userId)
|
||||||
});
|
});
|
||||||
@@ -225,7 +224,6 @@ namespace MareSynchronosServer.Hubs
|
|||||||
await File.WriteAllBytesAsync(Path.Combine(BasePath, hash), uploadedFile.ToArray());
|
await File.WriteAllBytesAsync(Path.Combine(BasePath, hash), uploadedFile.ToArray());
|
||||||
relatedFile = DbContext.Files.Single(f => f.Hash == hash);
|
relatedFile = DbContext.Files.Single(f => f.Hash == hash);
|
||||||
relatedFile.Uploaded = true;
|
relatedFile.Uploaded = true;
|
||||||
relatedFile.LastAccessTime = DateTime.Now;
|
|
||||||
await DbContext.SaveChangesAsync();
|
await DbContext.SaveChangesAsync();
|
||||||
Logger.LogInformation("File " + hash + " added to DB");
|
Logger.LogInformation("File " + hash + " added to DB");
|
||||||
}
|
}
|
||||||
|
|||||||
175
MareSynchronosServer/MareSynchronosServer/Migrations/20220712082237_SetMaxLengths.Designer.cs
generated
Normal file
175
MareSynchronosServer/MareSynchronosServer/Migrations/20220712082237_SetMaxLengths.Designer.cs
generated
Normal 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("20220712082237_SetMaxLengths")]
|
||||||
|
partial class SetMaxLengths
|
||||||
|
{
|
||||||
|
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<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<bool>("AllowReceivingMessages")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<bool>("IsPaused")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("OtherUserUID")
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Timestamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
|
.HasColumnType("rowversion");
|
||||||
|
|
||||||
|
b.Property<string>("UserUID")
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OtherUserUID");
|
||||||
|
|
||||||
|
b.HasIndex("UserUID");
|
||||||
|
|
||||||
|
b.ToTable("ClientPairs", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Hash")
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.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");
|
||||||
|
|
||||||
|
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserUID");
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace MareSynchronosServer.Migrations
|
||||||
|
{
|
||||||
|
public partial class SetMaxLengths : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "LastAccessTime",
|
||||||
|
table: "FileCaches");
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey("FK_FileCaches_Users_UploaderUID", "FileCaches");
|
||||||
|
migrationBuilder.DropForeignKey("FK_ClientPairs_Users_UserUID", "ClientPairs");
|
||||||
|
migrationBuilder.DropForeignKey("FK_ClientPairs_Users_OtherUserUID", "ClientPairs");
|
||||||
|
migrationBuilder.DropPrimaryKey("PK_FileCaches", "FileCaches");
|
||||||
|
migrationBuilder.DropPrimaryKey("PK_Users", "Users");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UploaderUID",
|
||||||
|
table: "FileCaches",
|
||||||
|
type: "nvarchar(10)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(450)",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Hash",
|
||||||
|
table: "FileCaches",
|
||||||
|
type: "nvarchar(40)",
|
||||||
|
maxLength: 20,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(450)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UserUID",
|
||||||
|
table: "ClientPairs",
|
||||||
|
type: "nvarchar(10)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(450)",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "OtherUserUID",
|
||||||
|
table: "ClientPairs",
|
||||||
|
type: "nvarchar(10)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(450)",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UID",
|
||||||
|
table: "Users",
|
||||||
|
type: "nvarchar(10)",
|
||||||
|
maxLength: 10,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(450)");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey("PK_Users", "Users", "UID");
|
||||||
|
migrationBuilder.AddPrimaryKey("PK_FileCaches", "FileCaches", "Hash");
|
||||||
|
migrationBuilder.AddForeignKey("FK_FileCaches_Users_UploaderUID", "FileCaches", "UploaderUID", "Users");
|
||||||
|
migrationBuilder.AddForeignKey("FK_ClientPairs_Users_UserUID", "ClientPairs", "UserUID", "Users");
|
||||||
|
migrationBuilder.AddForeignKey("FK_ClientPairs_Users_OtherUserUID", "ClientPairs", "UserUID", "Users");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey("FK_FileCaches_Users_UploaderUID", "FileCaches");
|
||||||
|
migrationBuilder.DropForeignKey("FK_ClientPairs_Users_UserUID", "ClientPairs");
|
||||||
|
migrationBuilder.DropForeignKey("FK_ClientPairs_Users_OtherUserUID", "ClientPairs");
|
||||||
|
migrationBuilder.DropPrimaryKey("PK_FileCaches", "FileCaches");
|
||||||
|
migrationBuilder.DropPrimaryKey("PK_Users", "Users");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UID",
|
||||||
|
table: "Users",
|
||||||
|
type: "nvarchar(450)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(10)",
|
||||||
|
oldMaxLength: 10);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UploaderUID",
|
||||||
|
table: "FileCaches",
|
||||||
|
type: "nvarchar(450)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(10)",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Hash",
|
||||||
|
table: "FileCaches",
|
||||||
|
type: "nvarchar(450)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(20)",
|
||||||
|
oldMaxLength: 20);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "LastAccessTime",
|
||||||
|
table: "FileCaches",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UserUID",
|
||||||
|
table: "ClientPairs",
|
||||||
|
type: "nvarchar(450)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(10)",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "OtherUserUID",
|
||||||
|
table: "ClientPairs",
|
||||||
|
type: "nvarchar(450)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(10)",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey("PK_Users", "Users", "UID");
|
||||||
|
migrationBuilder.AddPrimaryKey("PK_FileCaches", "FileCaches", "Hash");
|
||||||
|
migrationBuilder.AddForeignKey("FK_FileCaches_Users_UploaderUID", "FileCaches", "UploaderUID", "Users");
|
||||||
|
migrationBuilder.AddForeignKey("FK_ClientPairs_Users_UserUID", "ClientPairs", "UserUID", "Users");
|
||||||
|
migrationBuilder.AddForeignKey("FK_ClientPairs_Users_OtherUserUID", "ClientPairs", "UserUID", "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,7 +55,7 @@ namespace MareSynchronosServer.Migrations
|
|||||||
.HasColumnType("bit");
|
.HasColumnType("bit");
|
||||||
|
|
||||||
b.Property<string>("OtherUserUID")
|
b.Property<string>("OtherUserUID")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
b.Property<byte[]>("Timestamp")
|
b.Property<byte[]>("Timestamp")
|
||||||
.IsConcurrencyToken()
|
.IsConcurrencyToken()
|
||||||
@@ -63,7 +63,7 @@ namespace MareSynchronosServer.Migrations
|
|||||||
.HasColumnType("rowversion");
|
.HasColumnType("rowversion");
|
||||||
|
|
||||||
b.Property<string>("UserUID")
|
b.Property<string>("UserUID")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@@ -77,10 +77,8 @@ namespace MareSynchronosServer.Migrations
|
|||||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Hash")
|
b.Property<string>("Hash")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("nvarchar(40)");
|
||||||
b.Property<DateTime>("LastAccessTime")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<byte[]>("Timestamp")
|
b.Property<byte[]>("Timestamp")
|
||||||
.IsConcurrencyToken()
|
.IsConcurrencyToken()
|
||||||
@@ -91,7 +89,7 @@ namespace MareSynchronosServer.Migrations
|
|||||||
.HasColumnType("bit");
|
.HasColumnType("bit");
|
||||||
|
|
||||||
b.Property<string>("UploaderUID")
|
b.Property<string>("UploaderUID")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
b.HasKey("Hash");
|
b.HasKey("Hash");
|
||||||
|
|
||||||
@@ -121,7 +119,8 @@ namespace MareSynchronosServer.Migrations
|
|||||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("UID")
|
b.Property<string>("UID")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
b.Property<string>("CharacterIdentification")
|
b.Property<string>("CharacterIdentification")
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ namespace MareSynchronosServer.Models
|
|||||||
public class FileCache
|
public class FileCache
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
[MaxLength(40)]
|
||||||
public string Hash { get; set; }
|
public string Hash { get; set; }
|
||||||
public User Uploader { get; set; }
|
public User Uploader { get; set; }
|
||||||
public bool Uploaded { get; set; }
|
public bool Uploaded { get; set; }
|
||||||
public DateTime LastAccessTime { get; set; }
|
|
||||||
[Timestamp]
|
[Timestamp]
|
||||||
public byte[] Timestamp { get; set; }
|
public byte[] Timestamp { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace MareSynchronosServer.Models
|
|||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
|
[MaxLength(10)]
|
||||||
public string UID { get; set; }
|
public string UID { get; set; }
|
||||||
public string SecretKey { get; set; }
|
public string SecretKey { get; set; }
|
||||||
public string CharacterIdentification { get; set; }
|
public string CharacterIdentification { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user