From 570b5296aea2327f525d95f565ddf40dcf4d5ae1 Mon Sep 17 00:00:00 2001 From: Ilya Kozhemyakin Date: Mon, 14 Apr 2025 00:16:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbml/description.md | 5 + dbml/schema.dbml | 6 +- dbml/schema.sql | 565 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 574 insertions(+), 2 deletions(-) create mode 100644 dbml/description.md create mode 100644 dbml/schema.sql diff --git a/dbml/description.md b/dbml/description.md new file mode 100644 index 0000000..6d29ef9 --- /dev/null +++ b/dbml/description.md @@ -0,0 +1,5 @@ +# Структура таблиц + +## `entity` - корневой объект + +- `id` - diff --git a/dbml/schema.dbml b/dbml/schema.dbml index 933f2b4..2cd63b7 100644 --- a/dbml/schema.dbml +++ b/dbml/schema.dbml @@ -8,12 +8,14 @@ Table entity { img varchar(100) [not null, note: "{*}.img"] description text [not null, note: "{*}.system.description(.value)"] description_gm text [null, note: "{*}.system.description.gm"] - type entity_type [not null] - slug varchar [not null] + type entity_type [not null, note: "Таблица, к которому относится объект"] + slug varchar [not null, note: "Отображения"] rarity entity_rarity [not null, default: "common", note: "{*}.system.traits.rarity"] is_translated bool [default: false, note: "Первичный импорт идёт из англоязычного источника, перевод приходит вторым"] is_checked bool [default: false, note: "Флаг, указывающий, что перевод был проверен вручную и не требует обновления парсером"] + + } Enum entity_type { action diff --git a/dbml/schema.sql b/dbml/schema.sql new file mode 100644 index 0000000..c6a110a --- /dev/null +++ b/dbml/schema.sql @@ -0,0 +1,565 @@ +-- 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 +) 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, + "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"); + + +-- 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 +) 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 +) 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, + "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"); + + +-- 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 +) 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 +) 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 +) 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_action_type" AS ENUM ( + 'passive', + 'action', + 'reaction', + 'free' +); +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" feat_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 +) 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 +) INHERITS ("entity"); +ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); +ALTER TABLE "heritage" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");