feat(pokemon): allow duplicate display IDs to support multiple forms
Drop unique index on display_id to allow multiple forms under the same Pokopia number. Include sort_order in queries to ensure stable sorting for duplicate display IDs.
This commit is contained in:
@@ -1359,8 +1359,9 @@ CREATE INDEX IF NOT EXISTS skills_sort_order_idx ON skills(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS favorite_things_sort_order_idx ON favorite_things(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS pokemon_types_sort_order_idx ON pokemon_types(sort_order, id);
|
||||
DROP INDEX IF EXISTS pokemon_sort_order_idx;
|
||||
CREATE INDEX IF NOT EXISTS pokemon_display_order_idx ON pokemon(is_event_item, display_id, id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS pokemon_display_event_item_key ON pokemon(display_id, is_event_item);
|
||||
DROP INDEX IF EXISTS pokemon_display_event_item_key;
|
||||
DROP INDEX IF EXISTS pokemon_display_order_idx;
|
||||
CREATE INDEX IF NOT EXISTS pokemon_display_order_idx ON pokemon(is_event_item, display_id, sort_order, id);
|
||||
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);
|
||||
|
||||
@@ -2957,7 +2957,7 @@ export async function globalSearch(paramsQuery: QueryParams = {}, locale = defau
|
||||
${pokemonImageJson('p')} AS image
|
||||
FROM pokemon p
|
||||
WHERE ${pokemonName} ILIKE $1
|
||||
ORDER BY p.display_id, p.id
|
||||
ORDER BY p.display_id, p.sort_order, p.id
|
||||
LIMIT $2
|
||||
`,
|
||||
[pattern, limit]
|
||||
@@ -5847,7 +5847,7 @@ export async function listPokemon(paramsQuery: QueryParams, locale = defaultLoca
|
||||
}
|
||||
|
||||
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
||||
return queryMaybePaged(`${pokemonProjection(locale)} ${whereClause} ORDER BY p.display_id, p.id`, params, paramsQuery);
|
||||
return queryMaybePaged(`${pokemonProjection(locale)} ${whereClause} ORDER BY p.display_id, p.sort_order, p.id`, params, paramsQuery);
|
||||
}
|
||||
|
||||
export async function getPokemon(id: number, locale = defaultLocale) {
|
||||
@@ -6449,10 +6449,10 @@ export async function listHabitats(paramsQuery: QueryParams = {}, locale = defau
|
||||
'name', pokemon_rows.name,
|
||||
'isEventItem', pokemon_rows.is_event_item
|
||||
)
|
||||
ORDER BY pokemon_rows.display_id, pokemon_rows.id
|
||||
ORDER BY pokemon_rows.display_id, pokemon_rows.sort_order, pokemon_rows.id
|
||||
)
|
||||
FROM (
|
||||
SELECT DISTINCT p.id, p.display_id, ${pokemonName} AS name, p.is_event_item
|
||||
SELECT DISTINCT p.id, p.display_id, p.sort_order, ${pokemonName} AS name, p.is_event_item
|
||||
FROM habitat_pokemon hp
|
||||
JOIN pokemon p ON p.id = hp.pokemon_id
|
||||
WHERE hp.habitat_id = h.id
|
||||
@@ -6523,7 +6523,7 @@ export async function getHabitat(id: number, locale = defaultLocale) {
|
||||
JOIN pokemon p ON p.id = hp.pokemon_id
|
||||
JOIN maps m ON m.id = hp.map_id
|
||||
WHERE hp.habitat_id = $1
|
||||
ORDER BY hp.rarity, p.display_id, p.id, ${orderByEntity('m')}
|
||||
ORDER BY hp.rarity, p.display_id, p.sort_order, p.id, ${orderByEntity('m')}
|
||||
`,
|
||||
[id]
|
||||
),
|
||||
@@ -6935,7 +6935,7 @@ export async function getItem(id: number, locale = defaultLocale) {
|
||||
JOIN skills s ON s.id = psid.skill_id
|
||||
WHERE psid.item_id = $1
|
||||
AND s.has_item_drop = true
|
||||
ORDER BY p.display_id, p.id, ${orderByEntity('s')}
|
||||
ORDER BY p.display_id, p.sort_order, p.id, ${orderByEntity('s')}
|
||||
`,
|
||||
[id]
|
||||
),
|
||||
@@ -6976,7 +6976,7 @@ export async function getItem(id: number, locale = defaultLocale) {
|
||||
WHERE ps.pokemon_id = p.id
|
||||
AND trading_skill.has_trading = true
|
||||
)
|
||||
ORDER BY pti.preference DESC, p.display_id, p.id
|
||||
ORDER BY pti.preference DESC, p.display_id, p.sort_order, p.id
|
||||
`,
|
||||
[id]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user