Separate PokeAPI ID from national dex for correct form identification

Pokemon forms (e.g., Alolan Rattata) had their PokeAPI ID (10091) stored as
national_dex, causing them to display incorrectly. This renames the unique
identifier to pokeapi_id and adds a real national_dex field shared between
forms and their base species, so Alolan Rattata correctly shows as #19.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 14:55:06 +01:00
parent cb027e5215
commit d168d99bba
46 changed files with 23459 additions and 22289 deletions

View File

@@ -0,0 +1,53 @@
"""rename national_dex to pokeapi_id, add real national_dex
Revision ID: e5f6a7b8c9d0
Revises: d4e5f6a7b8c9
Create Date: 2026-02-07 10:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'e5f6a7b8c9d0'
down_revision: Union[str, Sequence[str], None] = 'd4e5f6a7b8c9'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Rename national_dex -> pokeapi_id and widen to Integer
op.alter_column(
'pokemon', 'national_dex',
new_column_name='pokeapi_id',
type_=sa.Integer(),
existing_type=sa.SmallInteger(),
existing_nullable=False,
)
# Add real national_dex column (shared between forms and base species)
op.add_column(
'pokemon',
sa.Column('national_dex', sa.SmallInteger(), nullable=False, server_default='0'),
)
# Populate national_dex = pokeapi_id for all existing rows
# (correct for base species; forms will be fixed by re-seeding)
op.execute('UPDATE pokemon SET national_dex = pokeapi_id')
# Remove the default now that all rows are populated
op.alter_column('pokemon', 'national_dex', server_default=None)
def downgrade() -> None:
op.drop_column('pokemon', 'national_dex')
op.alter_column(
'pokemon', 'pokeapi_id',
new_column_name='national_dex',
type_=sa.SmallInteger(),
existing_type=sa.Integer(),
existing_nullable=False,
)