Переход от наследования таблиц на 1-1 связи

This commit is contained in:
2025-04-15 11:55:10 +04:00
parent a087807fe4
commit 5475b6ab46
20 changed files with 491 additions and 752 deletions
+33 -31
View File
@@ -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$