fix: delete logic improved
This commit is contained in:
parent
76df4d8592
commit
cea7cd3cd8
1 changed files with 12 additions and 12 deletions
|
|
@ -28,8 +28,8 @@ CREATE TABLE reviews (
|
||||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
data text NOT NULL,
|
data text NOT NULL,
|
||||||
rating int CHECK (rating >= 0 AND rating <= 10),
|
rating int CHECK (rating >= 0 AND rating <= 10),
|
||||||
user_id bigint REFERENCES users (id),
|
user_id bigint REFERENCES users (id) ON DELETE SET NULL,
|
||||||
title_id bigint REFERENCES titles (id),
|
title_id bigint REFERENCES titles (id) ON DELETE CASCADE,
|
||||||
created_at timestamptz DEFAULT NOW()
|
created_at timestamptz DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -41,20 +41,20 @@ CREATE TABLE review_images (
|
||||||
|
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
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,
|
passhash text NOT NULL,
|
||||||
mail text CHECK (mail ~ '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+$'),
|
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,}$'),
|
nickname text UNIQUE NOT NULL CHECK (nickname ~ '^[a-zA-Z0-9_-]{3,}$'),
|
||||||
disp_name text,
|
disp_name text,
|
||||||
user_desc text,
|
user_desc text,
|
||||||
creation_date timestamptz NOT NULL,
|
creation_date timestamptz NOT NULL DEFAULT NOW(),
|
||||||
last_login timestamptz
|
last_login timestamptz
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE studios (
|
CREATE TABLE studios (
|
||||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
studio_name text NOT NULL UNIQUE,
|
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
|
studio_desc text
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ CREATE TABLE titles (
|
||||||
-- example {"ru": ["Атака титанов", "Атака Титанов"],"en": ["Attack on Titan", "AoT"],"ja": ["進撃の巨人", "しんげきのきょじん"]}
|
-- example {"ru": ["Атака титанов", "Атака Титанов"],"en": ["Attack on Titan", "AoT"],"ja": ["進撃の巨人", "しんげきのきょじん"]}
|
||||||
title_names jsonb NOT NULL,
|
title_names jsonb NOT NULL,
|
||||||
studio_id bigint NOT NULL REFERENCES studios (id),
|
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,
|
title_status title_status_t NOT NULL,
|
||||||
rating float CHECK (rating >= 0 AND rating <= 10),
|
rating float CHECK (rating >= 0 AND rating <= 10),
|
||||||
rating_count int CHECK (rating_count >= 0),
|
rating_count int CHECK (rating_count >= 0),
|
||||||
|
|
@ -82,19 +82,19 @@ CREATE TABLE titles (
|
||||||
|
|
||||||
CREATE TABLE usertitles (
|
CREATE TABLE usertitles (
|
||||||
PRIMARY KEY (user_id, title_id),
|
PRIMARY KEY (user_id, title_id),
|
||||||
user_id bigint NOT NULL REFERENCES users (id),
|
user_id bigint NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||||
title_id bigint NOT NULL REFERENCES titles (id),
|
title_id bigint NOT NULL REFERENCES titles (id) ON DELETE CASCADE,
|
||||||
status usertitle_status_t NOT NULL,
|
status usertitle_status_t NOT NULL,
|
||||||
rate int CHECK (rate > 0 AND rate <= 10),
|
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()
|
ctime timestamptz NOT NULL DEFAULT now()
|
||||||
-- // TODO: series status
|
-- // TODO: series status
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE title_tags (
|
CREATE TABLE title_tags (
|
||||||
PRIMARY KEY (title_id, tag_id),
|
PRIMARY KEY (title_id, tag_id),
|
||||||
title_id bigint NOT NULL REFERENCES titles (id),
|
title_id bigint NOT NULL REFERENCES titles (id) ON DELETE CASCADE,
|
||||||
tag_id bigint NOT NULL REFERENCES tags (id)
|
tag_id bigint NOT NULL REFERENCES tags (id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE signals (
|
CREATE TABLE signals (
|
||||||
|
|
@ -180,6 +180,6 @@ END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE TRIGGER set_ctime_on_update
|
CREATE TRIGGER set_ctime_on_update
|
||||||
BEFORE UPDATE ON usertitles
|
AFTER UPDATE ON usertitles
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION set_ctime();
|
EXECUTE FUNCTION set_ctime();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue