fix: Deletion behaviours

This commit is contained in:
Timothy Schenk 2023-11-22 10:16:16 +01:00
parent 4bb4236eb3
commit bd25ff9f09
7 changed files with 483 additions and 14 deletions

View file

@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
namespace Server.DB.Documents;
@ -31,5 +32,9 @@ public class Account
public byte PermissionLevel { get; set; }
[Column(TypeName = "bytea")] public byte[] Salt { get; set; }
public virtual ICollection<Character> Characters { get; } = new List<Character>();
[CanBeNull] public virtual ICollection<Character> Characters { get; set; }
[DeleteBehavior(DeleteBehavior.Cascade)]
[CanBeNull]
public virtual GuildMember GuildMember { get; set; }
}

View file

@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Wonderking.Game.Data.Character;
using Wonderking.Packets.Outgoing.Data;
@ -12,7 +13,7 @@ namespace Server.DB.Documents;
[Index(nameof(Id), IsUnique = true)]
public class Character
{
[DeleteBehavior(DeleteBehavior.Restrict)]
[DeleteBehavior(DeleteBehavior.Cascade)]
public virtual Account Account { get; set; }
[Key]
@ -21,8 +22,7 @@ public class Character
public ushort MapId { get; set; }
[MaxLength(20)]
public string Name { get; set; }
[MaxLength(20)] public string Name { get; set; }
public short LastXCoordinate { get; set; }
public short LastYCoordinate { get; set; }
@ -30,7 +30,9 @@ public class Character
public Gender Gender { get; set; }
public long Experience { get; set; }
public byte Level { get; set; }
[DeleteBehavior(DeleteBehavior.Cascade)]
[CanBeNull]
public virtual ICollection<InventoryItem> InventoryItems { get; set; }
public BaseStats BaseStats { get; set; }
@ -40,5 +42,6 @@ public class Character
public int Mana { get; set; }
[DeleteBehavior(DeleteBehavior.Restrict)]
[CanBeNull]
public virtual Guild Guild { get; set; }
}

View file

