diff --git a/Server/DB/Migrations/20231120162002_FixInventoryItemAsDbset.Designer.cs b/Server/DB/Migrations/20231120162002_FixInventoryItemAsDbset.Designer.cs new file mode 100644 index 0000000..097b08e --- /dev/null +++ b/Server/DB/Migrations/20231120162002_FixInventoryItemAsDbset.Designer.cs @@ -0,0 +1,337 @@ +// +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("20231120162002_FixInventoryItemAsDbset")] + partial class FixInventoryItemAsDbset + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.0") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .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") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex("Id") + .IsUnique(); + + 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") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("PvPLevel") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("GuildId"); + + b.HasIndex("Id") + .IsUnique(); + + 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("Guilds"); + }); + + 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("InventoryTab") + .HasColumnType("smallint"); + + b.Property("ItemId") + .HasColumnType("integer"); + + 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("InventoryItems"); + }); + + modelBuilder.Entity("Server.DB.Documents.Character", b => + { + b.HasOne("Server.DB.Documents.Account", "Account") + .WithMany("Characters") + .HasForeignKey("AccountId"); + + b.HasOne("Server.DB.Documents.Guild", "Guild") + .WithMany() + .HasForeignKey("GuildId"); + + b.OwnsOne("Wonderking.Packets.Outgoing.Data.BaseStats", "BaseStats", b1 => + { + b1.Property("CharacterId") + .HasColumnType("uuid"); + + b1.Property("Dexterity") + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "dexterity"); + + b1.Property("Intelligence") + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "intelligence"); + + b1.Property("Luck") + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "luck"); + + b1.Property("Strength") + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "strength"); + + b1.Property("Vitality") + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "vitality"); + + b1.Property("Wisdom") + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "wisdom"); + + b1.HasKey("CharacterId"); + + b1.ToTable("Characters"); + + b1.WithOwner() + .HasForeignKey("CharacterId"); + }); + + b.OwnsOne("Wonderking.Packets.Outgoing.Data.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"); + + b.HasOne("Server.DB.Documents.Guild", "Guild") + .WithMany("GuildMembers") + .HasForeignKey("GuildId"); + + b.Navigation("Character"); + + b.Navigation("Guild"); + }); + + modelBuilder.Entity("Server.DB.Documents.InventoryItem", b => + { + b.HasOne("Server.DB.Documents.Character", "Character") + .WithMany("InventoryItems") + .HasForeignKey("CharacterId"); + + 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/20231120162002_FixInventoryItemAsDbset.cs b/Server/DB/Migrations/20231120162002_FixInventoryItemAsDbset.cs new file mode 100644 index 0000000..86b6b4a --- /dev/null +++ b/Server/DB/Migrations/20231120162002_FixInventoryItemAsDbset.cs @@ -0,0 +1,164 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Server.DB.Migrations; + +/// +public partial class FixInventoryItemAsDbset : Migration +{ + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Characters_Guild_GuildId", + table: "Characters"); + + migrationBuilder.DropForeignKey( + name: "FK_GuildMember_Guild_GuildId", + table: "GuildMember"); + + migrationBuilder.DropForeignKey( + name: "FK_InventoryItem_Characters_CharacterId", + table: "InventoryItem"); + + migrationBuilder.DropPrimaryKey( + name: "PK_InventoryItem", + table: "InventoryItem"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Guild", + table: "Guild"); + + migrationBuilder.RenameTable( + name: "InventoryItem", + newName: "InventoryItems"); + + migrationBuilder.RenameTable( + name: "Guild", + newName: "Guilds"); + + migrationBuilder.RenameIndex( + name: "IX_InventoryItem_CharacterId", + table: "InventoryItems", + newName: "IX_InventoryItems_CharacterId"); + + migrationBuilder.AlterColumn( + name: "CharacterId", + table: "InventoryItems", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AddPrimaryKey( + name: "PK_InventoryItems", + table: "InventoryItems", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Guilds", + table: "Guilds", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Characters_Guilds_GuildId", + table: "Characters", + column: "GuildId", + principalTable: "Guilds", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_GuildMember_Guilds_GuildId", + table: "GuildMember", + column: "GuildId", + principalTable: "Guilds", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_InventoryItems_Characters_CharacterId", + table: "InventoryItems", + column: "CharacterId", + principalTable: "Characters", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Characters_Guilds_GuildId", + table: "Characters"); + + migrationBuilder.DropForeignKey( + name: "FK_GuildMember_Guilds_GuildId", + table: "GuildMember"); + + migrationBuilder.DropForeignKey( + name: "FK_InventoryItems_Characters_CharacterId", + table: "InventoryItems"); + + migrationBuilder.DropPrimaryKey( + name: "PK_InventoryItems", + table: "InventoryItems"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Guilds", + table: "Guilds"); + + migrationBuilder.RenameTable( + name: "InventoryItems", + newName: "InventoryItem"); + + migrationBuilder.RenameTable( + name: "Guilds", + newName: "Guild"); + + migrationBuilder.RenameIndex( + name: "IX_InventoryItems_CharacterId", + table: "InventoryItem", + newName: "IX_InventoryItem_CharacterId"); + + migrationBuilder.AlterColumn( + name: "CharacterId", + table: "InventoryItem", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AddPrimaryKey( + name: "PK_InventoryItem", + table: "InventoryItem", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Guild", + table: "Guild", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Characters_Guild_GuildId", + table: "Characters", + column: "GuildId", + principalTable: "Guild", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_GuildMember_Guild_GuildId", + table: "GuildMember", + column: "GuildId", + principalTable: "Guild", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_InventoryItem_Characters_CharacterId", + table: "InventoryItem", + column: "CharacterId", + principalTable: "Characters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } +} diff --git a/Server/DB/Migrations/WonderkingContextModelSnapshot.cs b/Server/DB/Migrations/WonderkingContextModelSnapshot.cs index 8e5308f..44bf8fc 100644 --- a/Server/DB/Migrations/WonderkingContextModelSnapshot.cs +++ b/Server/DB/Migrations/WonderkingContextModelSnapshot.cs @@ -130,7 +130,7 @@ namespace Server.DB.Migrations b.HasKey("Id"); - b.ToTable("Guild"); + b.ToTable("Guilds"); }); modelBuilder.Entity("Server.DB.Documents.GuildMember", b => @@ -172,7 +172,7 @@ namespace Server.DB.Migrations b.Property("AddOption3") .HasColumnType("smallint"); - b.Property("CharacterId") + b.Property("CharacterId") .HasColumnType("uuid"); b.Property("Count") @@ -206,7 +206,7 @@ namespace Server.DB.Migrations b.HasIndex("CharacterId"); - b.ToTable("InventoryItem"); + b.ToTable("InventoryItems"); }); modelBuilder.Entity("Server.DB.Documents.Character", b => @@ -225,22 +225,28 @@ namespace Server.DB.Migrations .HasColumnType("uuid"); b1.Property("Dexterity") - .HasColumnType("smallint"); + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "dexterity"); b1.Property("Intelligence") - .HasColumnType("smallint"); + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "intelligence"); b1.Property("Luck") - .HasColumnType("smallint"); + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "luck"); b1.Property("Strength") - .HasColumnType("smallint"); + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "strength"); b1.Property("Vitality") - .HasColumnType("smallint"); + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "vitality"); b1.Property("Wisdom") - .HasColumnType("smallint"); + .HasColumnType("smallint") + .HasAnnotation("Relational:JsonPropertyName", "wisdom"); b1.HasKey("CharacterId"); @@ -303,9 +309,7 @@ namespace Server.DB.Migrations { b.HasOne("Server.DB.Documents.Character", "Character") .WithMany("InventoryItems") - .HasForeignKey("CharacterId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("CharacterId"); b.Navigation("Character"); }); diff --git a/Server/DB/WonderkingContext.cs b/Server/DB/WonderkingContext.cs index 891c3d0..ca7824a 100644 --- a/Server/DB/WonderkingContext.cs +++ b/Server/DB/WonderkingContext.cs @@ -12,4 +12,6 @@ public class WonderkingContext : DbContext public DbSet Accounts { get; set; } public DbSet Characters { get; set; } + public DbSet InventoryItems { get; set; } + public DbSet Guilds { get; set; } }