Создание модели БД в EntityFramework

This commit is contained in:
2025-04-14 18:40:38 +04:00
parent 570b5296ae
commit 73bba7a865
48 changed files with 2154 additions and 139 deletions
+569
View File
@@ -0,0 +1,569 @@
-- Common Enums
CREATE TYPE "enum_size" AS ENUM (
'med',
'lanuages',
'system',
'tiny'
);
-- Entity
CREATE TYPE "entity_type" AS ENUM (
'action',
'ancestry',
'background',
'backpack',
'campaign_feature',
'class',
'condition',
'deity',
'feat',
'heritage',
'spell'
);
CREATE TYPE "entity_rarity" AS ENUM (
'common',
'uncommon',
'rare',
'unique'
);
CREATE TABLE "entity" (
"id" int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar(150) NOT NULL,
"img" varchar(150) NOT NULL,
"description" text NOT NULL,
"description_gm" text,
"type" entity_type NOT NULL,
"slug" varchar(150) NOT NULL,
"rarity" entity_rarity NOT NULL DEFAULT 'common',
"is_translated" bool DEFAULT false,
"is_checked" bool DEFAULT false
);
-- Alias
CREATE TYPE "alias_type" AS ENUM (
'old',
'english',
'hobby'
);
CREATE TABLE "entity_aliases" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"entity_id" int NOT NULL,
"alias" varchar NOT NULL,
"type" alias_type NOT NULL
);
ALTER TABLE "entity_aliases" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
-- Keywords
CREATE TABLE "keyword" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"slug" varchar(50) NOT NULL
);
CREATE TABLE "entity_keywords" (
"entity_id" int NOT NULL,
"keyword_id" int NOT NULL
);
ALTER TABLE "entity_keywords" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
ALTER TABLE "entity_keywords" ADD FOREIGN KEY ("keyword_id") REFERENCES "keyword" ("id");
CREATE TABLE "keyword_aliases" (
"keyword_id" int,
"type" alias_type,
"value" varchar NOT NULL,
PRIMARY KEY ("keyword_id", "type")
);
ALTER TABLE "keyword_aliases" ADD FOREIGN KEY ("keyword_id") REFERENCES "keyword" ("id");
-- Source
CREATE TABLE "source" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar NOT NULL,
"url" varchar NOT NULL
);
CREATE TABLE "entity_sources" (
"entity_id" int NOT NULL,
"source_id" int NOT NULL,
"suffix" varchar NOT NULL DEFAULT '',
"is_remaster" bool NOT NULL
);
ALTER TABLE "entity_sources" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
ALTER TABLE "entity_sources" ADD FOREIGN KEY ("source_id") REFERENCES "source" ("id");
-- External
CREATE TABLE "external_target" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar NOT NULL,
"icon" varchar NOT NULL
);
CREATE TABLE "entity_external" (
"entity_id" int,
"target_id" int,
"path" varchar NOT NULL,
"suffix" varchar NOT NULL DEFAULT '',
"md5" varchar NOT NULL,
PRIMARY KEY ("entity_id", "target_id")
);
ALTER TABLE "entity_external" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
ALTER TABLE "entity_external" ADD FOREIGN KEY ("target_id") REFERENCES "external_target" ("id");
-- Trait
CREATE TYPE "trait_type" AS ENUM (
'regular',
'tradition'
);
CREATE TABLE "trait" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar NOT NULL,
"description" text NOT NULL,
"type" trait_type NOT NULL
);
CREATE TABLE "entity_traits" (
"entity_id" int,
"trait_id" int,
PRIMARY KEY ("entity_id", "trait_id")
);
ALTER TABLE "entity_traits" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
ALTER TABLE "entity_traits" ADD FOREIGN KEY ("trait_id") REFERENCES "trait" ("id");
-- Frequency
CREATE TABLE "frequency" (
"id" int PRIMARY KEY,
"max" int NOT NULL,
"per" int NOT NULL,
"value" int
);
ALTER TABLE "frequency" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Language
CREATE TABLE "language" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar NOT NULL,
"rarity" entity_rarity NOT NULL
);
-- Training
CREATE TABLE "trainings" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"key" varchar NOT NULL
);
------------------------------------------------------------------------------------------
-- Spell
CREATE TYPE "spell_area_type" AS ENUM (
'burst',
'emanation',
'cone',
'line',
'square',
'cube',
'cylinder'
);
CREATE TYPE "spell_damage_category" AS ENUM (
'persistent',
'splash'
);
CREATE TYPE "spell_damage_kinds" AS ENUM (
'damage',
'healing',
'any'
);
CREATE TABLE "spell" (
-- "id" int PRIMARY KEY,
"level" int NOT NULL,
"cost" int NOT NULL,
"counteraction" bool NOT NULL,
"sustained" bool NOT NULL,
"duration" varchar NOT NULL,
"range" varchar NOT NULL,
"requirements" varchar NOT NULL,
"target" varchar NOT NULL,
"time" varchar NOT NULL,
"can_heightening" bool NOT NULL,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "spell" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "spell_area" (
"spell_id" int PRIMARY KEY,
"details" varchar,
"type" spell_area_type NOT NULL,
"value" int NOT NULL
);
ALTER TABLE "spell_area" ADD FOREIGN KEY ("spell_id") REFERENCES "spell" ("id");
CREATE TABLE "spell_damage" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"spell_id" int NOT NULL,
"key" varchar NOT NULL,
"apply_mod" bool,
"category" spell_damage_category,
"formula" varchar NOT NULL,
"kinds" spell_damage_kinds NOT NULL,
"materials" varchar,
"type" varchar NOT NULL
);
ALTER TABLE "spell_damage" ADD FOREIGN KEY ("spell_id") REFERENCES "spell" ("id");
CREATE TABLE "spell_ritual" (
"spell_id" int PRIMARY KEY,
"primary_check" varchar NOT NULL,
"secondary_casters" int NOT NULL,
"secondary_checks" varchar NOT NULL
);
ALTER TABLE "spell_ritual" ADD FOREIGN KEY ("spell_id") REFERENCES "spell" ("id");
CREATE TABLE "spell_defense" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"spell_id" int NOT NULL,
"is_passive" bool NOT NULL,
"is_basic" bool,
"statistic" varchar NOT NULL
);
ALTER TABLE "spell_defense" ADD FOREIGN KEY ("spell_id") REFERENCES "spell" ("id");
-- Action
CREATE TYPE "action_type" AS ENUM (
'action',
'free',
'reaction',
'passive'
);
CREATE TYPE "action_category" AS ENUM (
'offensive',
'defensive',
'interaction',
'familiar'
);
CREATE TYPE "ancestry_vision" AS ENUM (
'normal',
'low_light_vision',
'darkvision'
);
CREATE TABLE "action" (
-- "id" int PRIMARY KEY,
"action_type" action_type NOT NULL,
"actions" int,
"category" action_category,
"death_note" bool,
"extra" text,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "action" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Ancestry
CREATE TABLE "ancestry" (
-- "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,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "ancestry" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "ancestry_languages" (
"ancestry_id" int,
"language_id" int,
"is_additional" bool NOT NULL,
PRIMARY KEY ("ancestry_id", "language_id")
);
ALTER TABLE "ancestry_languages" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");
ALTER TABLE "ancestry_languages" ADD FOREIGN KEY ("language_id") REFERENCES "language" ("id");
CREATE TABLE "ancestry_boosts" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"ancestry_id" int NOT NULL,
"boost" bool NOT NULL DEFAULT true,
"value" varchar(3)
);
ALTER TABLE "ancestry_boosts" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");
CREATE TABLE "ancestry_items" (
"ancestry_id" int,
"item_id" int,
"level" int NOT NULL,
PRIMARY KEY ("ancestry_id", "item_id")
);
ALTER TABLE "ancestry_items" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");
ALTER TABLE "ancestry_items" ADD FOREIGN KEY ("item_id") REFERENCES "entity" ("id");
-- Background
CREATE TABLE "background" (
-- "id" int PRIMARY KEY,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "background" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "background_items" (
"background_id" int,
"entity_id" int,
"level" int,
PRIMARY KEY ("background_id", "entity_id")
);
ALTER TABLE "background_items" ADD FOREIGN KEY ("background_id") REFERENCES "background" ("id");
ALTER TABLE "background_items" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
CREATE TABLE "background_skills" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"background_id" int NOT NULL,
"name" varchar NOT NULL,
"is_skill" bool NOT NULL
);
ALTER TABLE "background_skills" ADD FOREIGN KEY ("background_id") REFERENCES "background" ("id");
CREATE TABLE "background_boosts" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"background_id" int NOT NULL,
"value" varchar(3)
);
ALTER TABLE "background_boosts" ADD FOREIGN KEY ("background_id") REFERENCES "background" ("id");
-- Campaign Feature
CREATE TYPE "campaign_feature_category" AS ENUM (
'army_tactic',
'army_war_action',
'kingdom_activity',
'kingdom_feat',
'kingdom_feature'
);
CREATE TABLE "campaign_feature" (
-- "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,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "campaign_feature" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Class
CREATE TYPE "class_progression_type" AS ENUM (
'entity',
'ancestry_feat',
'class_feat',
'general_feat',
'skill_feat',
'skill_increase'
);
CREATE TABLE "class" (
-- "id" int PRIMARY KEY,
"hp" int NOT NULL,
"perception" int NOT NULL,
"spellcasting" bool NOT NULL,
"additionalTrainedSkills" int NOT NULL,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "class" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "class_key_abilities" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"class_id" int NOT NULL,
"value" varchar(3) NOT NULL
);
ALTER TABLE "class_key_abilities" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id");
CREATE TABLE "class_progression" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"class_id" int NOT NULL,
"level" int NOT NULL,
"type" class_progression_type NOT NULL,
"entity_id" int
);
ALTER TABLE "class_progression" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id");
ALTER TABLE "class_progression" ADD FOREIGN KEY ("entity_id") REFERENCES "entity" ("id");
CREATE TABLE "class_trainings" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"class_id" int NOT NULL,
"item" int,
"name" varchar,
"stage" int NOT NULL
);
ALTER TABLE "class_trainings" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id");
ALTER TABLE "class_trainings" ADD FOREIGN KEY ("item") REFERENCES "trainings" ("id");
-- Condition
CREATE TYPE "condition_group" AS ENUM (
'senses',
'abilities',
'death',
'attitudes',
'detection'
);
CREATE TABLE "condition" (
-- "id" int PRIMARY KEY,
"group" condition_group,
"extra" text,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "condition" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Deity
CREATE TYPE "deity_category" AS ENUM (
'deity',
'pantheon',
'covenant',
'philosophy'
);
CREATE TYPE "deity_fonts" AS ENUM (
'none',
'heal',
'harm',
'any'
);
CREATE TYPE "deity_sanctification" AS ENUM (
'holy',
'unholy',
'any'
);
CREATE TABLE "deity" (
-- "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,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "deity" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "deity_attributes" (
"deity_id" int,
"attribute" varchar(3),
PRIMARY KEY ("deity_id", "attribute")
);
ALTER TABLE "deity_attributes" ADD FOREIGN KEY ("deity_id") REFERENCES "deity" ("id");
CREATE TABLE "deity_skills" (
"deity_id" int,
"skill_id" int,
PRIMARY KEY ("deity_id", "skill_id")
);
ALTER TABLE "deity_skills" ADD FOREIGN KEY ("deity_id") REFERENCES "deity" ("id");
ALTER TABLE "deity_skills" ADD FOREIGN KEY ("skill_id") REFERENCES "trainings" ("id");
CREATE TABLE "deity_spells" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"deity_id" int NOT NULL,
"level" int NOT NULL,
"spell_id" int NOT NULL
);
ALTER TABLE "deity_spells" ADD FOREIGN KEY ("deity_id") REFERENCES "deity" ("id");
ALTER TABLE "deity_spells" ADD FOREIGN KEY ("spell_id") REFERENCES "spell" ("id");
CREATE TABLE "deity_weapons" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"deity_id" int NOT NULL,
"weapon" varchar NOT NULL
);
ALTER TABLE "deity_weapons" ADD FOREIGN KEY ("deity_id") REFERENCES "deity" ("id");
CREATE TABLE "deity_domains" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"deity_id" int NOT NULL,
"is_primary" bool NOT NULL,
"value" varchar NOT NULL
);
ALTER TABLE "deity_domains" ADD FOREIGN KEY ("deity_id") REFERENCES "deity" ("id");
-- Feat
CREATE TYPE "feat_category" AS ENUM (
'ancestryfeature',
'classfeature',
'calling',
'class',
'skill',
'general',
'ancestry',
'bonus',
'deityboon',
'curse',
'pfsboon'
);
CREATE TABLE "feat" (
-- "id" int PRIMARY KEY,
"action_type" action_type NOT NULL,
"actions" int,
"category" feat_category NOT NULL,
"level" int NOT NULL,
"level_taken" int,
"max_takable" int,
"location" varchar(12),
"only_level_1" bool,
"extra" text,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "feat" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "feat_prerequisites" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"feat_id" int NOT NULL,
"value" varchar NOT NULL
);
ALTER TABLE "feat_prerequisites" ADD FOREIGN KEY ("feat_id") REFERENCES "feat" ("id");
-- Heritage
CREATE TABLE "heritage" (
-- "id" int PRIMARY KEY,
"ancestry_id" int,
PRIMARY KEY ("id")
) INHERITS ("entity");
-- ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
ALTER TABLE "heritage" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");