refactor(life): remove life categories and ratings
Drop life_tags and life_post_ratings tables and related schema Remove category selection and rating UI from Life posts Simplify Life feed filters and API endpoints
This commit is contained in:
@@ -32,7 +32,6 @@ CREATE TABLE IF NOT EXISTS entity_translations (
|
||||
'maps',
|
||||
'habitats',
|
||||
'daily-checklist-items',
|
||||
'life-tags',
|
||||
'game-versions',
|
||||
'dish-categories',
|
||||
'dish-flavors',
|
||||
@@ -46,6 +45,31 @@ CREATE TABLE IF NOT EXISTS entity_translations (
|
||||
PRIMARY KEY (entity_type, entity_id, locale, field_name)
|
||||
);
|
||||
|
||||
DELETE FROM entity_translations
|
||||
WHERE entity_type = 'life-tags';
|
||||
|
||||
ALTER TABLE entity_translations
|
||||
DROP CONSTRAINT IF EXISTS entity_translations_entity_type_check,
|
||||
ADD CONSTRAINT entity_translations_entity_type_check CHECK (
|
||||
entity_type IN (
|
||||
'pokemon',
|
||||
'pokemon-types',
|
||||
'skills',
|
||||
'environments',
|
||||
'favorite-things',
|
||||
'acquisition-methods',
|
||||
'items',
|
||||
'ancient-artifacts',
|
||||
'maps',
|
||||
'habitats',
|
||||
'daily-checklist-items',
|
||||
'game-versions',
|
||||
'dish-categories',
|
||||
'dish-flavors',
|
||||
'dishes'
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS entity_translations_lookup_idx
|
||||
ON entity_translations (entity_type, entity_id, field_name, locale);
|
||||
|
||||
@@ -266,7 +290,6 @@ VALUES
|
||||
('life.comments.delete-any', 'Delete any Life comment', 'Delete any Life comment.', 'Life', true),
|
||||
('life.comments.like', 'Like Life comments', 'Like and unlike Life comments.', 'Life', true),
|
||||
('life.reactions.set', 'Set Life reactions', 'Set and remove Life reactions.', 'Life', true),
|
||||
('life.ratings.set', 'Set Life ratings', 'Set and remove Life star ratings.', 'Life', true),
|
||||
('threads.create', 'Create Threads', 'Create forum threads.', 'Threads', true),
|
||||
('threads.messages.create', 'Create Thread messages', 'Create chat messages inside Threads.', 'Threads', true),
|
||||
('threads.follow', 'Follow Threads', 'Follow Threads and manage read state.', 'Threads', true),
|
||||
@@ -288,6 +311,9 @@ ON CONFLICT (key) DO NOTHING;
|
||||
DELETE FROM permissions
|
||||
WHERE key = 'pokemon.order';
|
||||
|
||||
DELETE FROM permissions
|
||||
WHERE key = 'life.ratings.set';
|
||||
|
||||
INSERT INTO roles (key, name, description, level, enabled, system_role)
|
||||
VALUES
|
||||
('owner', 'Owner', 'Highest-level system owner with all permissions.', 1000, true, true),
|
||||
@@ -377,7 +403,6 @@ JOIN permissions p ON p.key = ANY (ARRAY[
|
||||
'life.comments.delete-any',
|
||||
'life.comments.like',
|
||||
'life.reactions.set',
|
||||
'life.ratings.set',
|
||||
'threads.create',
|
||||
'threads.messages.create',
|
||||
'threads.follow',
|
||||
@@ -461,7 +486,6 @@ JOIN permissions p ON p.key = ANY (ARRAY[
|
||||
'life.comments.delete',
|
||||
'life.comments.like',
|
||||
'life.reactions.set',
|
||||
'life.ratings.set',
|
||||
'threads.create',
|
||||
'threads.messages.create',
|
||||
'threads.follow',
|
||||
@@ -538,7 +562,6 @@ JOIN permissions p ON p.key = ANY (ARRAY[
|
||||
'life.comments.delete',
|
||||
'life.comments.like',
|
||||
'life.reactions.set',
|
||||
'life.ratings.set',
|
||||
'threads.create',
|
||||
'threads.messages.create',
|
||||
'threads.follow',
|
||||
@@ -556,13 +579,6 @@ WHERE r.key = 'member'
|
||||
)
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
INSERT INTO role_permissions (role_id, permission_id)
|
||||
SELECT r.id, p.id
|
||||
FROM roles r
|
||||
JOIN permissions p ON p.key = 'life.ratings.set'
|
||||
WHERE r.key IN ('admin', 'editor', 'member')
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
INSERT INTO role_permissions (role_id, permission_id)
|
||||
SELECT r.id, p.id
|
||||
FROM roles r
|
||||
@@ -725,18 +741,6 @@ CREATE TABLE IF NOT EXISTS daily_checklist_items (
|
||||
CREATE INDEX IF NOT EXISTS daily_checklist_items_sort_order_idx
|
||||
ON daily_checklist_items(sort_order, id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS life_tags (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text NOT NULL UNIQUE,
|
||||
is_default boolean NOT NULL DEFAULT false,
|
||||
is_rateable boolean NOT NULL DEFAULT false,
|
||||
sort_order integer NOT NULL DEFAULT 0 CHECK (sort_order >= 0),
|
||||
created_by_user_id integer REFERENCES users(id) ON DELETE SET NULL,
|
||||
updated_by_user_id integer REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS game_versions (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text NOT NULL UNIQUE,
|
||||
@@ -754,7 +758,6 @@ CREATE INDEX IF NOT EXISTS game_versions_sort_order_idx
|
||||
CREATE TABLE IF NOT EXISTS life_posts (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
body text NOT NULL CHECK (length(body) BETWEEN 1 AND 2000),
|
||||
category_id integer REFERENCES life_tags(id) ON DELETE RESTRICT,
|
||||
game_version_id integer REFERENCES game_versions(id) ON DELETE SET NULL,
|
||||
ai_moderation_status text NOT NULL DEFAULT 'unreviewed' CHECK (ai_moderation_status IN ('unreviewed', 'reviewing', 'approved', 'rejected', 'failed')),
|
||||
ai_moderation_language_code text REFERENCES languages(code) ON DELETE SET NULL,
|
||||
@@ -782,14 +785,14 @@ CREATE INDEX IF NOT EXISTS life_posts_user_created_at_idx
|
||||
ON life_posts(created_by_user_id, created_at DESC, id DESC)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS life_post_tags (
|
||||
post_id integer NOT NULL REFERENCES life_posts(id) ON DELETE CASCADE,
|
||||
tag_id integer NOT NULL REFERENCES life_tags(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (post_id, tag_id)
|
||||
);
|
||||
DROP INDEX IF EXISTS life_posts_category_idx;
|
||||
DROP TABLE IF EXISTS life_post_ratings;
|
||||
DROP TABLE IF EXISTS life_post_tags;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS life_post_tags_tag_idx
|
||||
ON life_post_tags(tag_id, post_id);
|
||||
ALTER TABLE life_posts
|
||||
DROP COLUMN IF EXISTS category_id;
|
||||
|
||||
DROP TABLE IF EXISTS life_tags;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS life_post_comments (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
@@ -847,21 +850,6 @@ CREATE INDEX IF NOT EXISTS life_post_reactions_post_idx
|
||||
CREATE INDEX IF NOT EXISTS life_post_reactions_user_idx
|
||||
ON life_post_reactions(user_id, updated_at DESC, post_id DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS life_post_ratings (
|
||||
post_id integer NOT NULL REFERENCES life_posts(id) ON DELETE CASCADE,
|
||||
user_id integer NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
rating integer NOT NULL CHECK (rating BETWEEN 1 AND 5),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (post_id, user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS life_post_ratings_post_idx
|
||||
ON life_post_ratings(post_id, rating);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS life_post_ratings_user_idx
|
||||
ON life_post_ratings(user_id, updated_at DESC, post_id DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS thread_channels (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text NOT NULL UNIQUE,
|
||||
@@ -1344,8 +1332,6 @@ CREATE INDEX IF NOT EXISTS favorite_things_sort_order_idx ON favorite_things(sor
|
||||
CREATE INDEX IF NOT EXISTS pokemon_types_sort_order_idx ON pokemon_types(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS pokemon_sort_order_idx ON pokemon(sort_order, id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS pokemon_display_event_item_key ON pokemon(display_id, is_event_item);
|
||||
CREATE INDEX IF NOT EXISTS life_tags_sort_order_idx ON life_tags(sort_order, id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS life_tags_single_default_idx ON life_tags(is_default) WHERE is_default = true;
|
||||
CREATE INDEX IF NOT EXISTS acquisition_methods_sort_order_idx ON acquisition_methods(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS items_sort_order_idx ON items(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS recipes_sort_order_idx ON recipes(sort_order, id);
|
||||
@@ -1506,10 +1492,6 @@ CREATE TABLE IF NOT EXISTS notification_ws_tickets (
|
||||
CREATE INDEX IF NOT EXISTS notification_ws_tickets_user_idx
|
||||
ON notification_ws_tickets(user_id, expires_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS life_posts_category_idx
|
||||
ON life_posts(category_id, created_at DESC, id DESC)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS life_posts_game_version_idx
|
||||
ON life_posts(game_version_id, created_at DESC, id DESC)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
Reference in New Issue
Block a user