Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ make docker-migrate
When you start PokéAPI with the above Docker Compose setup, an [Hasura Engine](https://github.com/hasura/graphql-engine) server is started as well. It's possible to track all the PokeAPI tables and foreign keys by simply

```sh
# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli.html
# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/2.0/hasura-cli/install-hasura-cli
# hasura cli's version has to greater than v2.48.1
make hasura-apply
```
Expand Down
12 changes: 11 additions & 1 deletion data/v2/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ def csv_record_to_objects(info):
id=int(info[0]),
name=info[1],
item_category_id=int(info[2]),
cost=int(info[3]),
fling_power=int(info[4]) if info[4] != "" else None,
item_fling_effect_id=int(info[5]) if info[5] != "" else None,
)
Expand Down Expand Up @@ -544,6 +543,17 @@ def csv_record_to_objects(info):

build_generic((ItemGameIndex,), "item_game_indices.csv", csv_record_to_objects)

def csv_record_to_objects(info):
yield ItemPrice(
item_id=int(info[0]),
version_group_id=int(info[1]),
is_purchasable=bool(int(info[2])),
purchase_price=int(info[3]) if info[3] else None,
sell_price=int(info[4]) if info[4] else None,
)

build_generic((ItemPrice,), "item_prices.csv", csv_record_to_objects)

