feat(pokemon): store official data identity separate from display ID

Add data_id and data_identifier to pokemon schema
Use official data ID as internal route ID for non-event pokemon
Prevent applying fetched data with mismatched ID to existing pokemon
This commit is contained in:
2026-05-04 00:06:22 +08:00
parent 8dfd03f3d2
commit fa06d24826
6 changed files with 103 additions and 44 deletions

View File

@@ -712,6 +712,8 @@ CREATE TABLE IF NOT EXISTS pokemon_types (
CREATE TABLE IF NOT EXISTS pokemon (
id integer PRIMARY KEY,
data_id integer CHECK (data_id > 0),
data_identifier text NOT NULL DEFAULT '',
display_id integer NOT NULL CHECK (display_id > 0),
name text NOT NULL UNIQUE,
is_event_item boolean NOT NULL DEFAULT false,
@@ -738,6 +740,10 @@ CREATE TABLE IF NOT EXISTS pokemon (
updated_at timestamptz NOT NULL DEFAULT now()
);
ALTER TABLE pokemon
ADD COLUMN IF NOT EXISTS data_id integer CHECK (data_id > 0),
ADD COLUMN IF NOT EXISTS data_identifier text NOT NULL DEFAULT '';
CREATE TABLE IF NOT EXISTS pokemon_pokemon_types (
pokemon_id integer NOT NULL REFERENCES pokemon(id) ON DELETE CASCADE,
type_id integer NOT NULL REFERENCES pokemon_types(id) ON DELETE CASCADE,