Ещё пачка изменений
This commit is contained in:
+5
-4
@@ -29,15 +29,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
|
||||
public void PrepareProcessors()
|
||||
{
|
||||
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
|
||||
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
|
||||
{
|
||||
if (type.GetCustomAttributes(typeof(Pf2eTypeProcessor), true).Length > 0)
|
||||
if (type.GetCustomAttributes(typeof(Pf2eTypeProcessor), true).Length <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var attribute = type.GetCustomAttribute<Pf2eTypeProcessor>();
|
||||
Processors.Add(attribute!.Type, type.GetConstructor(new[] { typeof(JObject) })!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractProcessor? GetProcessor(string type, JObject input)
|
||||
{
|
||||
@@ -53,7 +54,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
{
|
||||
Console.WriteLine("Truncating all old data...");
|
||||
|
||||
Database.ExecuteCommand($"SELECT f_truncate_tables();");
|
||||
Database.ExecuteCommand("SELECT f_truncate_tables();");
|
||||
|
||||
Console.WriteLine("Truncation completed!");
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Slugify;
|
||||
using static LinqToDB.Common.Configuration;
|
||||
|
||||
@@ -24,7 +25,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Pro
|
||||
Img = GetRequired<string>("img"),
|
||||
Description = GetRequired<string>("system.description.value"),
|
||||
DescriptionGm = GetOptional<string>("system.description.gm"),
|
||||
// Type =
|
||||
Type = EntityType.Condition,
|
||||
IsTranslated = false,
|
||||
IsChecked = false,
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
@@ -11,6 +12,8 @@ public partial class Action
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Action;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
@@ -11,6 +12,8 @@ public partial class Ancestry
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Ancestry;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
@@ -11,6 +12,8 @@ public partial class Background
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Background;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
@@ -11,6 +12,8 @@ public partial class CampaignFeature
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.CampaignFeature;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
@@ -11,6 +12,8 @@ public partial class Class
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Class;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using System;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Condition
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Id { get; set; } = -1;
|
||||
|
||||
public string Name { 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; }
|
||||
@@ -21,5 +24,7 @@ public partial class Condition
|
||||
|
||||
public bool? IsChecked { get; set; }
|
||||
|
||||
public ConditionGroup Group { get; set; }
|
||||
|
||||
public string? Extra { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
@@ -11,6 +12,8 @@ public partial class Deity
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Deity;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Entity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Id { get; set; } = -1;
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
|
||||
public enum ConditionGroup
|
||||
{
|
||||
[PgName("senses")]
|
||||
Senses,
|
||||
|
||||
[PgName("abilities")]
|
||||
Abilities,
|
||||
|
||||
[PgName("death")]
|
||||
Death,
|
||||
|
||||
[PgName("attitudes")]
|
||||
Attitudes,
|
||||
|
||||
[PgName("detection")]
|
||||
Detection
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum EntityType
|
||||
{
|
||||
[PgName("unknown")]
|
||||
Unknown,
|
||||
|
||||
[PgName("action")]
|
||||
Action,
|
||||
|
||||
[PgName("ancestry")]
|
||||
Ancestry,
|
||||
|
||||
[PgName("background")]
|
||||
Background,
|
||||
|
||||
[PgName("backpack")]
|
||||
Backpack,
|
||||
|
||||
[PgName("campaign_feature")]
|
||||
CampaignFeature,
|
||||
|
||||
[PgName("class")]
|
||||
Class,
|
||||
|
||||
[PgName("condition")]
|
||||
Condition,
|
||||
|
||||
[PgName("deity")]
|
||||
Deity,
|
||||
|
||||
[PgName("feat")]
|
||||
Feat,
|
||||
|
||||
[PgName("heritage")]
|
||||
Heritage,
|
||||
|
||||
[PgName("spell")]
|
||||
Spell
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class ExternalTarget
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Feat
|
||||
{
|
||||
@@ -11,6 +12,8 @@ public partial class Feat
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Feat;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class FeatPrerequisite
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Frequency
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Pf2eDataScrapper.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Heritage
|
||||
{
|
||||
@@ -12,6 +13,8 @@ public partial class Heritage
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Heritage;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Keyword
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class KeywordAlias
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Language
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
@@ -11,6 +12,8 @@ public partial class Spell
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; } = EntityType.Spell;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace Pf2eDataScrapper
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public void RebuildDatabase()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using LinqToDB.SqlQuery;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
|
||||
@@ -98,10 +103,74 @@ public partial class Pf2eTestContext : DbContext
|
||||
|
||||
public virtual DbSet<Trait> Traits { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseNpgsql(EnvSettings.DatabaseConnection);
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
|
||||
optionsBuilder.UseNpgsql(EnvSettings.DatabaseConnection,
|
||||
builder =>
|
||||
{
|
||||
builder
|
||||
.MapEnum<EntityType>("entity_type")
|
||||
.MapEnum<ConditionGroup>("condition_group");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected string FromEnum<T>(T enumValue) where T : Enum
|
||||
{
|
||||
var enumFieldName = enumValue.ToString();
|
||||
var field = typeof(T).GetField(enumFieldName);
|
||||
if (field is null)
|
||||
{
|
||||
return enumFieldName;
|
||||
}
|
||||
|
||||
var attribute = field.GetCustomAttribute<DescriptionAttribute>();
|
||||
return attribute is null ? enumFieldName : attribute.Description;
|
||||
}
|
||||
|
||||
protected T ToEnum<T>(string enumValue) where T : Enum
|
||||
{
|
||||
var enumType = typeof(T);
|
||||
foreach (var field in enumType.GetFields())
|
||||
{
|
||||
var attribute = field.GetCustomAttribute<DescriptionAttribute>();
|
||||
if (attribute is null)
|
||||
{
|
||||
if (field.Name == enumValue)
|
||||
{
|
||||
return (T)field.GetValue(null)!;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (attribute.Description == enumValue)
|
||||
{
|
||||
return (T)field.GetValue(null)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new ArgumentException($"No matching value found for {enumValue} in {enumType.Name}");
|
||||
}
|
||||
|
||||
protected ValueConverter<T, string> GetEnumConverter<T>() where T : Enum
|
||||
{
|
||||
return new ValueConverter<T, string>(
|
||||
v => FromEnum(v),
|
||||
v => ToEnum<T>(v));
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.UseIdentityByDefaultColumns();
|
||||
|
||||
modelBuilder.HasSequence<int>("entity_sequence");
|
||||
|
||||
modelBuilder
|
||||
.HasPostgresEnum<EntityType>("entity_type")
|
||||
.HasPostgresEnum<ConditionGroup>("condition_group")
|
||||
;
|
||||
|
||||
|
||||
|
||||
modelBuilder
|
||||
.HasPostgresEnum("action_category", new[] { "offensive", "defensive", "interaction", "familiar" })
|
||||
.HasPostgresEnum("action_type", new[] { "action", "free", "reaction", "passive" })
|
||||
@@ -109,12 +178,12 @@ public partial class Pf2eTestContext : DbContext
|
||||
.HasPostgresEnum("ancestry_vision", new[] { "normal", "low_light_vision", "darkvision" })
|
||||
.HasPostgresEnum("campaign_feature_category", new[] { "army_tactic", "army_war_action", "kingdom_activity", "kingdom_feat", "kingdom_feature" })
|
||||
.HasPostgresEnum("class_progression_type", new[] { "entity", "ancestry_feat", "class_feat", "general_feat", "skill_feat", "skill_increase" })
|
||||
.HasPostgresEnum("condition_group", new[] { "senses", "abilities", "death", "attitudes", "detection" })
|
||||
// .HasPostgresEnum("condition_group", new[] { "senses", "abilities", "death", "attitudes", "detection" })
|
||||
.HasPostgresEnum("deity_category", new[] { "deity", "pantheon", "covenant", "philosophy" })
|
||||
.HasPostgresEnum("deity_fonts", new[] { "none", "heal", "harm", "any" })
|
||||
.HasPostgresEnum("deity_sanctification", new[] { "holy", "unholy", "any" })
|
||||
.HasPostgresEnum("entity_rarity", new[] { "common", "uncommon", "rare", "unique" })
|
||||
.HasPostgresEnum("entity_type", new[] { "action", "ancestry", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell" })
|
||||
// .HasPostgresEnum("entity_type", new[] { "action", "ancestry", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell" })
|
||||
.HasPostgresEnum("enum_size", new[] { "med", "lanuages", "system", "tiny" })
|
||||
.HasPostgresEnum("feat_category", new[] { "ancestryfeature", "classfeature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon" })
|
||||
.HasPostgresEnum("spell_area_type", new[] { "burst", "emanation", "cone", "line", "square", "cube", "cylinder" })
|
||||
@@ -131,6 +200,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Actions).HasColumnName("actions");
|
||||
entity.Property(e => e.DeathNote).HasColumnName("death_note");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
@@ -162,6 +234,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
entity.Property(e => e.Hp).HasColumnName("hp");
|
||||
@@ -256,6 +331,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
entity.Property(e => e.Img)
|
||||
@@ -376,6 +454,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.AdditionalTrainedSkills).HasColumnName("additionalTrainedSkills");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
@@ -469,8 +550,13 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.ToTable("condition");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
//.ValueGeneratedNever()
|
||||
.HasDefaultValueSql("nextval('entity_sequence')")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
//.HasConversion(GetEnumConverter<EntityType>())
|
||||
//.HasConversion<string>()
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
entity.Property(e => e.Extra).HasColumnName("extra");
|
||||
@@ -489,6 +575,10 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Slug)
|
||||
.HasMaxLength(150)
|
||||
.HasColumnName("slug");
|
||||
entity.Property(e => e.Group)
|
||||
//.HasConversion(GetEnumConverter<ConditionGroup>())
|
||||
//.HasConversion<string>()
|
||||
.HasColumnName("group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Deity>(entity =>
|
||||
@@ -500,6 +590,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
entity.Property(e => e.Img)
|
||||
@@ -777,6 +870,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Actions).HasColumnName("actions");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
@@ -851,6 +947,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.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");
|
||||
@@ -940,6 +1039,9 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Type)
|
||||
.HasConversion(GetEnumConverter<EntityType>())
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.CanHeightening).HasColumnName("can_heightening");
|
||||
entity.Property(e => e.Cost).HasColumnName("cost");
|
||||
entity.Property(e => e.Counteraction).HasColumnName("counteraction");
|
||||
|
||||
@@ -8,9 +8,10 @@ var importer = new Pf2EFoundryImporter();
|
||||
|
||||
importer.Prepare();
|
||||
|
||||
importer.Import();
|
||||
/*
|
||||
try
|
||||
{
|
||||
importer.Import();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -22,3 +23,4 @@ catch (Exception ex)
|
||||
// importer.BuildSchemas();
|
||||
|
||||
|
||||
*/
|
||||
@@ -204,7 +204,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
/// </summary>
|
||||
/// <param name="input">Словарь данных.</param>
|
||||
/// <returns>Строка форматированных данных</returns>
|
||||
public static string FormatYaml(params List<Dictionary<string, string>> input)
|
||||
public static string FormatYaml(params Dictionary<string, string>[] input)
|
||||
{
|
||||
var result = "";
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
return result.Trim();
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> MergeDictionaries(params List<Dictionary<string, string>> input)
|
||||
public static Dictionary<string, string> MergeDictionaries(params Dictionary<string, string>[] input)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
-- Common Enums
|
||||
|
||||
DROP TYPE IF EXISTS "enum_size";
|
||||
CREATE TYPE "enum_size" AS ENUM (
|
||||
'med',
|
||||
'lanuages',
|
||||
@@ -9,6 +11,9 @@ CREATE TYPE "enum_size" AS ENUM (
|
||||
|
||||
-- Entity
|
||||
|
||||
CREATE SEQUENCE "entity_sequence";
|
||||
|
||||
DROP TYPE IF EXISTS "entity_type";
|
||||
CREATE TYPE "entity_type" AS ENUM (
|
||||
'action',
|
||||
'ancestry',
|
||||
@@ -23,6 +28,7 @@ CREATE TYPE "entity_type" AS ENUM (
|
||||
'spell'
|
||||
);
|
||||
|
||||
DROP TYPE IF EXISTS "entity_rarity";
|
||||
CREATE TYPE "entity_rarity" AS ENUM (
|
||||
'common',
|
||||
'uncommon',
|
||||
@@ -31,7 +37,7 @@ CREATE TYPE "entity_rarity" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "entity" (
|
||||
"id" int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"name" varchar(150) NOT NULL,
|
||||
"img" varchar(150) NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
@@ -47,6 +53,7 @@ CREATE TABLE "entity" (
|
||||
|
||||
-- Alias
|
||||
|
||||
DROP TYPE IF EXISTS "alias_type";
|
||||
CREATE TYPE "alias_type" AS ENUM (
|
||||
'old',
|
||||
'english',
|
||||
@@ -126,6 +133,7 @@ ALTER TABLE "entity_external" ADD FOREIGN KEY ("target_id") REFERENCES "external
|
||||
|
||||
-- Trait
|
||||
|
||||
DROP TYPE IF EXISTS "trait_type";
|
||||
CREATE TYPE "trait_type" AS ENUM (
|
||||
'regular',
|
||||
'tradition'
|
||||
@@ -179,6 +187,7 @@ CREATE TABLE "trainings" (
|
||||
|
||||
-- Spell
|
||||
|
||||
DROP TYPE IF EXISTS "spell_area_type";
|
||||
CREATE TYPE "spell_area_type" AS ENUM (
|
||||
'burst',
|
||||
'emanation',
|
||||
@@ -188,10 +197,12 @@ CREATE TYPE "spell_area_type" AS ENUM (
|
||||
'cube',
|
||||
'cylinder'
|
||||
);
|
||||
DROP TYPE IF EXISTS "spell_damage_category";
|
||||
CREATE TYPE "spell_damage_category" AS ENUM (
|
||||
'persistent',
|
||||
'splash'
|
||||
);
|
||||
DROP TYPE IF EXISTS "spell_damage_kinds";
|
||||
CREATE TYPE "spell_damage_kinds" AS ENUM (
|
||||
'damage',
|
||||
'healing',
|
||||
@@ -199,7 +210,7 @@ CREATE TYPE "spell_damage_kinds" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "spell" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"level" int NOT NULL,
|
||||
"cost" int NOT NULL,
|
||||
"counteraction" bool NOT NULL,
|
||||
@@ -209,8 +220,7 @@ CREATE TABLE "spell" (
|
||||
"requirements" varchar NOT NULL,
|
||||
"target" varchar NOT NULL,
|
||||
"time" varchar NOT NULL,
|
||||
"can_heightening" bool NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
"can_heightening" bool NOT NULL
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "spell" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -255,18 +265,21 @@ ALTER TABLE "spell_defense" ADD FOREIGN KEY ("spell_id") REFERENCES "spell" ("id
|
||||
|
||||
-- Action
|
||||
|
||||
DROP TYPE IF EXISTS "action_type";
|
||||
CREATE TYPE "action_type" AS ENUM (
|
||||
'action',
|
||||
'free',
|
||||
'reaction',
|
||||
'passive'
|
||||
);
|
||||
DROP TYPE IF EXISTS "action_category";
|
||||
CREATE TYPE "action_category" AS ENUM (
|
||||
'offensive',
|
||||
'defensive',
|
||||
'interaction',
|
||||
'familiar'
|
||||
);
|
||||
DROP TYPE IF EXISTS "ancestry_vision";
|
||||
CREATE TYPE "ancestry_vision" AS ENUM (
|
||||
'normal',
|
||||
'low_light_vision',
|
||||
@@ -274,13 +287,12 @@ CREATE TYPE "ancestry_vision" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "action" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"action_type" action_type NOT NULL,
|
||||
"actions" int,
|
||||
"category" action_category,
|
||||
"death_note" bool,
|
||||
"extra" text,
|
||||
PRIMARY KEY ("id")
|
||||
"extra" text
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "action" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -288,13 +300,12 @@ CREATE TABLE "action" (
|
||||
-- Ancestry
|
||||
|
||||
CREATE TABLE "ancestry" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"hp" int NOT NULL,
|
||||
"reach" int NOT NULL,
|
||||
"size" enum_size NOT NULL,
|
||||
"speed" int NOT NULL,
|
||||
"vision" ancestry_vision NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
"vision" ancestry_vision NOT NULL
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "ancestry" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -328,8 +339,7 @@ ALTER TABLE "ancestry_items" ADD FOREIGN KEY ("item_id") REFERENCES "entity" ("i
|
||||
-- Background
|
||||
|
||||
CREATE TABLE "background" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
PRIMARY KEY ("id")
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "background" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -360,6 +370,7 @@ ALTER TABLE "background_boosts" ADD FOREIGN KEY ("background_id") REFERENCES "ba
|
||||
|
||||
-- Campaign Feature
|
||||
|
||||
DROP TYPE IF EXISTS "campaign_feature_category";
|
||||
CREATE TYPE "campaign_feature_category" AS ENUM (
|
||||
'army_tactic',
|
||||
'army_war_action',
|
||||
@@ -369,20 +380,20 @@ CREATE TYPE "campaign_feature_category" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "campaign_feature" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"level" int,
|
||||
"action_type" action_type NOT NULL,
|
||||
"actions" int NOT NULL,
|
||||
"category" campaign_feature_category NOT NULL,
|
||||
"prerequisites" varchar,
|
||||
"extra" text,
|
||||
PRIMARY KEY ("id")
|
||||
"extra" text
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "campaign_feature" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
|
||||
-- Class
|
||||
|
||||
DROP TYPE IF EXISTS "class_progression_type";
|
||||
CREATE TYPE "class_progression_type" AS ENUM (
|
||||
'entity',
|
||||
'ancestry_feat',
|
||||
@@ -393,12 +404,11 @@ CREATE TYPE "class_progression_type" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "class" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"hp" int NOT NULL,
|
||||
"perception" int NOT NULL,
|
||||
"spellcasting" bool NOT NULL,
|
||||
"additionalTrainedSkills" int NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
"additionalTrainedSkills" int NOT NULL
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "class" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -432,6 +442,7 @@ ALTER TABLE "class_trainings" ADD FOREIGN KEY ("item") REFERENCES "trainings" ("
|
||||
|
||||
-- Condition
|
||||
|
||||
DROP TYPE IF EXISTS "condition_group";
|
||||
CREATE TYPE "condition_group" AS ENUM (
|
||||
'senses',
|
||||
'abilities',
|
||||
@@ -441,28 +452,30 @@ CREATE TYPE "condition_group" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "condition" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"group" condition_group,
|
||||
"extra" text,
|
||||
PRIMARY KEY ("id")
|
||||
"extra" text
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "condition" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
|
||||
-- Deity
|
||||
|
||||
DROP TYPE IF EXISTS "deity_category";
|
||||
CREATE TYPE "deity_category" AS ENUM (
|
||||
'deity',
|
||||
'pantheon',
|
||||
'covenant',
|
||||
'philosophy'
|
||||
);
|
||||
DROP TYPE IF EXISTS "deity_fonts";
|
||||
CREATE TYPE "deity_fonts" AS ENUM (
|
||||
'none',
|
||||
'heal',
|
||||
'harm',
|
||||
'any'
|
||||
);
|
||||
DROP TYPE IF EXISTS "deity_sanctification";
|
||||
CREATE TYPE "deity_sanctification" AS ENUM (
|
||||
'holy',
|
||||
'unholy',
|
||||
@@ -470,12 +483,11 @@ CREATE TYPE "deity_sanctification" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "deity" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"category" deity_category NOT NULL,
|
||||
"font" deity_fonts NOT NULL,
|
||||
"sanctification_must" bool NOT NULL,
|
||||
"sanctification_type" deity_sanctification NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
"sanctification_type" deity_sanctification NOT NULL
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "deity" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -521,6 +533,7 @@ ALTER TABLE "deity_domains" ADD FOREIGN KEY ("deity_id") REFERENCES "deity" ("id
|
||||
|
||||
-- Feat
|
||||
|
||||
DROP TYPE IF EXISTS "feat_category";
|
||||
CREATE TYPE "feat_category" AS ENUM (
|
||||
'ancestryfeature',
|
||||
'classfeature',
|
||||
@@ -536,7 +549,7 @@ CREATE TYPE "feat_category" AS ENUM (
|
||||
);
|
||||
|
||||
CREATE TABLE "feat" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"action_type" action_type NOT NULL,
|
||||
"actions" int,
|
||||
"category" feat_category NOT NULL,
|
||||
@@ -545,8 +558,7 @@ CREATE TABLE "feat" (
|
||||
"max_takable" int,
|
||||
"location" varchar(12),
|
||||
"only_level_1" bool,
|
||||
"extra" text,
|
||||
PRIMARY KEY ("id")
|
||||
"extra" text
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "feat" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
|
||||
@@ -561,9 +573,63 @@ ALTER TABLE "feat_prerequisites" ADD FOREIGN KEY ("feat_id") REFERENCES "feat" (
|
||||
-- Heritage
|
||||
|
||||
CREATE TABLE "heritage" (
|
||||
-- "id" int PRIMARY KEY,
|
||||
"ancestry_id" int,
|
||||
PRIMARY KEY ("id")
|
||||
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY,
|
||||
"ancestry_id" int
|
||||
) INHERITS ("entity");
|
||||
-- ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
|
||||
ALTER TABLE "heritage" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");
|
||||
|
||||
|
||||
----------------------------------------------------------------------------------------------
|
||||
|
||||
CREATE OR REPLACE FUNCTION f_truncate_tables()
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
BEGIN
|
||||
EXECUTE
|
||||
(SELECT 'TRUNCATE TABLE '
|
||||
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|
||||
|| ' CASCADE;'
|
||||
FROM pg_tables
|
||||
WHERE schemaname = 'public'
|
||||
);
|
||||
END
|
||||
$func$;
|
||||
|
||||
----------------------------------------------------------------------------------------------
|
||||
|
||||
CREATE OR REPLACE FUNCTION f_drop_tables()
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
BEGIN
|
||||
EXECUTE
|
||||
(SELECT 'DROP TABLE '
|
||||
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|
||||
|| ' CASCADE;'
|
||||
FROM pg_tables
|
||||
WHERE schemaname = 'public'
|
||||
);
|
||||
END
|
||||
$func$;
|
||||
|
||||
----------------------------------------------------------------------------------------------
|
||||
|
||||
CREATE OR REPLACE FUNCTION f_drop_tables(_username text)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
DECLARE
|
||||
_tbl text;
|
||||
_sch text;
|
||||
BEGIN
|
||||
FOR _sch, _tbl IN
|
||||
SELECT schemaname, tablename
|
||||
FROM pg_tables
|
||||
WHERE schemaname = 'public'
|
||||
LOOP
|
||||
EXECUTE format('ALTER TABLE %I.%I OWNER TO %I', _sch, _tbl, _username);
|
||||
END LOOP;
|
||||
END
|
||||
$func$;
|
||||
Reference in New Issue
Block a user