fix: delete logic improved
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m38s
Build and Deploy Go App / deploy (push) Successful in 25s

This commit is contained in:
Iron_Felix 2025-11-25 01:56:48 +03:00
parent 76df4d8592
commit cea7cd3cd8

View file

@ -28,8 +28,8 @@ CREATE TABLE reviews (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
data text NOT NULL,
rating int CHECK (rating >= 0 AND rating <= 10),
user_id bigint REFERENCES users (id),
title_id bigint REFERENCES titles (id),
user_id bigint REFERENCES users (id) ON DELETE SET NULL,
title_id bigint REFERENCES titles (id) ON DELETE CASCADE,
created_at timestamptz DEFAULT NOW()
);
@ -41,20 +41,20 @@ CREATE TABLE review_images (
CREATE TABLE users (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
avatar_id bigint REFERENCES images (id),
avatar_id bigint REFERENCES images (id) ON DELETE SET NULL,
passhash text NOT NULL,
mail text CHECK (mail ~ '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+$'),
nickname text UNIQUE NOT NULL CHECK (nickname ~ '^[a-zA-Z0-9_-]{3,}$'),
disp_name text,
user_desc text,
creation_date timestamptz NOT NULL,
creation_date timestamptz NOT NULL DEFAULT NOW(),
last_login timestamptz
);
CREATE TABLE studios (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
studio_name text NOT NULL UNIQUE,
illust_id bigint REFERENCES images (id),
illust_id bigint REFERENCES images (id) ON DELETE SET NULL,
studio_desc text
);
@ -64,7 +64,7 @@ CREATE TABLE titles (
-- example {"ru": ["Атака титанов", "Атака Титанов"],"en": ["Attack on Titan", "AoT"],"ja": ["進撃の巨人", "しんげきのきょじん"]}
title_names jsonb NOT NULL,
studio_id bigint NOT NULL REFERENCES studios (id),
poster_id bigint REFERENCES images (id),
poster_id bigint REFERENCES images (id) ON DELETE SET NULL,
title_status title_status_t NOT NULL,
rating float CHECK (rating >= 0 AND rating <= 10),
rating_count int CHECK (rating_count >= 0),
@ -82,19 +82,19 @@ CREATE TABLE titles (
CREATE TABLE usertitles (
PRIMARY KEY (user_id, title_id),
user_id bigint NOT NULL REFERENCES users (id),
title_id bigint NOT NULL REFERENCES titles (id),
user_id bigint NOT NULL REFERENCES users (id) ON DELETE CASCADE,
title_id bigint NOT NULL REFERENCES titles (id) ON DELETE CASCADE,
status usertitle_status_t NOT NULL,
rate int CHECK (rate > 0 AND rate <= 10),
review_id bigint REFERENCES reviews (id),
review_id bigint REFERENCES reviews (id) ON DELETE SET NULL,
ctime timestamptz NOT NULL DEFAULT now()
-- // TODO: series status
);
CREATE TABLE title_tags (
PRIMARY KEY (title_id, tag_id),
title_id bigint NOT NULL REFERENCES titles (id),
tag_id bigint NOT NULL REFERENCES tags (id)
title_id bigint NOT NULL REFERENCES titles (id) ON DELETE CASCADE,
tag_id bigint NOT NULL REFERENCES tags (id) ON DELETE CASCADE
);
CREATE TABLE signals (
@ -180,6 +180,6 @@ END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER set_ctime_on_update
BEFORE UPDATE ON usertitles
AFTER UPDATE ON usertitles
FOR EACH ROW
EXECUTE FUNCTION set_ctime();