diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index eb55e9f..7e80593 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -18,7 +18,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Server/DB/Migrations/20231114200451_AddAdditionalIndices.Designer.cs b/Server/DB/Migrations/20231114200451_AddAdditionalIndices.Designer.cs new file mode 100644 index 0000000..cffcc62 --- /dev/null +++ b/Server/DB/Migrations/20231114200451_AddAdditionalIndices.Designer.cs @@ -0,0 +1,333 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Server.DB; + +#nullable disable + +namespace Server.DB.Migrations +{ + [DbContext(typeof(WonderkingContext))] + [Migration("20231114200451_AddAdditionalIndices")] + partial class AddAdditionalIndices + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Server.DB.Documents.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("Password") + .HasColumnType("bytea"); + + b.Property("PermissionLevel") + .HasColumnType("smallint"); + + b.Property("Salt") + .HasColumnType("bytea"); + + b.Property("Username") + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("Server.DB.Documents.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccountId") + .HasColumnType("uuid"); + + b.Property("Experience") + .HasColumnType("bigint"); + + b.Property("Gender") + .HasColumnType("smallint"); + + b.Property("GuildId") + .HasColumnType("uuid"); + + b.Property("Health") + .HasColumnType("integer"); + + b.Property("LastXCoordinate") + .HasColumnType("smallint"); + + b.Property("LastYCoordinate") + .HasColumnType("smallint"); + + b.Property("Level") + .HasColumnType("smallint"); + + b.Property("Mana") + .HasColumnType("integer"); + + b.Property("MapId") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("varchar(20)"); + + b.Property("PvPLevel") + .HasColumnType("smallint"); + + b.Property("ServerId") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("GuildId"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("Server.DB.Documents.Guild", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Notice") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Guild"); + }); + + modelBuilder.Entity("Server.DB.Documents.GuildMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CharacterId") + .HasColumnType("uuid"); + + b.Property("GuildId") + .HasColumnType("uuid"); + + b.Property("Rank") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("GuildId"); + + b.ToTable("GuildMember"); + }); + + modelBuilder.Entity("Server.DB.Documents.InventoryItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AddOption") + .HasColumnType("smallint"); + + b.Property("AddOption2") + .HasColumnType("smallint"); + + b.Property("AddOption3") + .HasColumnType("smallint"); + + b.Property("CharacterId") + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ItemId") + .HasColumnType("integer"); + + b.Property("ItemType") + .HasColumnType("smallint"); + + b.Property("Level") + .HasColumnType("smallint"); + + b.Property("Option") + .HasColumnType("smallint"); + + b.Property("Option2") + .HasColumnType("smallint"); + + b.Property("Option3") + .HasColumnType("smallint"); + + b.Property("Rarity") + .HasColumnType("smallint"); + + b.Property("Slot") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.ToTable("InventoryItem"); + }); + + modelBuilder.Entity("Server.DB.Documents.Character", b => + { + b.HasOne("Server.DB.Documents.Account", "Account") + .WithMany("Characters") + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.DB.Documents.Guild", "Guild") + .WithMany() + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("Wonderking.Packets.Outgoing.BaseStats", "BaseStats", b1 => + { + b1.Property("CharacterId") + .HasColumnType("uuid"); + + b1.Property("Dexterity") + .HasColumnType("smallint"); + + b1.Property("Intelligence") + .HasColumnType("smallint"); + + b1.Property("Luck") + .HasColumnType("smallint"); + + b1.Property("Strength") + .HasColumnType("smallint"); + + b1.Property("Vitality") + .HasColumnType("smallint"); + + b1.Property("Wisdom") + .HasColumnType("smallint"); + + b1.HasKey("CharacterId"); + + b1.ToTable("Characters"); + + b1.WithOwner() + .HasForeignKey("CharacterId"); + }); + + b.OwnsOne("Wonderking.Packets.Outgoing.JobData", "JobData", b1 => + { + b1.Property("CharacterId") + .HasColumnType("uuid"); + + b1.Property("FirstJob") + .HasColumnType("smallint"); + + b1.Property("FourthJob") + .HasColumnType("smallint"); + + b1.Property("SecondJob") + .HasColumnType("smallint"); + + b1.Property("ThirdJob") + .HasColumnType("smallint"); + + b1.HasKey("CharacterId"); + + b1.ToTable("Characters"); + + b1.WithOwner() + .HasForeignKey("CharacterId"); + }); + + b.Navigation("Account"); + + b.Navigation("BaseStats"); + + b.Navigation("Guild"); + + b.Navigation("JobData"); + }); + + modelBuilder.Entity("Server.DB.Documents.GuildMember", b => + { + b.HasOne("Server.DB.Documents.Character", "Character") + .WithMany() + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.DB.Documents.Guild", "Guild") + .WithMany("GuildMembers") + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + + b.Navigation("Guild"); + }); + + modelBuilder.Entity("Server.DB.Documents.InventoryItem", b => + { + b.HasOne("Server.DB.Documents.Character", "Character") + .WithMany("InventoryItems") + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + }); + + modelBuilder.Entity("Server.DB.Documents.Account", b => + { + b.Navigation("Characters"); + }); + + modelBuilder.Entity("Server.DB.Documents.Character", b => + { + b.Navigation("InventoryItems"); + }); + + modelBuilder.Entity("Server.DB.Documents.Guild", b => + { + b.Navigation("GuildMembers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Server/DB/Migrations/20231114200451_AddAdditionalIndices.cs b/Server/DB/Migrations/20231114200451_AddAdditionalIndices.cs new file mode 100644 index 0000000..f1785e0 --- /dev/null +++ b/Server/DB/Migrations/20231114200451_AddAdditionalIndices.cs @@ -0,0 +1,262 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Server.DB.Migrations; + +/// +public partial class AddAdditionalIndices : Migration +{ + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ItemId", + table: "InventoryItem", + type: "integer", + nullable: false, + oldClrType: typeof(short), + oldType: "smallint"); + + migrationBuilder.AddColumn( + name: "BaseStats_Dexterity", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BaseStats_Intelligence", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BaseStats_Luck", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BaseStats_Strength", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BaseStats_Vitality", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BaseStats_Wisdom", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "GuildId", + table: "Characters", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); + + migrationBuilder.AddColumn( + name: "Health", + table: "Characters", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "JobData_FirstJob", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "JobData_FourthJob", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "JobData_SecondJob", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "JobData_ThirdJob", + table: "Characters", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "Mana", + table: "Characters", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Guild", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: true), + Notice = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Guild", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "GuildMember", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + CharacterId = table.Column(type: "uuid", nullable: false), + GuildId = table.Column(type: "uuid", nullable: false), + Rank = table.Column(type: "smallint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GuildMember", x => x.Id); + table.ForeignKey( + name: "FK_GuildMember_Characters_CharacterId", + column: x => x.CharacterId, + principalTable: "Characters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GuildMember_Guild_GuildId", + column: x => x.GuildId, + principalTable: "Guild", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Characters_GuildId", + table: "Characters", + column: "GuildId"); + + migrationBuilder.CreateIndex( + name: "IX_Characters_Name", + table: "Characters", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Accounts_Username", + table: "Accounts", + column: "Username", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_GuildMember_CharacterId", + table: "GuildMember", + column: "CharacterId"); + + migrationBuilder.CreateIndex( + name: "IX_GuildMember_GuildId", + table: "GuildMember", + column: "GuildId"); + + migrationBuilder.AddForeignKey( + name: "FK_Characters_Guild_GuildId", + table: "Characters", + column: "GuildId", + principalTable: "Guild", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Characters_Guild_GuildId", + table: "Characters"); + + migrationBuilder.DropTable( + name: "GuildMember"); + + migrationBuilder.DropTable( + name: "Guild"); + + migrationBuilder.DropIndex( + name: "IX_Characters_GuildId", + table: "Characters"); + + migrationBuilder.DropIndex( + name: "IX_Characters_Name", + table: "Characters"); + + migrationBuilder.DropIndex( + name: "IX_Accounts_Username", + table: "Accounts"); + + migrationBuilder.DropColumn( + name: "BaseStats_Dexterity", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "BaseStats_Intelligence", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "BaseStats_Luck", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "BaseStats_Strength", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "BaseStats_Vitality", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "BaseStats_Wisdom", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "GuildId", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "Health", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "JobData_FirstJob", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "JobData_FourthJob", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "JobData_SecondJob", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "JobData_ThirdJob", + table: "Characters"); + + migrationBuilder.DropColumn( + name: "Mana", + table: "Characters"); + + migrationBuilder.AlterColumn( + name: "ItemId", + table: "InventoryItem", + type: "smallint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + } +} diff --git a/Server/DB/Migrations/WonderkingContextModelSnapshot.cs b/Server/DB/Migrations/WonderkingContextModelSnapshot.cs index ab1f034..a40cde7 100644 --- a/Server/DB/Migrations/WonderkingContextModelSnapshot.cs +++ b/Server/DB/Migrations/WonderkingContextModelSnapshot.cs @@ -17,7 +17,7 @@ namespace Server.DB.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("ProductVersion", "8.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -45,6 +45,9 @@ namespace Server.DB.Migrations b.HasKey("Id"); + b.HasIndex("Username") + .IsUnique(); + b.ToTable("Accounts"); }); @@ -63,6 +66,12 @@ namespace Server.DB.Migrations b.Property("Gender") .HasColumnType("smallint"); + b.Property("GuildId") + .HasColumnType("uuid"); + + b.Property("Health") + .HasColumnType("integer"); + b.Property("LastXCoordinate") .HasColumnType("smallint"); @@ -72,6 +81,9 @@ namespace Server.DB.Migrations b.Property("Level") .HasColumnType("smallint"); + b.Property("Mana") + .HasColumnType("integer"); + b.Property("MapId") .HasColumnType("integer"); @@ -88,9 +100,55 @@ namespace Server.DB.Migrations b.HasIndex("AccountId"); + b.HasIndex("GuildId"); + + b.HasIndex("Name") + .IsUnique(); + b.ToTable("Characters"); }); + modelBuilder.Entity("Server.DB.Documents.Guild", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Notice") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Guild"); + }); + + modelBuilder.Entity("Server.DB.Documents.GuildMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CharacterId") + .HasColumnType("uuid"); + + b.Property("GuildId") + .HasColumnType("uuid"); + + b.Property("Rank") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("GuildId"); + + b.ToTable("GuildMember"); + }); + modelBuilder.Entity("Server.DB.Documents.InventoryItem", b => { b.Property("Id") @@ -112,8 +170,8 @@ namespace Server.DB.Migrations b.Property("Count") .HasColumnType("integer"); - b.Property("ItemId") - .HasColumnType("smallint"); + b.Property("ItemId") + .HasColumnType("integer"); b.Property("ItemType") .HasColumnType("smallint"); @@ -151,7 +209,94 @@ namespace Server.DB.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("Server.DB.Documents.Guild", "Guild") + .WithMany() + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("Wonderking.Packets.Outgoing.BaseStats", "BaseStats", b1 => + { + b1.Property("CharacterId") + .HasColumnType("uuid"); + + b1.Property("Dexterity") + .HasColumnType("smallint"); + + b1.Property("Intelligence") + .HasColumnType("smallint"); + + b1.Property("Luck") + .HasColumnType("smallint"); + + b1.Property("Strength") + .HasColumnType("smallint"); + + b1.Property("Vitality") + .HasColumnType("smallint"); + + b1.Property("Wisdom") + .HasColumnType("smallint"); + + b1.HasKey("CharacterId"); + + b1.ToTable("Characters"); + + b1.WithOwner() + .HasForeignKey("CharacterId"); + }); + + b.OwnsOne("Wonderking.Packets.Outgoing.JobData", "JobData", b1 => + { + b1.Property("CharacterId") + .HasColumnType("uuid"); + + b1.Property("FirstJob") + .HasColumnType("smallint"); + + b1.Property("FourthJob") + .HasColumnType("smallint"); + + b1.Property("SecondJob") + .HasColumnType("smallint"); + + b1.Property("ThirdJob") + .HasColumnType("smallint"); + + b1.HasKey("CharacterId"); + + b1.ToTable("Characters"); + + b1.WithOwner() + .HasForeignKey("CharacterId"); + }); + b.Navigation("Account"); + + b.Navigation("BaseStats"); + + b.Navigation("Guild"); + + b.Navigation("JobData"); + }); + + modelBuilder.Entity("Server.DB.Documents.GuildMember", b => + { + b.HasOne("Server.DB.Documents.Character", "Character") + .WithMany() + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.DB.Documents.Guild", "Guild") + .WithMany("GuildMembers") + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + + b.Navigation("Guild"); }); modelBuilder.Entity("Server.DB.Documents.InventoryItem", b => @@ -174,6 +319,11 @@ namespace Server.DB.Migrations { b.Navigation("InventoryItems"); }); + + modelBuilder.Entity("Server.DB.Documents.Guild", b => + { + b.Navigation("GuildMembers"); + }); #pragma warning restore 612, 618 } } diff --git a/Server/DB/WonderkingContext.cs b/Server/DB/WonderkingContext.cs index 94efe19..af4e97e 100644 --- a/Server/DB/WonderkingContext.cs +++ b/Server/DB/WonderkingContext.cs @@ -29,6 +29,7 @@ public class WonderkingContext : DbContext modelBuilder.Entity(builder => { builder.Property(b => b.Username).HasColumnType("varchar(20)"); + builder.HasIndex(b => b.Username).IsUnique(); builder.Property(b => b.Password).HasColumnType("bytea"); builder.Property(b => b.Salt).HasColumnType("bytea"); builder.HasKey(b => b.Id); @@ -38,6 +39,7 @@ public class WonderkingContext : DbContext { builder.HasKey(c => c.Id); builder.Property(c => c.Name).HasColumnType("varchar(20)"); + builder.HasIndex(c => c.Name).IsUnique(); builder.HasMany(e => e.InventoryItems).WithOne(e => e.Character) .HasForeignKey(e => e.CharacterId).IsRequired(); builder.OwnsOne(p => p.BaseStats); diff --git a/Server/Server.csproj b/Server/Server.csproj index ba239ce..aec1e47 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -66,7 +66,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -77,21 +77,17 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/Wonderking/Wonderking.csproj b/Wonderking/Wonderking.csproj index f41aaad..c1bdf54 100644 --- a/Wonderking/Wonderking.csproj +++ b/Wonderking/Wonderking.csproj @@ -22,7 +22,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive