feat(pokemon): add opposite relationships and redesign detail view

Add description and opposite relationships to environments and favorite things
Move pokedex reference data (stats, dimensions, types) to a separate tab
Highlight core mechanics (skills, habitat, favorite things) in detail view
Update related pokemon scoring to account for opposite relationships
This commit is contained in:
2026-05-07 15:57:38 +08:00
parent a781bc559b
commit 953b90eba1
8 changed files with 489 additions and 96 deletions

View File

@@ -109,11 +109,14 @@ CREATE INDEX IF NOT EXISTS user_follows_followed_created_idx
CREATE TABLE IF NOT EXISTS environments (
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name text NOT NULL UNIQUE,
description text NOT NULL DEFAULT '',
opposite_environment_id integer REFERENCES environments(id) ON DELETE SET NULL,
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()
updated_at timestamptz NOT NULL DEFAULT now(),
CHECK (opposite_environment_id IS NULL OR opposite_environment_id <> id)
);
CREATE TABLE IF NOT EXISTS roles (
@@ -1071,11 +1074,13 @@ CREATE TABLE IF NOT EXISTS skills (
CREATE TABLE IF NOT EXISTS favorite_things (
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name text NOT NULL UNIQUE,
opposite_favorite_thing_id integer REFERENCES favorite_things(id) ON DELETE SET NULL,
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()
updated_at timestamptz NOT NULL DEFAULT now(),
CHECK (opposite_favorite_thing_id IS NULL OR opposite_favorite_thing_id <> id)
);
CREATE TABLE IF NOT EXISTS pokemon_types (
@@ -1526,6 +1531,50 @@ ALTER TABLE skills
ALTER TABLE items
ADD COLUMN IF NOT EXISTS dyeability integer NOT NULL DEFAULT 0 CHECK (dyeability IN (0, 1, 2, 3));
ALTER TABLE environments
ADD COLUMN IF NOT EXISTS description text NOT NULL DEFAULT '';
ALTER TABLE environments
ADD COLUMN IF NOT EXISTS opposite_environment_id integer;
ALTER TABLE favorite_things
ADD COLUMN IF NOT EXISTS opposite_favorite_thing_id integer;
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'environments_opposite_environment_id_fkey'
) THEN
ALTER TABLE environments
ADD CONSTRAINT environments_opposite_environment_id_fkey
FOREIGN KEY (opposite_environment_id) REFERENCES environments(id) ON DELETE SET NULL;
END IF;
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'environments_opposite_environment_id_check'
) THEN
ALTER TABLE environments
ADD CONSTRAINT environments_opposite_environment_id_check
CHECK (opposite_environment_id IS NULL OR opposite_environment_id <> id);
END IF;
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'favorite_things_opposite_favorite_thing_id_fkey'
) THEN
ALTER TABLE favorite_things
ADD CONSTRAINT favorite_things_opposite_favorite_thing_id_fkey
FOREIGN KEY (opposite_favorite_thing_id) REFERENCES favorite_things(id) ON DELETE SET NULL;
END IF;
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'favorite_things_opposite_favorite_thing_id_check'
) THEN
ALTER TABLE favorite_things
ADD CONSTRAINT favorite_things_opposite_favorite_thing_id_check
CHECK (opposite_favorite_thing_id IS NULL OR opposite_favorite_thing_id <> id);
END IF;
END $$;
UPDATE items
SET dyeability = CASE
WHEN dual_dyeable THEN 2