Ещё пачка изменений

This commit is contained in:
2025-04-15 00:02:03 +04:00
parent 80b5770036
commit 9668807b46
26 changed files with 329 additions and 59 deletions
+96 -30
View File
@@ -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$;