From 5475b6ab46b4792772fb542addf2aef8bd7ed4cc Mon Sep 17 00:00:00 2001 From: kozhilya Date: Tue, 15 Apr 2025 11:55:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BE=D1=82=20=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=20=D0=BD=D0=B0=201-1=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBuilder/AbstractProcessor.cs | 73 +- .../DataBuilder/DataBuilderHelper.cs | 74 +- .../DataBuilder/Pf2eTypeProcessor.cs | 3 +- .../Processors/ConditionProcessor.cs | 36 +- Pf2eDataScrapper/Model/Action.cs | 16 +- Pf2eDataScrapper/Model/Ancestry.cs | 24 +- Pf2eDataScrapper/Model/Background.cs | 16 +- Pf2eDataScrapper/Model/CampaignFeature.cs | 16 +- Pf2eDataScrapper/Model/Class.cs | 16 +- Pf2eDataScrapper/Model/Condition.cs | 20 +- Pf2eDataScrapper/Model/Deity.cs | 16 +- Pf2eDataScrapper/Model/Entity.cs | 12 +- Pf2eDataScrapper/Model/Feat.cs | 16 +- Pf2eDataScrapper/Model/Heritage.cs | 16 +- Pf2eDataScrapper/Model/IEntity.cs | 13 +- Pf2eDataScrapper/Model/Spell.cs | 16 +- Pf2eDataScrapper/Model/Trait.cs | 4 +- Pf2eDataScrapper/Pf2eTestContext.cs | 787 ++++++++---------- Pf2eDataScrapper/schema.pgsql | 64 +- dbml/schema.dbml | 5 +- 20 files changed, 491 insertions(+), 752 deletions(-) diff --git a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/AbstractProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/AbstractProcessor.cs index f9068f7..f869b5b 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/AbstractProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/AbstractProcessor.cs @@ -1,4 +1,8 @@ using Newtonsoft.Json.Linq; +using NpgsqlTypes; +using Pf2eDataScrapper.Model; +using Pf2eDataScrapper.Model.Enum; +using System.ComponentModel; namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder { @@ -8,23 +12,49 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder public readonly JObject Input = input; - public abstract void Process(); + protected DataBuilderHelper Helper = DataBuilderHelper.Instance; + + public Entity Entity { get; set; } = new Entity(); + + public abstract EntityType Type { get; } + + public abstract IEntity Object { get; } + + public virtual void Process() + { + Entity.Id = Helper.NextId; + Entity.Type = Type; + + Entity.Name = GetRequired("name"); + Entity.Img = GetRequired("img"); + Entity.Description = GetRequired("system.description.value"); + Entity.DescriptionGm = GetOptional("system.description.gm"); + + Entity.IsTranslated = false; + Entity.IsChecked = false; + + Entity.Slug = Helper.GenerateSlug(Entity.Name); + + Object.Id = Entity.Id; + + Context.Entities.Add(Entity); + + // TODO Traits, Alias + } public void Save() { Context.SaveChanges(); } - - - protected T GetRequired(string path) + public T GetRequired(string path) { var token = Input.SelectToken(path) ?? throw new NullReferenceException($"'{path}' is null"); return token.ToObject() ?? throw new NullReferenceException($"'{path}' is null"); } - protected T? GetOptional(string path) + public T? GetOptional(string path) { var token = Input.SelectToken(path) ?? null; @@ -36,6 +66,39 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder return token.ToObject() ?? default; } + public T EnumRequired(string path) where T : Enum + { + return EnumOptional(path) ?? throw new Exception($"Can't resolve Enum value for {typeof(T).Name} in path {path}"); + } + public T? EnumOptional(string path) where T : Enum + { + string? value = GetOptional(path); + + if (value == null) + { + return default; + } + + foreach (var field in typeof(T).GetFields()) + { + if (Attribute.GetCustomAttribute(field, typeof(PgNameAttribute)) is PgNameAttribute attribute) + { + if (attribute.PgName == value) + { + return (T)field.GetValue(null); + } + } + else + { + if (field.Name == value) + { + return (T)field.GetValue(null); + } + } + } + + return default; + } } } diff --git a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/DataBuilderHelper.cs b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/DataBuilderHelper.cs index cbab03d..f41897e 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/DataBuilderHelper.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/DataBuilderHelper.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json.Linq; -using Npgsql; +using Slugify; namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder { @@ -7,76 +6,23 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder { public Pf2eDatabase Database = Pf2eDatabase.Instance; + public SlugHelper Slugger = new(); + private DataBuilderHelper() { } - public NpgsqlCommand PrepareInsert(string table, Dictionary data, bool returnId) + private int _id = 0; + + public int NextId { get => ++_id; } + + public string GenerateSlug(string name) { - List columns = []; - List patterns = []; - - foreach (var key in data.Keys) - { - columns.Add(key); - patterns.Add($":{key.ToUpper()}"); - } - - string dml = $"INSERT INTO {table} (\"{string.Join("\", \"", columns)}\") VALUES ({string.Join(", ", patterns)})" + (returnId ? " RETURNING id" : ""); - - NpgsqlCommand cmd = Database.GetCommand(dml); - foreach (var kvp in data) - { - cmd.Parameters.AddWithValue(":" + kvp.Key.ToUpper(), kvp.Value ?? DBNull.Value); - } - - Console.WriteLine(cmd.CommandText); - return cmd; + return Slugger.GenerateSlug(name); } - public int Insert(string table, Dictionary data) - { - var cmd = PrepareInsert(table, data, true); - return (int)(cmd.ExecuteScalar() ?? throw new Exception("Not a number")); - } - public void InsertBlind(string table, Dictionary data) - { - var cmd = PrepareInsert(table, data, false); - cmd.ExecuteNonQuery(); - } - public static object? JsonGet(JObject root, string path) - { - var token = root.SelectToken(path); - - if (token == null) - { - return null; - } - - if (token.Type == JTokenType.String) - { - return token.ToString(); - } - else if (token.Type == JTokenType.Integer) - { - return token.ToObject(); - } - else if (token.Type == JTokenType.Float) - { - return token.ToObject(); - } - else if (token.Type == JTokenType.Boolean) - { - return token.ToObject(); - } - else - { - return token.ToString(); - } - } - - public static DataBuilderHelper Instance = new(); + public readonly static DataBuilderHelper Instance = new(); } } diff --git a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Pf2eTypeProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Pf2eTypeProcessor.cs index 8e1f4f0..e3609c1 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Pf2eTypeProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Pf2eTypeProcessor.cs @@ -1,9 +1,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder { [AttributeUsage(AttributeTargets.Class)] - internal class Pf2eTypeProcessor(string type) : Attribute + internal class Pf2eTypeProcessor(string type, int priority = 0) : Attribute { public readonly string Type = type; + public readonly int Priority = priority; } } diff --git a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Processors/ConditionProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Processors/ConditionProcessor.cs index fb0f2ce..9ec2eb4 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Processors/ConditionProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/DataBuilder/Processors/ConditionProcessor.cs @@ -1,39 +1,33 @@ using Newtonsoft.Json.Linq; using Pf2eDataScrapper.Model; using Pf2eDataScrapper.Model.Enum; -using Slugify; namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors { [Pf2eTypeProcessor("Item.condition")] internal class ConditionProcessor(JObject input) : AbstractProcessor(input) { + public override EntityType Type => EntityType.Condition; + + public override Condition Object { get; } = new(); + public override void Process() { + base.Process(); + JObject extra = new() - { - { "duration", Input.SelectToken("duration") }, - { "overrides", Input.SelectToken("overrides") }, - { "references", Input.SelectToken("references") }, - { "value", Input.SelectToken("value") } - }; - - Condition condition = new() { - Name = GetRequired("name"), - Img = GetRequired("img"), - Description = GetRequired("system.description.value"), - DescriptionGm = GetOptional("system.description.gm"), - Type = EntityType.Condition, - IsTranslated = false, - IsChecked = false, - - // Group = GetOptional("system.group"); - Extra = extra.ToString(Newtonsoft.Json.Formatting.Indented) + { "duration", Input.SelectToken("system.duration") }, + { "overrides", Input.SelectToken("system.overrides") }, + { "references", Input.SelectToken("system.references") }, + { "value", Input.SelectToken("system.value") } }; - condition.Slug = new SlugHelper().GenerateSlug(condition.Name); - Context.Conditions.Add(condition); + Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.Indented); + + Object.Group = EnumOptional("system.group"); + + Context.Conditions.Add(Object); } } } diff --git a/Pf2eDataScrapper/Model/Action.cs b/Pf2eDataScrapper/Model/Action.cs index cd2f380..5aa0e60 100644 --- a/Pf2eDataScrapper/Model/Action.cs +++ b/Pf2eDataScrapper/Model/Action.cs @@ -6,21 +6,9 @@ public partial class Action : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; + public Entity Entity { get; set; } = null!; - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Action; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + // TODO ActionType public int? Actions { get; set; } diff --git a/Pf2eDataScrapper/Model/Ancestry.cs b/Pf2eDataScrapper/Model/Ancestry.cs index 8dcd9f2..7331526 100644 --- a/Pf2eDataScrapper/Model/Ancestry.cs +++ b/Pf2eDataScrapper/Model/Ancestry.cs @@ -6,21 +6,9 @@ public partial class Ancestry : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; + public Entity Entity { get; set; } = null!; - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Ancestry; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + // TODO Size Vision public int Hp { get; set; } @@ -28,11 +16,11 @@ public partial class Ancestry : IEntity public int Speed { get; set; } - public virtual ICollection AncestryBoosts { get; set; } = new List(); + public virtual ICollection AncestryBoosts { get; set; } = []; - public virtual ICollection AncestryItems { get; set; } = new List(); + public virtual ICollection AncestryItems { get; set; } = []; - public virtual ICollection AncestryLanguages { get; set; } = new List(); + public virtual ICollection AncestryLanguages { get; set; } = []; - public virtual ICollection Heritages { get; set; } = new List(); + public virtual ICollection Heritages { get; set; } = []; } diff --git a/Pf2eDataScrapper/Model/Background.cs b/Pf2eDataScrapper/Model/Background.cs index f28d534..396a830 100644 --- a/Pf2eDataScrapper/Model/Background.cs +++ b/Pf2eDataScrapper/Model/Background.cs @@ -6,21 +6,7 @@ public partial class Background : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; - - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Background; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + public Entity Entity { get; set; } = null!; public virtual ICollection BackgroundBoosts { get; set; } = new List(); diff --git a/Pf2eDataScrapper/Model/CampaignFeature.cs b/Pf2eDataScrapper/Model/CampaignFeature.cs index 4238ad4..110d28e 100644 --- a/Pf2eDataScrapper/Model/CampaignFeature.cs +++ b/Pf2eDataScrapper/Model/CampaignFeature.cs @@ -6,21 +6,9 @@ public partial class CampaignFeature : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; + public Entity Entity { get; set; } = null!; - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.CampaignFeature; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + // TODO ActionType Category public int? Level { get; set; } diff --git a/Pf2eDataScrapper/Model/Class.cs b/Pf2eDataScrapper/Model/Class.cs index b773530..7c00b4d 100644 --- a/Pf2eDataScrapper/Model/Class.cs +++ b/Pf2eDataScrapper/Model/Class.cs @@ -6,21 +6,7 @@ public partial class Class : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; - - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Class; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + public Entity Entity { get; set; } = null!; public int Hp { get; set; } diff --git a/Pf2eDataScrapper/Model/Condition.cs b/Pf2eDataScrapper/Model/Condition.cs index 57d721e..280d3d8 100644 --- a/Pf2eDataScrapper/Model/Condition.cs +++ b/Pf2eDataScrapper/Model/Condition.cs @@ -4,25 +4,11 @@ namespace Pf2eDataScrapper.Model; public partial class Condition : IEntity { - public int Id { get; set; } = -1; + public int Id { get; set; } - public string Name { get; set; } = null!; + public Entity Entity { get; set; } = null!; - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Condition; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } - - public ConditionGroup Group { get; set; } + public ConditionGroup? Group { get; set; } public string? Extra { get; set; } } diff --git a/Pf2eDataScrapper/Model/Deity.cs b/Pf2eDataScrapper/Model/Deity.cs index 5cd8fc9..c47cc83 100644 --- a/Pf2eDataScrapper/Model/Deity.cs +++ b/Pf2eDataScrapper/Model/Deity.cs @@ -6,21 +6,9 @@ public partial class Deity : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; + public Entity Entity { get; set; } = null!; - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Deity; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + // TODO Category Font Sanctification public bool SanctificationMust { get; set; } diff --git a/Pf2eDataScrapper/Model/Entity.cs b/Pf2eDataScrapper/Model/Entity.cs index 20f9a4c..3460574 100644 --- a/Pf2eDataScrapper/Model/Entity.cs +++ b/Pf2eDataScrapper/Model/Entity.cs @@ -1,13 +1,17 @@ -namespace Pf2eDataScrapper.Model; +using Pf2eDataScrapper.Model.Enum; -public partial class Entity : IEntity +namespace Pf2eDataScrapper.Model; + +public class Entity { - public int Id { get; set; } = -1; + public int Id { get; set; } public string Name { get; set; } = null!; public string Img { get; set; } = null!; + public EntityType Type { get; set; } + public string Description { get; set; } = null!; public string? DescriptionGm { get; set; } @@ -18,5 +22,5 @@ public partial class Entity : IEntity public bool? IsChecked { get; set; } - public virtual ICollection Traits { get; set; } = new List(); + public virtual ICollection Traits { get; set; } = []; } diff --git a/Pf2eDataScrapper/Model/Feat.cs b/Pf2eDataScrapper/Model/Feat.cs index dd9ef20..06a34b9 100644 --- a/Pf2eDataScrapper/Model/Feat.cs +++ b/Pf2eDataScrapper/Model/Feat.cs @@ -6,21 +6,9 @@ public partial class Feat : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; + public Entity Entity { get; set; } = null!; - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Feat; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + // TODO ActionType Category public int? Actions { get; set; } diff --git a/Pf2eDataScrapper/Model/Heritage.cs b/Pf2eDataScrapper/Model/Heritage.cs index cc21938..9c2a129 100644 --- a/Pf2eDataScrapper/Model/Heritage.cs +++ b/Pf2eDataScrapper/Model/Heritage.cs @@ -6,21 +6,7 @@ public partial class Heritage : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; - - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Heritage; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + public Entity Entity { get; set; } = null!; public int? AncestryId { get; set; } diff --git a/Pf2eDataScrapper/Model/IEntity.cs b/Pf2eDataScrapper/Model/IEntity.cs index 8d8189e..1bad196 100644 --- a/Pf2eDataScrapper/Model/IEntity.cs +++ b/Pf2eDataScrapper/Model/IEntity.cs @@ -4,18 +4,7 @@ { public int Id { get; set; } - public string Name { get; set; } + public Entity Entity { get; set; } - public string Img { get; set; } - - public string Description { get; set; } - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } } } diff --git a/Pf2eDataScrapper/Model/Spell.cs b/Pf2eDataScrapper/Model/Spell.cs index ad9d854..f840816 100644 --- a/Pf2eDataScrapper/Model/Spell.cs +++ b/Pf2eDataScrapper/Model/Spell.cs @@ -6,21 +6,7 @@ public partial class Spell : IEntity { public int Id { get; set; } - public string Name { get; set; } = null!; - - public string Img { get; set; } = null!; - - public EntityType Type { get; set; } = EntityType.Spell; - - public string Description { get; set; } = null!; - - public string? DescriptionGm { get; set; } - - public string Slug { get; set; } = null!; - - public bool? IsTranslated { get; set; } - - public bool? IsChecked { get; set; } + public Entity Entity { get; set; } = null!; public int Level { get; set; } diff --git a/Pf2eDataScrapper/Model/Trait.cs b/Pf2eDataScrapper/Model/Trait.cs index dc99fe0..4db7311 100644 --- a/Pf2eDataScrapper/Model/Trait.cs +++ b/Pf2eDataScrapper/Model/Trait.cs @@ -6,7 +6,7 @@ public partial class Trait public string Name { get; set; } = null!; - public string Description { get; set; } = null!; + public string Slug { get; set; } = null!; - public virtual ICollection Entities { get; set; } = new List(); + public string Description { get; set; } = null!; } diff --git a/Pf2eDataScrapper/Pf2eTestContext.cs b/Pf2eDataScrapper/Pf2eTestContext.cs index d1f5c39..7f34c6c 100644 --- a/Pf2eDataScrapper/Pf2eTestContext.cs +++ b/Pf2eDataScrapper/Pf2eTestContext.cs @@ -18,6 +18,8 @@ public partial class Pf2eTestContext : DbContext { } + #region DbSets + public virtual DbSet Actions { get; set; } public virtual DbSet Ancestries { get; set; } @@ -100,6 +102,7 @@ public partial class Pf2eTestContext : DbContext public virtual DbSet Traits { get; set; } + #endregion protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseNpgsql(EnvSettings.DatabaseConnection, @@ -160,15 +163,11 @@ public partial class Pf2eTestContext : DbContext { modelBuilder.UseIdentityByDefaultColumns(); - modelBuilder.HasSequence("entity_sequence"); - modelBuilder .HasPostgresEnum("entity_type") .HasPostgresEnum("condition_group") ; - - modelBuilder .HasPostgresEnum("action_category", new[] { "offensive", "defensive", "interaction", "familiar" }) .HasPostgresEnum("action_type", new[] { "action", "free", "reaction", "passive" }) @@ -189,23 +188,18 @@ public partial class Pf2eTestContext : DbContext .HasPostgresEnum("spell_damage_kinds", new[] { "damage", "healing", "any" }) .HasPostgresEnum("trait_type", new[] { "regular", "tradition" }); - modelBuilder.Entity(entity => + + modelBuilder.Entity(entity => { - entity.HasKey(e => e.Id).HasName("action_pkey"); + entity.HasKey(e => e.Id).HasName("entity_pkey"); - entity.ToTable("action"); + entity.ToTable("entity"); - entity.Property(e => e.Id) - .ValueGeneratedNever() - .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.Actions).HasColumnName("actions"); - entity.Property(e => e.DeathNote).HasColumnName("death_note"); + entity.Property(e => e.Id).HasColumnName("id"); entity.Property(e => e.Description).HasColumnName("description"); entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Extra).HasColumnName("extra"); + entity.Property(e => e.Type) + .HasColumnName("type"); entity.Property(e => e.Img) .HasMaxLength(150) .HasColumnName("img"); @@ -221,8 +215,262 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Slug) .HasMaxLength(150) .HasColumnName("slug"); + + entity.HasMany(d => d.Traits).WithMany() + .UsingEntity>( + "EntityTrait", + r => r.HasOne().WithMany() + .HasForeignKey("TraitId") + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_traits_trait_id_fkey"), + l => l.HasOne().WithMany() + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_traits_entity_id_fkey"), + j => + { + j.HasKey("EntityId", "TraitId").HasName("entity_traits_pkey"); + j.ToTable("entity_traits"); + j.IndexerProperty("EntityId").HasColumnName("entity_id"); + j.IndexerProperty("TraitId").HasColumnName("trait_id"); + }); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("entity_aliases_pkey"); + + entity.ToTable("entity_aliases"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Alias) + .HasColumnType("character varying") + .HasColumnName("alias"); + entity.Property(e => e.EntityId).HasColumnName("entity_id"); + + entity.HasOne(d => d.Entity).WithMany() + .HasForeignKey(d => d.EntityId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_aliases_entity_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.EntityId, e.TargetId }).HasName("entity_external_pkey"); + + entity.ToTable("entity_external"); + + entity.Property(e => e.EntityId).HasColumnName("entity_id"); + entity.Property(e => e.TargetId).HasColumnName("target_id"); + entity.Property(e => e.Md5) + .HasColumnType("character varying") + .HasColumnName("md5"); + entity.Property(e => e.Path) + .HasColumnType("character varying") + .HasColumnName("path"); + entity.Property(e => e.Suffix) + .HasDefaultValueSql("''::character varying") + .HasColumnType("character varying") + .HasColumnName("suffix"); + + entity.HasOne(d => d.Entity).WithMany() + .HasForeignKey(d => d.EntityId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_external_entity_id_fkey"); + + entity.HasOne(d => d.Target).WithMany() + .HasForeignKey(d => d.TargetId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_external_target_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity + .HasNoKey() + .ToTable("entity_keywords"); + + entity.Property(e => e.EntityId).HasColumnName("entity_id"); + entity.Property(e => e.KeywordId).HasColumnName("keyword_id"); + + entity.HasOne(d => d.Entity).WithMany() + .HasForeignKey(d => d.EntityId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_keywords_entity_id_fkey"); + + entity.HasOne(d => d.Keyword).WithMany() + .HasForeignKey(d => d.KeywordId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_keywords_keyword_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity + .HasNoKey() + .ToTable("entity_sources"); + + entity.Property(e => e.EntityId).HasColumnName("entity_id"); + entity.Property(e => e.IsRemaster).HasColumnName("is_remaster"); + entity.Property(e => e.SourceId).HasColumnName("source_id"); + entity.Property(e => e.Suffix) + .HasDefaultValueSql("''::character varying") + .HasColumnType("character varying") + .HasColumnName("suffix"); + + entity.HasOne(d => d.Entity).WithMany() + .HasForeignKey(d => d.EntityId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_sources_entity_id_fkey"); + + entity.HasOne(d => d.Source).WithMany() + .HasForeignKey(d => d.SourceId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("entity_sources_source_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("external_target_pkey"); + + entity.ToTable("external_target"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Icon) + .HasColumnType("character varying") + .HasColumnName("icon"); + entity.Property(e => e.Name) + .HasColumnType("character varying") + .HasColumnName("name"); + }); + + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("frequency_pkey"); + + entity.ToTable("frequency"); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasColumnName("id"); + entity.Property(e => e.Max).HasColumnName("max"); + entity.Property(e => e.Per).HasColumnName("per"); + entity.Property(e => e.Value).HasColumnName("value"); + + entity.HasOne(d => d.IdNavigation).WithOne() + .HasForeignKey(d => d.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("frequency_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("keyword_pkey"); + + entity.ToTable("keyword"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Slug) + .HasMaxLength(50) + .HasColumnName("slug"); + }); + + modelBuilder.Entity(entity => + { + entity + .HasNoKey() + .ToTable("keyword_aliases"); + + entity.Property(e => e.KeywordId).HasColumnName("keyword_id"); + entity.Property(e => e.Value) + .HasColumnType("character varying") + .HasColumnName("value"); + + entity.HasOne(d => d.Keyword).WithMany() + .HasForeignKey(d => d.KeywordId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("keyword_aliases_keyword_id_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("language_pkey"); + + entity.ToTable("language"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Name) + .HasColumnType("character varying") + .HasColumnName("name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("source_pkey"); + + entity.ToTable("source"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Name) + .HasColumnType("character varying") + .HasColumnName("name"); + entity.Property(e => e.Url) + .HasColumnType("character varying") + .HasColumnName("url"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("trainings_pkey"); + + entity.ToTable("trainings"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Key) + .HasColumnType("character varying") + .HasColumnName("key"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("trait_pkey"); + + entity.ToTable("trait"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Description).HasColumnName("description"); + entity.Property(e => e.Name) + .HasColumnType("character varying") + .HasColumnName("name"); + entity.Property(e => e.Slug) + .HasColumnType("character varying") + .HasColumnName("slug"); + }); + + + + + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("action_pkey"); + + entity.ToTable("action"); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasColumnName("id"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("action_id_fkey"); + entity.Property(e => e.Actions).HasColumnName("actions"); + entity.Property(e => e.DeathNote).HasColumnName("death_note"); + }); + + + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("ancestry_pkey"); @@ -232,28 +480,12 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("ancestry_id_fkey"); entity.Property(e => e.Hp).HasColumnName("hp"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); entity.Property(e => e.Reach).HasColumnName("reach"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); entity.Property(e => e.Speed).HasColumnName("speed"); }); @@ -293,7 +525,7 @@ public partial class Pf2eTestContext : DbContext .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("ancestry_items_ancestry_id_fkey"); - entity.HasOne(d => d.Item).WithMany(p => p.AncestryItems) + entity.HasOne(d => d.Item).WithMany() .HasForeignKey(d => d.ItemId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("ancestry_items_item_id_fkey"); @@ -320,6 +552,8 @@ public partial class Pf2eTestContext : DbContext .HasConstraintName("ancestry_languages_language_id_fkey"); }); + + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("background_pkey"); @@ -329,26 +563,10 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("background_id_fkey"); }); modelBuilder.Entity(entity => @@ -384,7 +602,7 @@ public partial class Pf2eTestContext : DbContext .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("background_items_background_id_fkey"); - entity.HasOne(d => d.Entity).WithMany(p => p.BackgroundItems) + entity.HasOne(d => d.Entity).WithMany() .HasForeignKey(d => d.EntityId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("background_items_entity_id_fkey"); @@ -409,6 +627,8 @@ public partial class Pf2eTestContext : DbContext .HasConstraintName("background_skills_background_id_fkey"); }); + + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("campaign_feature_pkey"); @@ -418,31 +638,21 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Actions).HasColumnName("actions"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Extra).HasColumnName("extra"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("campaign_feature_id_fkey"); + entity.Property(e => e.Level).HasColumnName("level"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); + entity.Property(e => e.Actions).HasColumnName("actions"); entity.Property(e => e.Prerequisites) .HasColumnType("character varying") .HasColumnName("prerequisites"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); + entity.Property(e => e.Extra).HasColumnName("extra"); }); + + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("class_pkey"); @@ -452,30 +662,15 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.AdditionalTrainedSkills).HasColumnName("additionalTrainedSkills"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("class_id_fkey"); + entity.Property(e => e.Hp).HasColumnName("hp"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); entity.Property(e => e.Perception).HasColumnName("perception"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); entity.Property(e => e.Spellcasting).HasColumnName("spellcasting"); + entity.Property(e => e.AdditionalTrainedSkills).HasColumnName("additionalTrainedSkills"); }); modelBuilder.Entity(entity => @@ -512,7 +707,7 @@ public partial class Pf2eTestContext : DbContext .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("class_progression_class_id_fkey"); - entity.HasOne(d => d.Entity).WithMany(p => p.ClassProgressions) + entity.HasOne(d => d.Entity).WithMany() .HasForeignKey(d => d.EntityId) .HasConstraintName("class_progression_entity_id_fkey"); }); @@ -541,6 +736,8 @@ public partial class Pf2eTestContext : DbContext .HasConstraintName("class_trainings_item_fkey"); }); + + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("condition_pkey"); @@ -548,37 +745,19 @@ public partial class Pf2eTestContext : DbContext entity.ToTable("condition"); entity.Property(e => e.Id) - //.ValueGeneratedNever() - .HasDefaultValueSql("nextval('entity_sequence')") + .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - //.HasConversion(GetEnumConverter()) - //.HasConversion() - .HasColumnName("type"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("condition_id_fkey"); + + entity.Property(e => e.Group).HasColumnName("group"); entity.Property(e => e.Extra).HasColumnName("extra"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); - entity.Property(e => e.Group) - //.HasConversion(GetEnumConverter()) - //.HasConversion() - .HasColumnName("group"); }); + + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("deity_pkey"); @@ -588,27 +767,12 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("deity_id_fkey"); + entity.Property(e => e.SanctificationMust).HasColumnName("sanctification_must"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); entity.HasMany(d => d.Skills).WithMany(p => p.Deities) .UsingEntity>( @@ -706,158 +870,7 @@ public partial class Pf2eTestContext : DbContext .HasConstraintName("deity_weapons_deity_id_fkey"); }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("entity_pkey"); - entity.ToTable("entity"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); - - entity.HasMany(d => d.Traits).WithMany(p => p.Entities) - .UsingEntity>( - "EntityTrait", - r => r.HasOne().WithMany() - .HasForeignKey("TraitId") - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_traits_trait_id_fkey"), - l => l.HasOne().WithMany() - .HasForeignKey("EntityId") - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_traits_entity_id_fkey"), - j => - { - j.HasKey("EntityId", "TraitId").HasName("entity_traits_pkey"); - j.ToTable("entity_traits"); - j.IndexerProperty("EntityId").HasColumnName("entity_id"); - j.IndexerProperty("TraitId").HasColumnName("trait_id"); - }); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("entity_aliases_pkey"); - - entity.ToTable("entity_aliases"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Alias) - .HasColumnType("character varying") - .HasColumnName("alias"); - entity.Property(e => e.EntityId).HasColumnName("entity_id"); - - entity.HasOne(d => d.Entity).WithMany(p => p.EntityAliases) - .HasForeignKey(d => d.EntityId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_aliases_entity_id_fkey"); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => new { e.EntityId, e.TargetId }).HasName("entity_external_pkey"); - - entity.ToTable("entity_external"); - - entity.Property(e => e.EntityId).HasColumnName("entity_id"); - entity.Property(e => e.TargetId).HasColumnName("target_id"); - entity.Property(e => e.Md5) - .HasColumnType("character varying") - .HasColumnName("md5"); - entity.Property(e => e.Path) - .HasColumnType("character varying") - .HasColumnName("path"); - entity.Property(e => e.Suffix) - .HasDefaultValueSql("''::character varying") - .HasColumnType("character varying") - .HasColumnName("suffix"); - - entity.HasOne(d => d.Entity).WithMany(p => p.EntityExternals) - .HasForeignKey(d => d.EntityId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_external_entity_id_fkey"); - - entity.HasOne(d => d.Target).WithMany(p => p.EntityExternals) - .HasForeignKey(d => d.TargetId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_external_target_id_fkey"); - }); - - modelBuilder.Entity(entity => - { - entity - .HasNoKey() - .ToTable("entity_keywords"); - - entity.Property(e => e.EntityId).HasColumnName("entity_id"); - entity.Property(e => e.KeywordId).HasColumnName("keyword_id"); - - entity.HasOne(d => d.Entity).WithMany() - .HasForeignKey(d => d.EntityId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_keywords_entity_id_fkey"); - - entity.HasOne(d => d.Keyword).WithMany() - .HasForeignKey(d => d.KeywordId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_keywords_keyword_id_fkey"); - }); - - modelBuilder.Entity(entity => - { - entity - .HasNoKey() - .ToTable("entity_sources"); - - entity.Property(e => e.EntityId).HasColumnName("entity_id"); - entity.Property(e => e.IsRemaster).HasColumnName("is_remaster"); - entity.Property(e => e.SourceId).HasColumnName("source_id"); - entity.Property(e => e.Suffix) - .HasDefaultValueSql("''::character varying") - .HasColumnType("character varying") - .HasColumnName("suffix"); - - entity.HasOne(d => d.Entity).WithMany() - .HasForeignKey(d => d.EntityId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_sources_entity_id_fkey"); - - entity.HasOne(d => d.Source).WithMany() - .HasForeignKey(d => d.SourceId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("entity_sources_source_id_fkey"); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("external_target_pkey"); - - entity.ToTable("external_target"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Icon) - .HasColumnType("character varying") - .HasColumnName("icon"); - entity.Property(e => e.Name) - .HasColumnType("character varying") - .HasColumnName("name"); - }); modelBuilder.Entity(entity => { @@ -868,35 +881,19 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("feat_id_fkey"); + entity.Property(e => e.Actions).HasColumnName("actions"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Extra).HasColumnName("extra"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); entity.Property(e => e.Level).HasColumnName("level"); entity.Property(e => e.LevelTaken).HasColumnName("level_taken"); + entity.Property(e => e.MaxTakable).HasColumnName("max_takable"); entity.Property(e => e.Location) .HasMaxLength(12) .HasColumnName("location"); - entity.Property(e => e.MaxTakable).HasColumnName("max_takable"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); entity.Property(e => e.OnlyLevel1).HasColumnName("only_level_1"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); }); modelBuilder.Entity(entity => @@ -917,24 +914,7 @@ public partial class Pf2eTestContext : DbContext .HasConstraintName("feat_prerequisites_feat_id_fkey"); }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("frequency_pkey"); - entity.ToTable("frequency"); - - entity.Property(e => e.Id) - .ValueGeneratedNever() - .HasColumnName("id"); - entity.Property(e => e.Max).HasColumnName("max"); - entity.Property(e => e.Per).HasColumnName("per"); - entity.Property(e => e.Value).HasColumnName("value"); - - entity.HasOne(d => d.IdNavigation).WithOne(p => p.Frequency) - .HasForeignKey(d => d.Id) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("frequency_id_fkey"); - }); modelBuilder.Entity(entity => { @@ -945,88 +925,18 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.AncestryId).HasColumnName("ancestry_id"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("heritage_id_fkey"); + entity.Property(e => e.AncestryId).HasColumnName("ancestry_id"); entity.HasOne(d => d.Ancestry).WithMany(p => p.Heritages) .HasForeignKey(d => d.AncestryId) .HasConstraintName("heritage_ancestry_id_fkey"); }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("keyword_pkey"); - entity.ToTable("keyword"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Slug) - .HasMaxLength(50) - .HasColumnName("slug"); - }); - - modelBuilder.Entity(entity => - { - entity - .HasNoKey() - .ToTable("keyword_aliases"); - - entity.Property(e => e.KeywordId).HasColumnName("keyword_id"); - entity.Property(e => e.Value) - .HasColumnType("character varying") - .HasColumnName("value"); - - entity.HasOne(d => d.Keyword).WithMany() - .HasForeignKey(d => d.KeywordId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("keyword_aliases_keyword_id_fkey"); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("language_pkey"); - - entity.ToTable("language"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Name) - .HasColumnType("character varying") - .HasColumnName("name"); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("source_pkey"); - - entity.ToTable("source"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Name) - .HasColumnType("character varying") - .HasColumnName("name"); - entity.Property(e => e.Url) - .HasColumnType("character varying") - .HasColumnName("url"); - }); modelBuilder.Entity(entity => { @@ -1037,46 +947,31 @@ public partial class Pf2eTestContext : DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasColumnName("id"); - entity.Property(e => e.Type) - .HasConversion(GetEnumConverter()) - .HasColumnName("type"); - entity.Property(e => e.CanHeightening).HasColumnName("can_heightening"); + entity.HasOne(e => e.Entity).WithOne() + .HasForeignKey(e => e.Id) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("spell_id_fkey"); + + entity.Property(e => e.Level).HasColumnName("level"); entity.Property(e => e.Cost).HasColumnName("cost"); entity.Property(e => e.Counteraction).HasColumnName("counteraction"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.DescriptionGm).HasColumnName("description_gm"); + entity.Property(e => e.Sustained).HasColumnName("sustained"); entity.Property(e => e.Duration) .HasColumnType("character varying") .HasColumnName("duration"); - entity.Property(e => e.Img) - .HasMaxLength(150) - .HasColumnName("img"); - entity.Property(e => e.IsChecked) - .HasDefaultValue(false) - .HasColumnName("is_checked"); - entity.Property(e => e.IsTranslated) - .HasDefaultValue(false) - .HasColumnName("is_translated"); - entity.Property(e => e.Level).HasColumnName("level"); - entity.Property(e => e.Name) - .HasMaxLength(150) - .HasColumnName("name"); entity.Property(e => e.Range) .HasColumnType("character varying") .HasColumnName("range"); entity.Property(e => e.Requirements) .HasColumnType("character varying") .HasColumnName("requirements"); - entity.Property(e => e.Slug) - .HasMaxLength(150) - .HasColumnName("slug"); - entity.Property(e => e.Sustained).HasColumnName("sustained"); entity.Property(e => e.Target) .HasColumnType("character varying") .HasColumnName("target"); entity.Property(e => e.Time) .HasColumnType("character varying") .HasColumnName("time"); + entity.Property(e => e.CanHeightening).HasColumnName("can_heightening"); }); modelBuilder.Entity(entity => @@ -1170,30 +1065,6 @@ public partial class Pf2eTestContext : DbContext .HasConstraintName("spell_ritual_spell_id_fkey"); }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("trainings_pkey"); - - entity.ToTable("trainings"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Key) - .HasColumnType("character varying") - .HasColumnName("key"); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.Id).HasName("trait_pkey"); - - entity.ToTable("trait"); - - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Description).HasColumnName("description"); - entity.Property(e => e.Name) - .HasColumnType("character varying") - .HasColumnName("name"); - }); OnModelCreatingPartial(modelBuilder); } diff --git a/Pf2eDataScrapper/schema.pgsql b/Pf2eDataScrapper/schema.pgsql index a2e0ec1..41a6322 100644 --- a/Pf2eDataScrapper/schema.pgsql +++ b/Pf2eDataScrapper/schema.pgsql @@ -142,6 +142,7 @@ CREATE TYPE "trait_type" AS ENUM ( CREATE TABLE "trait" ( "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, "name" varchar NOT NULL, + "slug" varchar NOT NULL, "description" text NOT NULL, "type" trait_type NOT NULL ); @@ -210,7 +211,7 @@ CREATE TYPE "spell_damage_kinds" AS ENUM ( ); CREATE TABLE "spell" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "level" int NOT NULL, "cost" int NOT NULL, "counteraction" bool NOT NULL, @@ -221,8 +222,8 @@ CREATE TABLE "spell" ( "target" varchar NOT NULL, "time" varchar NOT NULL, "can_heightening" bool NOT NULL -) INHERITS ("entity"); --- ALTER TABLE "spell" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "spell" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); CREATE TABLE "spell_area" ( "spell_id" int PRIMARY KEY, @@ -287,27 +288,27 @@ CREATE TYPE "ancestry_vision" AS ENUM ( ); CREATE TABLE "action" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "action_type" action_type NOT NULL, "actions" int, "category" action_category, "death_note" bool, "extra" text -) INHERITS ("entity"); --- ALTER TABLE "action" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "action" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); -- Ancestry CREATE TABLE "ancestry" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "hp" int NOT NULL, "reach" int NOT NULL, "size" enum_size NOT NULL, "speed" int NOT NULL, "vision" ancestry_vision NOT NULL -) INHERITS ("entity"); --- ALTER TABLE "ancestry" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "ancestry" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); CREATE TABLE "ancestry_languages" ( "ancestry_id" int, @@ -339,9 +340,9 @@ ALTER TABLE "ancestry_items" ADD FOREIGN KEY ("item_id") REFERENCES "entity" ("i -- Background CREATE TABLE "background" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY -) INHERITS ("entity"); --- ALTER TABLE "background" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); + "id" int PRIMARY KEY +); +ALTER TABLE "background" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); CREATE TABLE "background_items" ( "background_id" int, @@ -380,15 +381,15 @@ CREATE TYPE "campaign_feature_category" AS ENUM ( ); CREATE TABLE "campaign_feature" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "level" int, "action_type" action_type NOT NULL, "actions" int NOT NULL, "category" campaign_feature_category NOT NULL, "prerequisites" varchar, "extra" text -) INHERITS ("entity"); --- ALTER TABLE "campaign_feature" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "campaign_feature" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); -- Class @@ -404,13 +405,13 @@ CREATE TYPE "class_progression_type" AS ENUM ( ); CREATE TABLE "class" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "hp" int NOT NULL, "perception" int NOT NULL, "spellcasting" bool NOT NULL, "additionalTrainedSkills" int NOT NULL -) INHERITS ("entity"); --- ALTER TABLE "class" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "class" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); CREATE TABLE "class_key_abilities" ( "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, @@ -452,11 +453,11 @@ CREATE TYPE "condition_group" AS ENUM ( ); CREATE TABLE "condition" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "group" condition_group, "extra" text -) INHERITS ("entity"); --- ALTER TABLE "condition" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "condition" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); -- Deity @@ -483,13 +484,13 @@ CREATE TYPE "deity_sanctification" AS ENUM ( ); CREATE TABLE "deity" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "category" deity_category NOT NULL, "font" deity_fonts NOT NULL, "sanctification_must" bool NOT NULL, "sanctification_type" deity_sanctification NOT NULL -) INHERITS ("entity"); --- ALTER TABLE "deity" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "deity" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); CREATE TABLE "deity_attributes" ( "deity_id" int, @@ -549,7 +550,7 @@ CREATE TYPE "feat_category" AS ENUM ( ); CREATE TABLE "feat" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "action_type" action_type NOT NULL, "actions" int, "category" feat_category NOT NULL, @@ -559,8 +560,8 @@ CREATE TABLE "feat" ( "location" varchar(12), "only_level_1" bool, "extra" text -) INHERITS ("entity"); --- ALTER TABLE "feat" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "feat" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); CREATE TABLE "feat_prerequisites" ( "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, @@ -573,10 +574,10 @@ ALTER TABLE "feat_prerequisites" ADD FOREIGN KEY ("feat_id") REFERENCES "feat" ( -- Heritage CREATE TABLE "heritage" ( - "id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, + "id" int PRIMARY KEY, "ancestry_id" int -) INHERITS ("entity"); --- ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +); +ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "heritage" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id"); @@ -599,6 +600,7 @@ $func$; ---------------------------------------------------------------------------------------------- + CREATE OR REPLACE FUNCTION f_drop_tables() RETURNS void LANGUAGE plpgsql AS @@ -616,7 +618,7 @@ $func$; ---------------------------------------------------------------------------------------------- -CREATE OR REPLACE FUNCTION f_drop_tables(_username text) +CREATE OR REPLACE FUNCTION f_permission_tables(_username text) RETURNS void LANGUAGE plpgsql AS $func$ diff --git a/dbml/schema.dbml b/dbml/schema.dbml index 2cd63b7..c607f56 100644 --- a/dbml/schema.dbml +++ b/dbml/schema.dbml @@ -14,8 +14,6 @@ Table entity { is_translated bool [default: false, note: "Первичный импорт идёт из англоязычного источника, перевод приходит вторым"] is_checked bool [default: false, note: "Флаг, указывающий, что перевод был проверен вручную и не требует обновления парсером"] - - } Enum entity_type { action @@ -98,6 +96,7 @@ Table entity_external { Table trait { id int [pk, increment] name varchar [not null] + slug varchar [not null] description text [not null] type trait_type [not null] } @@ -369,7 +368,7 @@ Enum class_progression_type { Table condition { id int [pk, ref: - entity.id] - group condition_group [null] + group condition_group [null, note: "{}.group"] extra text [null, note: "json для того, что надо рассмотреть"]