def csv_record_to_objects(info):
yield ItemFlavorText(
item_id=int(info[0]),
Expand Down
28 changes: 28 additions & 0 deletions data/v2/csv/item_prices.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
item_id,version_group_id,is_purchasable,purchase_price,sell_price
305,1,1,3000,1500
305,2,1,3000,1500
305,3,0,,1500
305,4,0,,1500
305,5,0,,1500
305,6,0,,1500
305,7,0,,1500
305,16,1,5000,
305,20,1,40000,
305,23,1,,1500
305,25,1,,400
305,28,1,3000,1500
305,29,1,3000,1500
306,1,1,2000,1000
306,2,1,2000,1000
306,3,1,2000,1000
306,4,1,2000,1000
306,5,0,,1500
306,6,0,,1500
306,7,0,,1500
306,8,0,,1500
306,9,0,,1500
306,10,0,,1500
306,12,0,,1500
306,13,0,,1500
306,23,1,,1500
306,25,1,,400
1 change: 0 additions & 1 deletion graphql/v1beta/examples/go/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ query pokemon_details($name: String) {
fireRedItems: pokemon_v2_pokemonitems(where: {pokemon_v2_version: {name: {_eq: "firered"}}}) {
pokemon_v2_item {
name
cost
}
rarity
}
Expand Down
1 change: 0 additions & 1 deletion graphql/v1beta/examples/node/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ function fetchPokemon_details(name="starmie") {
fireRedItems: pokemon_v2_pokemonitems(where: {pokemon_v2_version: {name: {_eq: "firered"}}}) {
pokemon_v2_item {
name
cost
}
rarity
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ array_relationships:
table:
name: pokemon_v2_itemname
schema: public
- name: pokemon_v2_itemprices
using:
foreign_key_constraint_on:
column: item_id
table:
name: pokemon_v2_itemprice
schema: public
- name: pokemon_v2_itemsprites
using:
foreign_key_constraint_on:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
table:
name: pokemon_v2_itemprice
schema: public
object_relationships:
- name: pokemon_v2_item
using:
foreign_key_constraint_on: item_id
- name: pokemon_v2_versiongroup
using:
foreign_key_constraint_on: version_group_id
select_permissions:
- role: anon
permission:
columns: '*'
filter: {}
limit: 100000
allow_aggregations: true
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ array_relationships:
table:
name: pokemon_v2_itemflavortext
schema: public
- name: pokemon_v2_itemprices
using:
foreign_key_constraint_on:
column: version_group_id
table:
name: pokemon_v2_itemprice
schema: public
- name: pokemon_v2_machines
using:
foreign_key_constraint_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- "!include public_pokemon_v2_itemflingeffecteffecttext.yaml"
- "!include public_pokemon_v2_itemgameindex.yaml"
- "!include public_pokemon_v2_itemname.yaml"
- "!include public_pokemon_v2_itemprice.yaml"
- "!include public_pokemon_v2_itempocket.yaml"
- "!include public_pokemon_v2_itempocketname.yaml"
- "!include public_pokemon_v2_itemsprites.yaml"
Expand Down
1 change: 0 additions & 1 deletion graphql/v1beta2/examples/go/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ query pokemon_details($name: String) {
fireRedItems: pokemonitems(where: {version: {name: {_eq: "firered"}}}) {
item {
name
cost
}
rarity
}
Expand Down
1 change: 0 additions & 1 deletion graphql/v1beta2/examples/node/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ function fetchPokemon_details(name="starmie") {
fireRedItems: pokemonitems(where: {version: {name: {_eq: "firered"}}}) {
item {
name
cost
}
rarity
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ array_relationships:
table:
name: pokemon_v2_itemname
schema: public
- name: itemprices
using:
foreign_key_constraint_on:
column: item_id
table:
name: pokemon_v2_itemprice
schema: public
- name: itemsprites
using:
foreign_key_constraint_on:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
table:
name: pokemon_v2_itemprice
schema: public
configuration:
column_config: {}
custom_column_names: {}
custom_name: itemprice
custom_root_fields: {}
object_relationships:
- name: item
using:
foreign_key_constraint_on: item_id
- name: versiongroup
using:
foreign_key_constraint_on: version_group_id
select_permissions:
- role: anon
permission:
columns: '*'
filter: {}
limit: 100000
allow_aggregations: true
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ array_relationships:
table:
name: pokemon_v2_itemflavortext
schema: public
- name: itemprices
using:
foreign_key_constraint_on:
column: version_group_id
table:
name: pokemon_v2_itemprice
schema: public
- name: machines
using:
foreign_key_constraint_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- "!include public_pokemon_v2_itemflingeffecteffecttext.yaml"
- "!include public_pokemon_v2_itemgameindex.yaml"
- "!include public_pokemon_v2_itemname.yaml"
- "!include public_pokemon_v2_itemprice.yaml"
- "!include public_pokemon_v2_itempocket.yaml"
- "!include public_pokemon_v2_itempocketname.yaml"
- "!include public_pokemon_v2_itemsprites.yaml"
Expand Down
29 changes: 23 additions & 6 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4659,10 +4659,6 @@ components:
name:
type: string
maxLength: 200
cost:
type:
- integer
- 'null'
fling_power:
type:
- integer
Expand Down Expand Up @@ -4704,6 +4700,11 @@ components:
items:
$ref: '#/components/schemas/ItemGameIndex'
readOnly: true
prices:
type: array
items:
$ref: '#/components/schemas/ItemPrice'
readOnly: true
names:
type: array
items:
Expand Down Expand Up @@ -4923,6 +4924,24 @@ components:
required:
- language
- name
ItemPrice:
type: object
properties:
is_purchasable:
type: boolean
purchase_price:
type:
- integer
- 'null'
sell_price:
type:
- integer
- 'null'
version_group:
$ref: '#/components/schemas/VersionGroupSummary'
required:
- is_purchasable
- version_group
ItemPocketDetail:
type: object
properties:
Expand Down Expand Up @@ -7530,7 +7549,6 @@ components:
- name
- names
- pokemon_entries
- region
- version_groups
PokedexName:
type: object
Expand Down Expand Up @@ -8638,7 +8656,6 @@ components:
required:
- id
- locations
- main_generation
- name
- names
- pokedexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,6 @@ class Migration(migrations.Migration):
),
),
("name", models.CharField(max_length=100)),
("cost", models.IntegerField(null=True, blank=True)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't touch old migration files.

("fling_power", models.IntegerField(null=True, blank=True)),
],
options={
Expand Down
54 changes: 54 additions & 0 deletions pokemon_v2/migrations/0026_itemprice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 5.2.10 on 2026-03-07 00:00

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("pokemon_v2", "0025_pokemonstatpast"),
]

operations = [
migrations.CreateModel(
name="ItemPrice",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("is_purchasable", models.BooleanField()),
("purchase_price", models.IntegerField(blank=True, null=True)),
("sell_price", models.IntegerField(blank=True, null=True)),
(
"item",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s",
to="pokemon_v2.item",
),
),
(
"version_group",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s",
to="pokemon_v2.versiongroup",
),
),
],
options={
"abstract": False,
},
),
]
8 changes: 6 additions & 2 deletions pokemon_v2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,6 @@ class ItemFlingEffectEffectText(HasLanguage, HasEffect, HasFlingEffect):


class Item(HasName, HasItemCategory, HasFlingEffect):
cost = models.IntegerField(blank=True, null=True)

fling_power = models.IntegerField(blank=True, null=True)


Expand Down Expand Up @@ -885,6 +883,12 @@ class ItemGameIndex(HasItem, HasGeneration, HasGameIndex):
pass


class ItemPrice(HasItem, HasVersionGroup):
is_purchasable = models.BooleanField()
purchase_price = models.IntegerField(blank=True, null=True)
sell_price = models.IntegerField(blank=True, null=True)


class ItemSprites(HasItem):
sprites = models.JSONField()

Expand Down
11 changes: 10 additions & 1 deletion pokemon_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,14 @@ class Meta:
fields = ("game_index", "generation")


class ItemPriceSerializer(serializers.ModelSerializer):
version_group = VersionGroupSummarySerializer()

class Meta:
model = ItemPrice
fields = ("is_purchasable", "purchase_price", "sell_price", "version_group")


class ItemNameSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()

Expand All @@ -1825,6 +1833,7 @@ class ItemDetailSerializer(serializers.ModelSerializer):
game_indices = ItemGameIndexSerializer(
many=True, read_only=True, source="itemgameindex"
)
prices = ItemPriceSerializer(many=True, read_only=True, source="itemprice")
effect_entries = ItemEffectTextSerializer(
many=True, read_only=True, source="itemeffecttext"
)
Expand All @@ -1844,14 +1853,14 @@ class Meta:
fields = (
"id",
"name",
"cost",
"fling_power",
"fling_effect",
"attributes",
"category",
"effect_entries",
"flavor_text_entries",
"game_indices",
"prices",
"names",
"held_by_pokemon",
"sprites",
Expand Down
Loading