Работа с порядком правил

This commit is contained in:
2025-05-07 15:43:38 +04:00
parent 3168c9c406
commit d48dc62fe7
6 changed files with 171 additions and 7 deletions
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations
{
[DbContext(typeof(Pf2eDbContext))]
[Migration("20250507075826_1")]
[Migration("20250507112626_1")]
partial class _1
{
/// <inheritdoc />
@@ -1407,9 +1407,22 @@ namespace Pf2eModel.Migrations
.HasColumnType("text[]")
.HasColumnName("breadcrumbs");
b.Property<int>("Order")
.HasColumnType("integer")
.HasColumnName("order")
.HasColumnOrder(2);
b.Property<int?>("ParentId")
.HasColumnType("integer")
.HasColumnName("parent_id")
.HasColumnOrder(3);
b.HasKey("Id")
.HasName("pk_rules");
b.HasIndex("ParentId")
.HasDatabaseName("ix_rules_parent_id");
b.ToTable("rules", (string)null);
});
@@ -2276,7 +2289,14 @@ namespace Pf2eModel.Migrations
.IsRequired()
.HasConstraintName("fk_rules_entities_id");
b.HasOne("Pf2eModel.Model.Structure.Rule", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId")
.HasConstraintName("fk_rules_rules_parent_id");
b.Navigation("Entity");
b.Navigation("Parent");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
@@ -2456,6 +2476,11 @@ namespace Pf2eModel.Migrations
b.Navigation("Checks");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Rule", b =>
{
b.Navigation("Children");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
{
b.Navigation("SpellAreas");
@@ -329,6 +329,8 @@ namespace Pf2eModel.Migrations
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false),
order = table.Column<int>(type: "integer", nullable: false),
parent_id = table.Column<int>(type: "integer", nullable: true),
breadcrumbs = table.Column<string[]>(type: "text[]", nullable: false)
},
constraints: table =>
@@ -340,6 +342,11 @@ namespace Pf2eModel.Migrations
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_rules_rules_parent_id",
column: x => x.parent_id,
principalTable: "rules",
principalColumn: "id");
});
migrationBuilder.CreateTable(
@@ -1293,6 +1300,11 @@ namespace Pf2eModel.Migrations
table: "ritual_checks",
column: "training_id");
migrationBuilder.CreateIndex(
name: "ix_rules_parent_id",
table: "rules",
column: "parent_id");
migrationBuilder.CreateIndex(
name: "ix_spell_areas_spell_id",
table: "spell_areas",
@@ -1404,9 +1404,22 @@ namespace Pf2eModel.Migrations
.HasColumnType("text[]")
.HasColumnName("breadcrumbs");
b.Property<int>("Order")
.HasColumnType("integer")
.HasColumnName("order")
.HasColumnOrder(2);
b.Property<int?>("ParentId")
.HasColumnType("integer")
.HasColumnName("parent_id")
.HasColumnOrder(3);
b.HasKey("Id")
.HasName("pk_rules");
b.HasIndex("ParentId")
.HasDatabaseName("ix_rules_parent_id");
b.ToTable("rules", (string)null);
});
@@ -2273,7 +2286,14 @@ namespace Pf2eModel.Migrations
.IsRequired()
.HasConstraintName("fk_rules_entities_id");
b.HasOne("Pf2eModel.Model.Structure.Rule", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId")
.HasConstraintName("fk_rules_rules_parent_id");
b.Navigation("Entity");
b.Navigation("Parent");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
@@ -2453,6 +2473,11 @@ namespace Pf2eModel.Migrations
b.Navigation("Checks");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Rule", b =>
{
b.Navigation("Children");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
{
b.Navigation("SpellAreas");
+10
View File
@@ -15,5 +15,15 @@ public class Rule : IEntity
public Entity Entity { get; set; } = null!;
[Column(Order = 2)]
public int Order { get; set; }
[Column(Order = 3)]
public int? ParentId { get; set; } = null;
public Rule? Parent { get; set; } = null;
public ICollection<Rule> Children { get; set; } = [];
public string[] Breadcrumbs { get; set; } = [];
}
+6
View File
@@ -508,6 +508,12 @@ public partial class Pf2eDbContext
modelBuilder.Entity<Rule>(entity =>
{
BindEntity(entity);
entity
.HasOne(r => r.Parent)
.WithMany(r => r.Children)
.HasForeignKey(r => r.ParentId)
.IsRequired(false);
});
}