Foreign key for selected character slots.
This commit is contained in:
@@ -20,10 +20,4 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Migrations\Postgres" />
|
|
||||||
<Folder Include="Migrations\Sqlite" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace Content.Server.Database.Migrations.Postgres
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PostgresServerDbContext))]
|
||||||
|
[Migration("20201006223000_SelectedCharacterSlotFk")]
|
||||||
|
public class SelectedCharacterSlotFk : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.Sql(@"ALTER TABLE preference
|
||||||
|
ADD CONSTRAINT ""FK_preference_profile_selected_character_slot_preference_id""
|
||||||
|
FOREIGN KEY (selected_character_slot, preference_id)
|
||||||
|
REFERENCES profile (slot, preference_id)
|
||||||
|
DEFERRABLE INITIALLY DEFERRED;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,12 @@ namespace Content.Server.Database
|
|||||||
[Table("preference")]
|
[Table("preference")]
|
||||||
public class Preference
|
public class Preference
|
||||||
{
|
{
|
||||||
|
// NOTE: on postgres there SHOULD be an FK ensuring that the selected character slot always exists.
|
||||||
|
// I had to use a migration to implement it and as a result its creation is a finicky mess.
|
||||||
|
// Because if I let EFCore know about it it would explode on a circular reference.
|
||||||
|
// Also it has to be DEFERRABLE INITIALLY DEFERRED so that insertion of new preferences works.
|
||||||
|
// Also I couldn't figure out how to create it on SQLite.
|
||||||
|
|
||||||
[Column("preference_id")] public int Id { get; set; }
|
[Column("preference_id")] public int Id { get; set; }
|
||||||
[Column("user_id")] public Guid UserId { get; set; }
|
[Column("user_id")] public Guid UserId { get; set; }
|
||||||
[Column("selected_character_slot")] public int SelectedCharacterSlot { get; set; }
|
[Column("selected_character_slot")] public int SelectedCharacterSlot { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user