Переосмысление аттрибутов переберающих процессоров и устаревшых элементов

This commit is contained in:
2025-05-14 15:44:32 +04:00
parent e6f53fc074
commit 995029ce8d
36 changed files with 1036 additions and 68 deletions
+34 -5
View File
@@ -22,15 +22,44 @@ public class ProcessorAttribute(string name) : Attribute
/// </summary>
public ProcessorGroupEnum Group { get; init; } = ProcessorGroupEnum.General;
/// <summary>
/// Коллекция названий обработчиков, которые должны быть выполнены до этого оброботчика.
/// </summary>
public string? InnerType { get; init; } = null;
/// <summary>
/// Процессор включён по умолчанию.
/// </summary>
public bool Active { get; init; } = true;
/// <summary>
/// Разрешить выполнять процессов в параллельном режиме
/// </summary>
public bool Parallel { get; init; } = true;
/// <summary>
/// Обработчик набора элементов
/// </summary>
public virtual bool Collection { get; } = false;
}
/// <summary>
/// Аттрибут обработчика набор элементов.
/// </summary>
/// <param name="name">Название обработчика.</param>
[AttributeUsage(AttributeTargets.Class)]
public class ProcessorCollectionAttribute(string name) : ProcessorAttribute(name)
{
/// <summary>
/// Название типов, который обрабатывает этот оброботчик.
/// <c>null</c> - обработать все типы.
/// </summary>
public required string? InnerType { get; init; }
/// <summary>
/// Тип используемого компендиума.
/// </summary>
public required ProcessorCompendiumEnum CompendiumType { get; init; }
/// <summary>
/// Обработчик набора элементов.
/// </summary>
public override bool Collection { get; } = true;
}
/// <summary>
+24 -5
View File
@@ -24,7 +24,7 @@ internal class ProcessorCollection
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public ProcessorCollectionItem this[string name] => Items.First(item => item.Name == name);
public ProcessorCollectionItem this[string name] => AllItems.First(item => item.Name == name);
/// <summary>
/// Конструктор класса <see cref="ProcessorCollection"/>.
@@ -65,7 +65,19 @@ internal class ProcessorCollection
ProcessorDependenciesAttribute? dependenciesAttribute =
type.GetCustomAttribute<ProcessorDependenciesAttribute>();
bool isCollection = processorAttribute.InnerType is not null;
bool isCollection = processorAttribute.Collection;
string? innerType = null;
ProcessorCompendiumEnum? compendium = null;
if (processorAttribute.GetType() == typeof(ProcessorCollectionAttribute))
{
ProcessorCollectionAttribute processorCollectionAttribute =
(ProcessorCollectionAttribute)processorAttribute;
innerType = processorCollectionAttribute.InnerType;
compendium = processorCollectionAttribute.CompendiumType;
}
return new()
{
@@ -74,8 +86,9 @@ internal class ProcessorCollection
Description = processorAttribute.Description,
Group = processorAttribute.Group,
Dependencies = dependenciesAttribute?.Dependencies ?? [],
IsCollectionProcessor = isCollection,
InnerType = processorAttribute.InnerType,
IsCollection = isCollection,
InnerType = innerType,
Compendium = compendium,
Active = processorAttribute.Active,
};
}
@@ -216,10 +229,16 @@ internal class ProcessorCollectionItem
/// Флаг, указывающий, обрабатывает ли обработчик коллекцию элементов.
/// Внутренний тип элементов указывается в <see cref="InnerType"/>.
/// </summary>
public required bool IsCollectionProcessor { get; init; }
public required bool IsCollection { get; init; }
/// <summary>
/// Флаг, указывающий внутренний тип коллекции обрабатываемых элементов.
/// </summary>
public string? InnerType { get; init; }
/// <summary>
/// Название типов, который обрабатывает этот оброботчик.
/// <c>null</c> - обработать все типы.
/// </summary>
public ProcessorCompendiumEnum? Compendium { get; init; }
}
@@ -24,6 +24,12 @@ public enum ProcessorGroupEnum
FoundryEnEntities,
}
public enum ProcessorCompendiumEnum
{
Aonprd,
FoundryEn,
}
public static class ProcessorGroupEnumExtension
{
public static string GetDescription(this ProcessorGroupEnum group)
@@ -13,6 +13,7 @@ using Pf2eDataScrapper.Processors;
using Pf2eModel;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common.I18n;
@@ -160,8 +161,9 @@ internal abstract class AbstractEntityProcessor(
{
Entity = Entity,
Target = Globals.AonprdTarget,
ExternalId = Input.GetRequired<string>("id"),
Suffix = Input.GetRequired<string>("url"),
Md5 = Md5(Input.Input.ToString()),
Md5 = Input.Md5(),
};
Context.EntityExternals.Add(external);
@@ -223,11 +225,6 @@ internal abstract class AbstractEntityProcessor(
return;
}
if (legacyIdArray.Count > 1)
{
throw new("Несколько отметок ремастер-сущности на устаревшие!");
}
string[] legacyIds = legacyIdArray.ToArray().Select(t => t.ToString()).ToArray();
if (legacyIds.Length == 0)
@@ -345,19 +342,5 @@ internal abstract class AbstractEntityProcessor(
return JsonConvert.SerializeObject(data, new JsonSerializerSettings());
}
/// <summary>
/// Создание контрольной суммы объекта.
/// </summary>
/// <param name="input">Строковое представление вычисляемого объекта.</param>
/// <param name="isLowercase">Использовать шестнадцатеричные цифры в нижнем регистре.</param>
/// <returns>Контрольная сумма объекта.</returns>
public static string Md5(string input, bool isLowercase = false)
{
using MD5 md5 = MD5.Create();
byte[] byteHash = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
string hash = BitConverter.ToString(byteHash).Replace("-", "");
return isLowercase ? hash.ToLower() : hash;
}
protected static readonly ConcurrentBag<LegacyEntityHandler> LegacyHandlers = [];
}
@@ -0,0 +1,125 @@
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.App;
using Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Helpers;
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Helpers;
using Pf2eDataScrapper.Processors;
using Pf2eModel;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Common.I18n;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Common;
[ProcessorCollection(
"aonprd:legacy",
InnerType = null,
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Создание ссылок на устаревшие сущности",
Group = ProcessorGroupEnum.AonprdPreparation
)]
[ProcessorDependencies(["aonprd:source", "aonprd:external"])]
internal class LegacyProcessor(
ProcessorInput input,
Pf2eDbContext context,
AonprdBuilderGlobals globals,
StringHelper stringHelper
) : AbstractInputProcessor(input)
{
public Pf2eDbContext Context { get; } = context;
public AonprdBuilderGlobals Globals { get; } = globals;
public StringHelper StringHelper { get; } = stringHelper;
private LegacyEntity LegacyEntity { get; set; } = null!;
public override void Process()
{
JArray? remasterIdArray = Input.GetOptional<JArray>("remaster_id");
if (Input.GetOptional<JArray>("remaster_id") is null)
{
throw new SilentSkipItemException();
}
LegacyEntity = new()
{
Name = { [LocaleType.English] = Input.GetOptional<string>("name", "sidebar-29") },
};
AddSource();
AddExternal();
}
/// <summary>
/// Генерация источников сущности.
/// </summary>
protected virtual void AddSource()
{
foreach (LegacyEntitySource entitySource in GetSources())
{
LegacyEntity.Sources.Add(entitySource);
}
}
/// <summary>
/// Получение списка источников сущности.
/// </summary>
/// <returns></returns>
public List<LegacyEntitySource> GetSources()
{
string[] sourceNames = Input
.GetRequired<JArray>("source")
.Select(token => token.ToString())
.ToArray();
if (sourceNames.Length == 0)
{
throw new(
$"Source for entity with id \"{LegacyEntity.Name[LocaleType.English]}\" "
+ $"(Aonprd id \"{Input.GetRequired<string>("id")}\") is not found"
);
}
List<LegacyEntitySource> entitySources = [];
foreach (string sourceName in sourceNames)
{
Source source =
Context.Sources.FirstOrDefault(s => s.Name == sourceName)
?? throw new($"Source \"{sourceName}\" did not found");
LegacyEntitySource entitySource = new()
{
LegacyEntity = LegacyEntity,
Source = source,
Suffix = StringHelper.ResolveSource(Input.GetRequired<string>("source_markdown")),
IsRemaster = Input.GetOptional<JArray>("legacy_id") is not null,
};
entitySources.Add(entitySource);
}
return entitySources;
}
/// <summary>
/// Генерация внешних ссылок сущности.
/// </summary>
protected virtual void AddExternal()
{
LegacyEntityExternal external = new()
{
LegacyEntity = LegacyEntity,
Target = Globals.AonprdTarget,
ExternalId = Input.GetRequired<string>("id"),
Suffix = Input.GetRequired<string>("url"),
Md5 = Input.Md5(),
};
Context.LegacyEntityExternals.Add(external);
}
public override void Save()
{
Context.LegacyEntities.Add(LegacyEntity);
}
}
@@ -7,8 +7,9 @@ using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Common;
[Processor(
[ProcessorCollection(
"aonprd:skill",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
InnerType = "skill",
Description = "Навыки",
Group = ProcessorGroupEnum.AonprdPreparation
@@ -6,9 +6,10 @@ using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Common;
[Processor(
[ProcessorCollection(
"aonprd:source",
InnerType = "source",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Источники",
Group = ProcessorGroupEnum.AonprdPreparation
)]
@@ -12,9 +12,10 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Subclasses;
[Processor(
[ProcessorCollection(
"aonprd:apparition",
InnerType = "apparition",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Apparitions",
Group = ProcessorGroupEnum.AonprdSubclasses
)]
@@ -8,9 +8,10 @@ using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:action",
InnerType = "action",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Действия",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -10,9 +10,10 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:ancestry",
InnerType = "ancestry",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Родословные",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -9,9 +9,10 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:archetype",
InnerType = "archetype",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Архетипы",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -11,9 +11,10 @@ using Pf2eModel.Model.Structure.BackgroundRelation;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:background",
InnerType = "background",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Предыстории",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -15,9 +15,10 @@ using static System.Text.RegularExpressions.Regex;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:class",
InnerType = "class",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Классы",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -10,9 +10,10 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:feat",
InnerType = "feat",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Черты",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -9,9 +9,10 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:language",
InnerType = "language",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Языки",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -13,9 +13,10 @@ using Pf2eModel.Model.Structure.RitualRelation;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:ritual",
InnerType = "ritual",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Ритуалы",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -5,6 +5,7 @@ using Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Helpers;
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Helpers;
using Pf2eDataScrapper.Processors;
using Pf2eModel;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common.I18n;
@@ -13,10 +14,11 @@ using Rule = Pf2eModel.Model.Structure.Rule;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types.Rules;
[Processor(
[ProcessorCollection(
"aonprd:rules",
InnerType = "rules",
Description = "Правила",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Создание цели внешних ссылок",
Group = ProcessorGroupEnum.AonprdEntities
)]
[ProcessorDependencies(["aonprd:trait", "aonprd:source", "aonprd:rules-toc"])]
@@ -12,9 +12,10 @@ using Pf2eModel.Model.Structure.SpellRelation;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:spell",
InnerType = "spell",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Заклинания",
Group = ProcessorGroupEnum.AonprdEntities
)]
@@ -9,13 +9,14 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Processors.Types;
[Processor(
[ProcessorCollection(
"aonprd:trait",
InnerType = "trait",
CompendiumType = ProcessorCompendiumEnum.Aonprd,
Description = "Признаки",
Group = ProcessorGroupEnum.AonprdEntities
)]
[ProcessorDependencies(["aonprd:external", "aonprd:source"])]
[ProcessorDependencies(["aonprd:legacy"])]
internal class TraitProcessor(
ProcessorInput input,
Pf2eDbContext context,
@@ -7,9 +7,10 @@ using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.Importers.Implementations.FoundryEn.Processors.Entities;
[Processor(
[ProcessorCollection(
"foundry-en:action",
InnerType = "action",
CompendiumType = ProcessorCompendiumEnum.FoundryEn,
Description = "Действия",
Group = ProcessorGroupEnum.FoundryEnEntities,
Active = false
@@ -8,9 +8,10 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.FoundryEn.Processors.Entities;
[Processor(
[ProcessorCollection(
"foundry-en:condition",
InnerType = "Item.condition",
CompendiumType = ProcessorCompendiumEnum.FoundryEn,
Description = "Состояния",
Group = ProcessorGroupEnum.FoundryEnEntities,
Active = false
@@ -7,6 +7,7 @@ using Pf2eDataScrapper.Processors;
using Pf2eModel;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common.I18n;
@@ -59,6 +59,10 @@ internal sealed class ProcessorExecutor(
{
Progress.Information(exception.Message);
}
catch (SilentSkipItemException)
{
//
}
}
Context.SaveChanges();
};
@@ -85,7 +89,7 @@ internal sealed class ProcessorExecutor(
private IEnumerable<IProcessor> IterateProcessors(ProcessorCollectionItem item)
{
if (!item.IsCollectionProcessor)
if (!item.IsCollection)
{
Progress.Local.Reset(1);
Progress.Local.Start(item.Description);
@@ -101,21 +105,20 @@ internal sealed class ProcessorExecutor(
);
}
AbstractCompendium compendium = item.Group switch
AbstractCompendium compendium = item.Compendium switch
{
ProcessorGroupEnum.AonprdPreparation
or ProcessorGroupEnum.AonprdEntities
or ProcessorGroupEnum.AonprdSubclasses => AonprdCompendium,
ProcessorGroupEnum.FoundryEnPreparation or ProcessorGroupEnum.FoundryEnEntities =>
FoundryEnCompendium,
ProcessorCompendiumEnum.Aonprd => AonprdCompendium,
ProcessorCompendiumEnum.FoundryEn => FoundryEnCompendium,
_ => throw new($"Не могу выбрать импортёр для группы {item.Group}"),
};
Progress.Local.Reset(compendium.Count(item.InnerType!));
Progress.Local.Reset(
item.InnerType is null ? compendium.Count() : compendium.Count(item.InnerType)
);
foreach (
(AbstractCompendiumItem compendiumItem, JObject json) in compendium.Iterate(
item.InnerType!
item.InnerType
)
)
{
@@ -150,3 +153,8 @@ public class LegacyItemException(string name) : SkipItemException(name, "Уст
/// <param name="reason">Причина пропуска.</param>
public class SkipItemException(string name, string reason)
: Exception($"Пропускаю элемент '{name}', указана причина: {reason}.") { }
/// <summary>
/// Исключение, показывающее, что обработка сущности пропускается без вывода сообщения.
/// </summary>
public class SilentSkipItemException : Exception { }
+15 -1
View File
@@ -1,4 +1,6 @@
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json.Linq;
using NpgsqlTypes;
using Pf2eModel.Model.Common.I18n;
@@ -181,6 +183,18 @@ internal class ProcessorInput(string name, JObject input, IEnumerable<IEnumSolve
throw new InvalidEnumStringException(typeof(T), value);
}
/// <summary>
/// Создание контрольной суммы объекта.
/// </summary>
/// <param name="isLowercase">Использовать шестнадцатеричные цифры в нижнем регистре.</param>
/// <returns>Контрольная сумма объекта.</returns>
public string Md5(bool isLowercase = false)
{
byte[] byteHash = MD5.HashData(Encoding.UTF8.GetBytes(Input.ToString()));
string hash = Convert.ToHexString(byteHash).Replace("-", "");
return isLowercase ? hash.ToLower() : hash;
}
/// <summary>
/// Исключение при неверном значении для перечисленния.
/// </summary>
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations
{
[DbContext(typeof(Pf2eDbContext))]
[Migration("20250514084949_1")]
[Migration("20250514102154_1")]
partial class _1
{
/// <inheritdoc />
@@ -86,6 +86,25 @@ namespace Pf2eModel.Migrations
b.ToTable("entity_keyword", (string)null);
});
modelBuilder.Entity("EntityLegacyEntity", b =>
{
b.Property<int>("LegacyEntitiesId")
.HasColumnType("integer")
.HasColumnName("legacy_entities_id");
b.Property<int>("RemasterEntitiesId")
.HasColumnType("integer")
.HasColumnName("remaster_entities_id");
b.HasKey("LegacyEntitiesId", "RemasterEntitiesId")
.HasName("pk_entity_legacy_entity");
b.HasIndex("RemasterEntitiesId")
.HasDatabaseName("ix_entity_legacy_entity_remaster_entities_id");
b.ToTable("entity_legacy_entity", (string)null);
});
modelBuilder.Entity("EntityTrait", b =>
{
b.Property<int>("EntitiesId")
@@ -240,6 +259,123 @@ namespace Pf2eModel.Migrations
b.ToTable("keyword_aliases", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("name")
.HasColumnOrder(2)
.HasComment("Отображаемое имя");
b.HasKey("Id")
.HasName("pk_legacy_entities");
b.ToTable("legacy_entities", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntityExternal", b =>
{
b.Property<int>("LegacyEntityId")
.HasColumnType("integer")
.HasColumnName("legacy_entity_id")
.HasColumnOrder(1)
.HasComment("Идентификатор сущности");
b.Property<int>("TargetId")
.HasColumnType("integer")
.HasColumnName("target_id")
.HasColumnOrder(2)
.HasComment("Идентификатор цели");
b.Property<string>("ExternalId")
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("external_id")
.HasColumnOrder(3);
b.Property<string>("Md5")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("md5")
.HasColumnOrder(5)
.HasComment("Контрольная сумма объекта");
b.Property<string>("Suffix")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("suffix")
.HasColumnOrder(4)
.HasComment("Часть URL до объекта. Для источников Foundry - полный UUID объекта");
b.HasKey("LegacyEntityId", "TargetId")
.HasName("pk_legacy_entity_externals");
b.HasIndex("TargetId")
.HasDatabaseName("ix_legacy_entity_externals_target_id");
b.ToTable("legacy_entity_externals", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntitySource", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(0)
.HasComment("Идентификатор");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("IsRemaster")
.HasColumnType("boolean")
.HasColumnName("is_remaster")
.HasColumnOrder(4)
.HasComment("Флаг, указывающий, что объект является частью ремастера");
b.Property<int>("LegacyEntityId")
.HasColumnType("integer")
.HasColumnName("legacy_entity_id")
.HasColumnOrder(1)
.HasComment("Идентификатор устаревшей сущности");
b.Property<int>("SourceId")
.HasColumnType("integer")
.HasColumnName("source_id")
.HasColumnOrder(2)
.HasComment("Идентификатор источника");
b.Property<string>("Suffix")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("suffix")
.HasColumnOrder(3)
.HasComment("Номер страницы, эррата и т.д.");
b.HasKey("Id")
.HasName("pk_legacy_entity_sources");
b.HasIndex("LegacyEntityId")
.HasDatabaseName("ix_legacy_entity_sources_legacy_entity_id");
b.HasIndex("SourceId")
.HasDatabaseName("ix_legacy_entity_sources_source_id");
b.ToTable("legacy_entity_sources", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Source.EntitySource", b =>
{
b.Property<int>("Id")
@@ -340,6 +476,12 @@ namespace Pf2eModel.Migrations
.HasColumnOrder(2)
.HasComment("Идентификатор цели");
b.Property<string>("ExternalId")
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("external_id")
.HasColumnOrder(3);
b.Property<string>("Md5")
.IsRequired()
.HasMaxLength(32)
@@ -1842,6 +1984,23 @@ namespace Pf2eModel.Migrations
.HasConstraintName("fk_entity_keyword_keywords_keywords_id");
});
modelBuilder.Entity("EntityLegacyEntity", b =>
{
b.HasOne("Pf2eModel.Model.Base.Legacy.LegacyEntity", null)
.WithMany()
.HasForeignKey("LegacyEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_entity_legacy_entity_legacy_entities_legacy_entities_id");
b.HasOne("Pf2eModel.Model.Base.Entity", null)
.WithMany()
.HasForeignKey("RemasterEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_entity_legacy_entity_entities_remaster_entities_id");
});
modelBuilder.Entity("EntityTrait", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", null)
@@ -1871,6 +2030,48 @@ namespace Pf2eModel.Migrations
b.Navigation("Keyword");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntityExternal", b =>
{
b.HasOne("Pf2eModel.Model.Base.Legacy.LegacyEntity", "LegacyEntity")
.WithMany("Externals")
.HasForeignKey("LegacyEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_externals_legacy_entities_legacy_entity_id");
b.HasOne("Pf2eModel.Model.Base.Targets.ExternalTarget", "Target")
.WithMany("LegacyEntityExternals")
.HasForeignKey("TargetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_externals_external_targets_target_id");
b.Navigation("LegacyEntity");
b.Navigation("Target");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntitySource", b =>
{
b.HasOne("Pf2eModel.Model.Base.Legacy.LegacyEntity", "LegacyEntity")
.WithMany("Sources")
.HasForeignKey("LegacyEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_sources_legacy_entities_legacy_entity_id");
b.HasOne("Pf2eModel.Model.Base.Source.Source", "Source")
.WithMany("LegacyEntitySources")
.HasForeignKey("SourceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_sources_sources_source_id");
b.Navigation("LegacyEntity");
b.Navigation("Source");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Source.EntitySource", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
@@ -2509,14 +2710,25 @@ namespace Pf2eModel.Migrations
b.Navigation("Aliases");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntity", b =>
{
b.Navigation("Externals");
b.Navigation("Sources");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Source.Source", b =>
{
b.Navigation("EntitySources");
b.Navigation("LegacyEntitySources");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Targets.ExternalTarget", b =>
{
b.Navigation("EntityExternals");
b.Navigation("LegacyEntityExternals");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Ancestry", b =>
@@ -101,6 +101,19 @@ namespace Pf2eModel.Migrations
table.PrimaryKey("pk_keywords", x => x.id);
});
migrationBuilder.CreateTable(
name: "legacy_entities",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "jsonb", nullable: false, comment: "Отображаемое имя")
},
constraints: table =>
{
table.PrimaryKey("pk_legacy_entities", x => x.id);
});
migrationBuilder.CreateTable(
name: "sources",
columns: table => new
@@ -399,6 +412,7 @@ namespace Pf2eModel.Migrations
{
entity_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор сущности"),
target_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор цели"),
external_id = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
suffix = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Часть URL до объекта. Для источников Foundry - полный UUID объекта"),
md5 = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "Контрольная сумма объекта")
},
@@ -463,6 +477,57 @@ namespace Pf2eModel.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "entity_legacy_entity",
columns: table => new
{
legacy_entities_id = table.Column<int>(type: "integer", nullable: false),
remaster_entities_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_entity_legacy_entity", x => new { x.legacy_entities_id, x.remaster_entities_id });
table.ForeignKey(
name: "fk_entity_legacy_entity_entities_remaster_entities_id",
column: x => x.remaster_entities_id,
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_entity_legacy_entity_legacy_entities_legacy_entities_id",
column: x => x.legacy_entities_id,
principalTable: "legacy_entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "legacy_entity_externals",
columns: table => new
{
legacy_entity_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор сущности"),
target_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор цели"),
external_id = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
suffix = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Часть URL до объекта. Для источников Foundry - полный UUID объекта"),
md5 = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "Контрольная сумма объекта")
},
constraints: table =>
{
table.PrimaryKey("pk_legacy_entity_externals", x => new { x.legacy_entity_id, x.target_id });
table.ForeignKey(
name: "fk_legacy_entity_externals_external_targets_target_id",
column: x => x.target_id,
principalTable: "external_targets",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_legacy_entity_externals_legacy_entities_legacy_entity_id",
column: x => x.legacy_entity_id,
principalTable: "legacy_entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "entity_sources",
columns: table => new
@@ -491,6 +556,34 @@ namespace Pf2eModel.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "legacy_entity_sources",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
legacy_entity_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор устаревшей сущности"),
source_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор источника"),
suffix = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Номер страницы, эррата и т.д."),
is_remaster = table.Column<bool>(type: "boolean", nullable: false, comment: "Флаг, указывающий, что объект является частью ремастера")
},
constraints: table =>
{
table.PrimaryKey("pk_legacy_entity_sources", x => x.id);
table.ForeignKey(
name: "fk_legacy_entity_sources_legacy_entities_legacy_entity_id",
column: x => x.legacy_entity_id,
principalTable: "legacy_entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_legacy_entity_sources_sources_source_id",
column: x => x.source_id,
principalTable: "sources",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ancestry_boosts",
columns: table => new
@@ -1260,6 +1353,11 @@ namespace Pf2eModel.Migrations
table: "entity_keyword",
column: "keywords_id");
migrationBuilder.CreateIndex(
name: "ix_entity_legacy_entity_remaster_entities_id",
table: "entity_legacy_entity",
column: "remaster_entities_id");
migrationBuilder.CreateIndex(
name: "ix_entity_sources_entity_id",
table: "entity_sources",
@@ -1295,6 +1393,21 @@ namespace Pf2eModel.Migrations
table: "languages",
column: "entity_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_entity_externals_target_id",
table: "legacy_entity_externals",
column: "target_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_entity_sources_legacy_entity_id",
table: "legacy_entity_sources",
column: "legacy_entity_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_entity_sources_source_id",
table: "legacy_entity_sources",
column: "source_id");
migrationBuilder.CreateIndex(
name: "ix_ritual_checks_ritual_id",
table: "ritual_checks",
@@ -1411,6 +1524,9 @@ namespace Pf2eModel.Migrations
migrationBuilder.DropTable(
name: "entity_keyword");
migrationBuilder.DropTable(
name: "entity_legacy_entity");
migrationBuilder.DropTable(
name: "entity_sources");
@@ -1429,6 +1545,12 @@ namespace Pf2eModel.Migrations
migrationBuilder.DropTable(
name: "keyword_aliases");
migrationBuilder.DropTable(
name: "legacy_entity_externals");
migrationBuilder.DropTable(
name: "legacy_entity_sources");
migrationBuilder.DropTable(
name: "ritual_areas");
@@ -1465,12 +1587,6 @@ namespace Pf2eModel.Migrations
migrationBuilder.DropTable(
name: "deities");
migrationBuilder.DropTable(
name: "external_targets");
migrationBuilder.DropTable(
name: "sources");
migrationBuilder.DropTable(
name: "traits");
@@ -1480,6 +1596,15 @@ namespace Pf2eModel.Migrations
migrationBuilder.DropTable(
name: "keywords");
migrationBuilder.DropTable(
name: "external_targets");
migrationBuilder.DropTable(
name: "legacy_entities");
migrationBuilder.DropTable(
name: "sources");
migrationBuilder.DropTable(
name: "rituals");
@@ -83,6 +83,25 @@ namespace Pf2eModel.Migrations
b.ToTable("entity_keyword", (string)null);
});
modelBuilder.Entity("EntityLegacyEntity", b =>
{
b.Property<int>("LegacyEntitiesId")
.HasColumnType("integer")
.HasColumnName("legacy_entities_id");
b.Property<int>("RemasterEntitiesId")
.HasColumnType("integer")
.HasColumnName("remaster_entities_id");
b.HasKey("LegacyEntitiesId", "RemasterEntitiesId")
.HasName("pk_entity_legacy_entity");
b.HasIndex("RemasterEntitiesId")
.HasDatabaseName("ix_entity_legacy_entity_remaster_entities_id");
b.ToTable("entity_legacy_entity", (string)null);
});
modelBuilder.Entity("EntityTrait", b =>
{
b.Property<int>("EntitiesId")
@@ -237,6 +256,123 @@ namespace Pf2eModel.Migrations
b.ToTable("keyword_aliases", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("name")
.HasColumnOrder(2)
.HasComment("Отображаемое имя");
b.HasKey("Id")
.HasName("pk_legacy_entities");
b.ToTable("legacy_entities", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntityExternal", b =>
{
b.Property<int>("LegacyEntityId")
.HasColumnType("integer")
.HasColumnName("legacy_entity_id")
.HasColumnOrder(1)
.HasComment("Идентификатор сущности");
b.Property<int>("TargetId")
.HasColumnType("integer")
.HasColumnName("target_id")
.HasColumnOrder(2)
.HasComment("Идентификатор цели");
b.Property<string>("ExternalId")
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("external_id")
.HasColumnOrder(3);
b.Property<string>("Md5")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("md5")
.HasColumnOrder(5)
.HasComment("Контрольная сумма объекта");
b.Property<string>("Suffix")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("suffix")
.HasColumnOrder(4)
.HasComment("Часть URL до объекта. Для источников Foundry - полный UUID объекта");
b.HasKey("LegacyEntityId", "TargetId")
.HasName("pk_legacy_entity_externals");
b.HasIndex("TargetId")
.HasDatabaseName("ix_legacy_entity_externals_target_id");
b.ToTable("legacy_entity_externals", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntitySource", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(0)
.HasComment("Идентификатор");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("IsRemaster")
.HasColumnType("boolean")
.HasColumnName("is_remaster")
.HasColumnOrder(4)
.HasComment("Флаг, указывающий, что объект является частью ремастера");
b.Property<int>("LegacyEntityId")
.HasColumnType("integer")
.HasColumnName("legacy_entity_id")
.HasColumnOrder(1)
.HasComment("Идентификатор устаревшей сущности");
b.Property<int>("SourceId")
.HasColumnType("integer")
.HasColumnName("source_id")
.HasColumnOrder(2)
.HasComment("Идентификатор источника");
b.Property<string>("Suffix")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("suffix")
.HasColumnOrder(3)
.HasComment("Номер страницы, эррата и т.д.");
b.HasKey("Id")
.HasName("pk_legacy_entity_sources");
b.HasIndex("LegacyEntityId")
.HasDatabaseName("ix_legacy_entity_sources_legacy_entity_id");
b.HasIndex("SourceId")
.HasDatabaseName("ix_legacy_entity_sources_source_id");
b.ToTable("legacy_entity_sources", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Base.Source.EntitySource", b =>
{
b.Property<int>("Id")
@@ -337,6 +473,12 @@ namespace Pf2eModel.Migrations
.HasColumnOrder(2)
.HasComment("Идентификатор цели");
b.Property<string>("ExternalId")
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("external_id")
.HasColumnOrder(3);
b.Property<string>("Md5")
.IsRequired()
.HasMaxLength(32)
@@ -1839,6 +1981,23 @@ namespace Pf2eModel.Migrations
.HasConstraintName("fk_entity_keyword_keywords_keywords_id");
});
modelBuilder.Entity("EntityLegacyEntity", b =>
{
b.HasOne("Pf2eModel.Model.Base.Legacy.LegacyEntity", null)
.WithMany()
.HasForeignKey("LegacyEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_entity_legacy_entity_legacy_entities_legacy_entities_id");
b.HasOne("Pf2eModel.Model.Base.Entity", null)
.WithMany()
.HasForeignKey("RemasterEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_entity_legacy_entity_entities_remaster_entities_id");
});
modelBuilder.Entity("EntityTrait", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", null)
@@ -1868,6 +2027,48 @@ namespace Pf2eModel.Migrations
b.Navigation("Keyword");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntityExternal", b =>
{
b.HasOne("Pf2eModel.Model.Base.Legacy.LegacyEntity", "LegacyEntity")
.WithMany("Externals")
.HasForeignKey("LegacyEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_externals_legacy_entities_legacy_entity_id");
b.HasOne("Pf2eModel.Model.Base.Targets.ExternalTarget", "Target")
.WithMany("LegacyEntityExternals")
.HasForeignKey("TargetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_externals_external_targets_target_id");
b.Navigation("LegacyEntity");
b.Navigation("Target");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntitySource", b =>
{
b.HasOne("Pf2eModel.Model.Base.Legacy.LegacyEntity", "LegacyEntity")
.WithMany("Sources")
.HasForeignKey("LegacyEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_sources_legacy_entities_legacy_entity_id");
b.HasOne("Pf2eModel.Model.Base.Source.Source", "Source")
.WithMany("LegacyEntitySources")
.HasForeignKey("SourceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_entity_sources_sources_source_id");
b.Navigation("LegacyEntity");
b.Navigation("Source");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Source.EntitySource", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
@@ -2506,14 +2707,25 @@ namespace Pf2eModel.Migrations
b.Navigation("Aliases");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Legacy.LegacyEntity", b =>
{
b.Navigation("Externals");
b.Navigation("Sources");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Source.Source", b =>
{
b.Navigation("EntitySources");
b.Navigation("LegacyEntitySources");
});
modelBuilder.Entity("Pf2eModel.Model.Base.Targets.ExternalTarget", b =>
{
b.Navigation("EntityExternals");
b.Navigation("LegacyEntityExternals");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Ancestry", b =>
+6
View File
@@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base.Keywords;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common.I18n;
@@ -99,4 +100,9 @@ public class Entity
/// Коллекция внешних ссылок, связанных с сущностью.
/// </summary>
public ICollection<EntityExternal> Externals { get; set; } = [];
/// <summary>
/// Коллекция устаревших сущностей.
/// </summary>
public IEnumerable<LegacyEntity> LegacyEntities { get; set; } = [];
}
@@ -0,0 +1,42 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Common.I18n;
namespace Pf2eModel.Model.Base.Legacy;
/// <summary>
/// Информация об устаревшей сущности
/// </summary>
public class LegacyEntity
{
/// <summary>
/// Идентификатор сущности.
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column(Order = 1)]
public int Id { get; set; }
/// <summary>
/// Отображаемое имя сущности.
/// </summary>
[Column(Order = 2)]
[Comment("Отображаемое имя")]
public LocaleString Name { get; set; } = [];
/// <summary>
/// Коллекция обновлённых сущностей.
/// </summary>
public ICollection<Entity> RemasterEntities { get; set; } = [];
/// <summary>
/// Коллекция источников, связанных с сущностью.
/// </summary>
public ICollection<LegacyEntitySource> Sources { get; set; } = [];
/// <summary>
/// Коллекция внешних ссылок, связанных с сущностью.
/// </summary>
public ICollection<LegacyEntityExternal> Externals { get; set; } = [];
}
@@ -0,0 +1,58 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base.Targets;
namespace Pf2eModel.Model.Base.Legacy;
/// <summary>
/// Внешняя ссылка сущности.
/// </summary>
[PrimaryKey(nameof(LegacyEntityId), nameof(TargetId))]
public class LegacyEntityExternal
{
/// <summary>
/// Идентификатор сущности.
/// </summary>
[Column(Order = 1)]
[Comment("Идентификатор сущности")]
public int LegacyEntityId { get; set; }
/// <summary>
/// Идентификатор цели.
/// </summary>
[Column(Order = 2)]
[Comment("Идентификатор цели")]
public int TargetId { get; set; }
[Column(Order = 3)]
[MaxLength(255)]
public string? ExternalId { get; set; } = null;
/// <summary>
/// Конечная часть URL внешней ссылки.
/// Для источников Foundry - полный UUID объекта.
/// </summary>
[Column(Order = 4)]
[MaxLength(255)]
[Comment("Часть URL до объекта. Для источников Foundry - полный UUID объекта")]
public string Suffix { get; set; } = "";
/// <summary>
/// Контрольная сумма объекта.
/// </summary>
[Column(Order = 5)]
[MaxLength(32)]
[Comment("Контрольная сумма объекта")]
public string Md5 { get; set; } = null!;
/// <summary>
/// Сущность, которая ссылается на внешнюю ссылку.
/// </summary>
public LegacyEntity LegacyEntity { get; set; } = null!;
/// <summary>
/// Цель внешней ссылки.
/// </summary>
public ExternalTarget Target { get; set; } = null!;
}
@@ -0,0 +1,59 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Pf2eModel.Model.Base.Legacy;
/// <summary>
/// Связь между сущностью и источником.
/// </summary>
public class LegacyEntitySource
{
/// <summary>
/// Идентификатор связи.
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column(Order = 0)]
[Comment("Идентификатор")]
public int Id { get; set; }
/// <summary>
/// Идентификатор устаревшей сущности.
/// </summary>
[Column(Order = 1)]
[Comment("Идентификатор устаревшей сущности")]
public int LegacyEntityId { get; set; }
/// <summary>
/// Идентификатор источника.
/// </summary>
[Column(Order = 2)]
[Comment("Идентификатор источника")]
public int SourceId { get; set; }
/// <summary>
/// Дополнительная информация о источнике, например, номер страницы, номер тома и т.д.
/// </summary>
[Column(Order = 3)]
[MaxLength(255)]
[Comment("Номер страницы, эррата и т.д.")]
public string Suffix { get; set; } = null!;
/// <summary>
/// Флаг, указывающий, что объект является частью ремастера.
/// </summary>
[Column(Order = 4)]
[Comment("Флаг, указывающий, что объект является частью ремастера")]
public bool IsRemaster { get; set; }
/// <summary>
/// Сущность, к которой относится источник.
/// </summary>
public LegacyEntity LegacyEntity { get; set; } = null!;
/// <summary>
/// Источник, к которому относится сущность.
/// </summary>
public Source.Source Source { get; set; } = null!;
}
+6
View File
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Base.Source;
@@ -45,4 +46,9 @@ public class Source
/// Связанные сущности.
/// </summary>
public ICollection<EntitySource> EntitySources { get; set; } = [];
/// <summary>
/// Связанные сущности.
/// </summary>
public ICollection<LegacyEntitySource> LegacyEntitySources { get; set; } = [];
}
@@ -24,11 +24,9 @@ public class EntityExternal
[Comment("Идентификатор цели")]
public int TargetId { get; set; }
/*
[Column(Order = 3)]
[MaxLength(255)]
public string ExternalId { get; set; } = "";
*/
public string? ExternalId { get; set; } = null;
/// <summary>
/// Конечная часть URL внешней ссылки.
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base.Legacy;
namespace Pf2eModel.Model.Base.Targets;
@@ -46,4 +47,9 @@ public class ExternalTarget
/// Коллекция сущностей, которые ссылаются на эту цель.
/// </summary>
public ICollection<EntityExternal> EntityExternals { get; set; } = [];
/// <summary>
/// Коллекция устаревших сущностей, которые ссылаются на эту цель.
/// </summary>
public ICollection<LegacyEntityExternal> LegacyEntityExternals { get; set; } = [];
}
+7
View File
@@ -3,6 +3,7 @@ using dotenv.net.Utilities;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Keywords;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common;
@@ -97,6 +98,12 @@ public partial class Pf2eDbContext : DbContext
public virtual DbSet<Language> Languages { get; set; }
public virtual DbSet<LegacyEntity> LegacyEntities { get; set; }
public virtual DbSet<LegacyEntityExternal> LegacyEntityExternals { get; set; }
public virtual DbSet<LegacyEntitySource> LegacyEntitySources { get; set; }
public virtual DbSet<Ritual> Rituals { get; set; }
public virtual DbSet<RitualArea> RitualAreas { get; set; }
+35
View File
@@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Keywords;
using Pf2eModel.Model.Base.Legacy;
using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common;
@@ -144,6 +145,28 @@ public partial class Pf2eDbContext
.OnDelete(DeleteBehavior.Cascade);
});
// LegacyEntity
modelBuilder.Entity<LegacyEntity>(entity =>
{
BindLocaleString(entity, l => l.Name);
entity.HasMany(l => l.RemasterEntities).WithMany(e => e.LegacyEntities);
// LegacyEntitySource
entity
.HasMany(e => e.Sources)
.WithOne(e => e.LegacyEntity)
.HasForeignKey(e => e.LegacyEntityId)
.OnDelete(DeleteBehavior.Cascade);
// LegacyEntityExternal
entity
.HasMany(e => e.Externals)
.WithOne(e => e.LegacyEntity)
.HasForeignKey(e => e.LegacyEntityId)
.OnDelete(DeleteBehavior.Cascade);
});
// Source
modelBuilder.Entity<Source>(entity =>
{
@@ -155,6 +178,12 @@ public partial class Pf2eDbContext
.HasForeignKey(e => e.SourceId)
.OnDelete(DeleteBehavior.Cascade);
entity
.HasMany(s => s.LegacyEntitySources)
.WithOne(e => e.Source)
.HasForeignKey(e => e.SourceId)
.OnDelete(DeleteBehavior.Cascade);
// + EntitySource
});
modelBuilder.Entity<EntitySource>(entity => { });
@@ -167,6 +196,12 @@ public partial class Pf2eDbContext
.WithOne(e => e.Target)
.HasForeignKey(e => e.TargetId)
.OnDelete(DeleteBehavior.Cascade);
entity
.HasMany(t => t.LegacyEntityExternals)
.WithOne(e => e.Target)
.HasForeignKey(e => e.TargetId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<EntityExternal>(entity => { });