@ -2,11 +2,13 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Server.DB.Documents;
public class InventoryItem
{
[DeleteBehavior(DeleteBehavior.Restrict)]
public virtual Character Character { get; set; }
[Key]

View file

@ -0,0 +1,367 @@
// <auto-generated />
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("20231122091030_VariousDeletionBehaviours")]
partial class VariousDeletionBehaviours
{
/// <inheritdoc />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Email")
.HasColumnType("text");
b.Property<Guid?>("GuildMemberId")
.HasColumnType("uuid");
b.Property<byte[]>("Password")
.HasColumnType("bytea");
b.Property<byte>("PermissionLevel")
.HasColumnType("smallint");
b.Property<byte[]>("Salt")
.HasColumnType("bytea");
b.Property<string>("Username")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.HasKey("Id");
b.HasIndex("GuildMemberId");
b.HasIndex("Id")
.IsUnique();
b.HasIndex("Username")
.IsUnique();
b.ToTable("Accounts");
});
modelBuilder.Entity("Server.DB.Documents.Character", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid?>("AccountId")
.HasColumnType("uuid");
b.Property<long>("Experience")
.HasColumnType("bigint");
b.Property<byte>("Gender")
.HasColumnType("smallint");
b.Property<Guid?>("GuildId")
.HasColumnType("uuid");
b.Property<int>("Health")
.HasColumnType("integer");
b.Property<short>("LastXCoordinate")
.HasColumnType("smallint");
b.Property<short>("LastYCoordinate")
.HasColumnType("smallint");
b.Property<byte>("Level")
.HasColumnType("smallint");
b.Property<int>("Mana")
.HasColumnType("integer");
b.Property<int>("MapId")
.HasColumnType("integer");
b.Property<string>("Name")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<byte>("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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.HasMaxLength(16)
.HasColumnType("character varying(16)");
b.Property<string>("Notice")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Id")
.IsUnique();
b.HasIndex("Name")
.IsUnique();
b.ToTable("Guilds");
});
modelBuilder.Entity("Server.DB.Documents.GuildMember", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid?>("CharacterId")
.HasColumnType("uuid");
b.Property<Guid?>("GuildId")
.HasColumnType("uuid");
b.Property<byte>("Rank")
.HasColumnType("smallint");
b.HasKey("Id");
b.HasIndex("CharacterId");
b.HasIndex("GuildId");
b.HasIndex("Id")
.IsUnique();
b.ToTable("GuildMember");
});
modelBuilder.Entity("Server.DB.Documents.InventoryItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte>("AddOption")
.HasColumnType("smallint");
b.Property<byte>("AddOption2")
.HasColumnType("smallint");
b.Property<byte>("AddOption3")
.HasColumnType("smallint");
b.Property<Guid?>("CharacterId")
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<byte>("InventoryTab")
.HasColumnType("smallint");
b.Property<int>("ItemId")
.HasColumnType("integer");
b.Property<byte>("Level")
.HasColumnType("smallint");
b.Property<short>("Option")
.HasColumnType("smallint");
b.Property<short>("Option2")
.HasColumnType("smallint");
b.Property<short>("Option3")
.HasColumnType("smallint");
b.Property<byte>("Rarity")
.HasColumnType("smallint");
b.Property<byte>("Slot")
.HasColumnType("smallint");
b.HasKey("Id");
b.HasIndex("CharacterId");
b.ToTable("InventoryItems");
});
modelBuilder.Entity("Server.DB.Documents.Account", b =>
{
b.HasOne("Server.DB.Documents.GuildMember", "GuildMember")
.WithMany()
.HasForeignKey("GuildMemberId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("GuildMember");
});
modelBuilder.Entity("Server.DB.Documents.Character", b =>
{
b.HasOne("Server.DB.Documents.Account", "Account")
.WithMany("Characters")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Server.DB.Documents.Guild", "Guild")
.WithMany()
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.Restrict);
b.OwnsOne("Wonderking.Packets.Outgoing.Data.BaseStats", "BaseStats", b1 =>
{
b1.Property<Guid>("CharacterId")
.HasColumnType("uuid");
b1.Property<short>("Dexterity")
.HasColumnType("smallint")
.HasAnnotation("Relational:JsonPropertyName", "dexterity");
b1.Property<short>("Intelligence")
.HasColumnType("smallint")
.HasAnnotation("Relational:JsonPropertyName", "intelligence");
b1.Property<short>("Luck")
.HasColumnType("smallint")
.HasAnnotation("Relational:JsonPropertyName", "luck");
b1.Property<short>("Strength")
.HasColumnType("smallint")
.HasAnnotation("Relational:JsonPropertyName", "strength");
b1.Property<short>("Vitality")
.HasColumnType("smallint")
.HasAnnotation("Relational:JsonPropertyName", "vitality");
b1.Property<short>("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<Guid>("CharacterId")
.HasColumnType("uuid");
b1.Property<byte>("FirstJob")
.HasColumnType("smallint");
b1.Property<byte>("FourthJob")
.HasColumnType("smallint");
b1.Property<byte>("SecondJob")
.HasColumnType("smallint");
b1.Property<byte>("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.Restrict);
b.HasOne("Server.DB.Documents.Guild", "Guild")
.WithMany("GuildMembers")
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.Cascade);
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);
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
}
}
}

View file

@ -0,0 +1,74 @@
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Server.DB.Migrations;
/// <inheritdoc />
public partial class VariousDeletionBehaviours : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Characters_Accounts_AccountId",
table: "Characters");
migrationBuilder.AddColumn<Guid>(
name: "GuildMemberId",
table: "Accounts",
type: "uuid",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Accounts_GuildMemberId",
table: "Accounts",
column: "GuildMemberId");
migrationBuilder.AddForeignKey(
name: "FK_Accounts_GuildMember_GuildMemberId",
table: "Accounts",
column: "GuildMemberId",
principalTable: "GuildMember",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Characters_Accounts_AccountId",
table: "Characters",
column: "AccountId",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Accounts_GuildMember_GuildMemberId",
table: "Accounts");
migrationBuilder.DropForeignKey(
name: "FK_Characters_Accounts_AccountId",
table: "Characters");
migrationBuilder.DropIndex(
name: "IX_Accounts_GuildMemberId",
table: "Accounts");
migrationBuilder.DropColumn(
name: "GuildMemberId",
table: "Accounts");
migrationBuilder.AddForeignKey(
name: "FK_Characters_Accounts_AccountId",
table: "Characters",
column: "AccountId",
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
}

View file

@ -34,6 +34,9 @@ namespace Server.DB.Migrations
b.Property<string>("Email")
.HasColumnType("text");
b.Property<Guid?>("GuildMemberId")
.HasColumnType("uuid");
b.Property<byte[]>("Password")
.HasColumnType("bytea");
@ -49,6 +52,8 @@ namespace Server.DB.Migrations
b.HasKey("Id");
b.HasIndex("GuildMemberId");
b.HasIndex("Id")
.IsUnique();
@ -219,12 +224,22 @@ namespace Server.DB.Migrations
b.ToTable("InventoryItems");
});
modelBuilder.Entity("Server.DB.Documents.Account", b =>
{
b.HasOne("Server.DB.Documents.GuildMember", "GuildMember")
.WithMany()
.HasForeignKey("GuildMemberId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("GuildMember");
});
modelBuilder.Entity("Server.DB.Documents.Character", b =>
{
b.HasOne("Server.DB.Documents.Account", "Account")
.WithMany("Characters")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Restrict);
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Server.DB.Documents.Guild", "Guild")
.WithMany()

View file

@ -60,21 +60,24 @@ services:
restart: always
networks:
- continuity
expose:
- 6831
- 6832
- 5778
- 4317
- 4318
- 14250
- 14268
- 14269
ports:
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 4317:4317
- 4318:4318
- 14250:14250
- 14268:14268
- 14269:14269
environment:
- COLLECTOR_OTLP_ENABLED=true
zipkin:
image: openzipkin/zipkin
container_name: continuity-zipkin
image: openzipkin/zipkin:2.24.3
restart: always
ports:
- 9411:9411
networks: