3 from sqlalchemy
import Column
, ForeignKey
, MetaData
, Table
4 from sqlalchemy
.ext
.declarative
import declarative_base
5 from sqlalchemy
.ext
.associationproxy
import association_proxy
6 from sqlalchemy
.orm
import backref
, relation
7 from sqlalchemy
.sql
import and_
8 from sqlalchemy
.types
import *
9 from sqlalchemy
.databases
.mysql
import *
11 from pokedex
.db
import rst
14 TableBase
= declarative_base(metadata
=metadata
)
16 class Ability(TableBase
):
17 __tablename__
= 'abilities'
18 __singlename__
= 'ability'
19 id = Column(Integer
, primary_key
=True, nullable
=False)
20 name
= Column(Unicode(24), nullable
=False)
21 flavor_text
= Column(Unicode(64), nullable
=False)
22 effect
= Column(Unicode(255), nullable
=False)
24 class ContestCombo(TableBase
):
25 __tablename__
= 'contest_combos'
26 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
27 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
29 class ContestEffect(TableBase
):
30 __tablename__
= 'contest_effects'
31 id = Column(Integer
, primary_key
=True, nullable
=False)
32 appeal
= Column(SmallInteger
, nullable
=False)
33 jam
= Column(SmallInteger
, nullable
=False)
34 flavor_text
= Column(Unicode(64), nullable
=False)
35 effect
= Column(Unicode(255), nullable
=False)
37 class EggGroup(TableBase
):
38 __tablename__
= 'egg_groups'
39 id = Column(Integer
, primary_key
=True, nullable
=False)
40 name
= Column(Unicode(16), nullable
=False)
42 class Encounter(TableBase
):
43 """Rows in this table represent encounters with wild Pokémon. Bear with
46 Within a given area in a given game, encounters are differentiated by the
47 "slot" they are in and the state of the game world.
49 What the player is doing to get an encounter, such as surfing or walking
50 through tall grass, is called terrain. Each terrain has its own set of
53 Within a terrain, slots are defined primarily by rarity. Each slot can
54 also be affected by world conditions; for example, the 20% slot for walking
55 in tall grass is affected by whether a swarm is in effect in that area.
56 "Is there a swarm?" is a condition; "there is a swarm" and "there is not a
57 swarm" are the possible values of this condition.
59 A slot (20% walking in grass) and any appropriate world conditions (no
60 swarm) are thus enough to define a specific encounter.
62 Well, okay, almost: each slot actually appears twice.
65 __tablename__
= 'encounters'
66 id = Column(Integer
, primary_key
=True, nullable
=False)
67 version_id
= Column(Integer
, ForeignKey('versions.id'), nullable
=False, autoincrement
=False)
68 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), nullable
=False, autoincrement
=False)
69 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), nullable
=False, autoincrement
=False)
70 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), nullable
=False, autoincrement
=False)
71 min_level
= Column(Integer
, nullable
=False, autoincrement
=False)
72 max_level
= Column(Integer
, nullable
=False, autoincrement
=False)
74 class EncounterCondition(TableBase
):
75 """Rows in this table represent varying conditions in the game world, such
79 __tablename__
= 'encounter_conditions'
80 id = Column(Integer
, primary_key
=True, nullable
=False)
81 name
= Column(Unicode(64), nullable
=False)
83 class EncounterConditionValue(TableBase
):
84 """Rows in this table represent possible states for a condition; for
85 example, the state of 'swarm' could be 'swarm' or 'no swarm'.
88 __tablename__
= 'encounter_condition_values'
89 id = Column(Integer
, primary_key
=True, nullable
=False)
90 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=False, nullable
=False, autoincrement
=False)
91 name
= Column(Unicode(64), nullable
=False)
92 is_default
= Column(Boolean
, nullable
=False)
94 class EncounterConditionValueMap(TableBase
):
95 """Maps encounters to the specific conditions under which they occur."""
97 __tablename__
= 'encounter_condition_value_map'
98 encounter_id
= Column(Integer
, ForeignKey('encounters.id'), primary_key
=True, nullable
=False, autoincrement
=False)
99 encounter_condition_value_id
= Column(Integer
, ForeignKey('encounter_condition_values.id'), primary_key
=True, nullable
=False, autoincrement
=False)
101 class EncounterTerrain(TableBase
):
102 """Rows in this table represent ways the player can enter a wild encounter,
103 e.g., surfing, fishing, or walking through tall grass.
106 __tablename__
= 'encounter_terrain'
107 id = Column(Integer
, primary_key
=True, nullable
=False)
108 name
= Column(Unicode(64), nullable
=False)
110 class EncounterSlot(TableBase
):
111 """Rows in this table represent an abstract "slot" within a terrain,
112 associated with both some set of conditions and a rarity.
114 Note that there are two encounters per slot, so the rarities will only add
118 __tablename__
= 'encounter_slots'
119 id = Column(Integer
, primary_key
=True, nullable
=False)
120 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False, autoincrement
=False)
121 encounter_terrain_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=False, nullable
=False, autoincrement
=False)
122 rarity
= Column(Integer
, nullable
=False, autoincrement
=False)
124 class EncounterSlotCondition(TableBase
):
125 """Lists all conditions that affect each slot."""
127 __tablename__
= 'encounter_slot_conditions'
128 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), primary_key
=True, nullable
=False, autoincrement
=False)
129 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
131 class EvolutionChain(TableBase
):
132 __tablename__
= 'evolution_chains'
133 id = Column(Integer
, primary_key
=True, nullable
=False)
134 growth_rate_id
= Column(Integer
, ForeignKey('growth_rates.id'), nullable
=False)
135 steps_to_hatch
= Column(Integer
, nullable
=False)
136 baby_trigger_item
= Column(Unicode(12))
138 class EvolutionMethod(TableBase
):
139 __tablename__
= 'evolution_methods'
140 id = Column(Integer
, primary_key
=True, nullable
=False)
141 name
= Column(Unicode(64), nullable
=False)
142 description
= Column(Unicode(255), nullable
=False)
144 class Generation(TableBase
):
145 __tablename__
= 'generations'
146 id = Column(Integer
, primary_key
=True, nullable
=False)
147 main_region_id
= Column(Integer
, ForeignKey('regions.id'))
148 name
= Column(Unicode(16), nullable
=False)
150 class GrowthRate(TableBase
):
151 """`formula` is written in LaTeX math notation."""
152 __tablename__
= 'growth_rates'
153 id = Column(Integer
, primary_key
=True, nullable
=False)
154 name
= Column(Unicode(20), nullable
=False)
155 formula
= Column(Unicode(500), nullable
=False)
157 class Item(TableBase
):
158 __tablename__
= 'items'
159 __singlename__
= 'item'
160 id = Column(Integer
, primary_key
=True, nullable
=False)
161 name
= Column(Unicode(16), nullable
=False)
163 class Language(TableBase
):
164 __tablename__
= 'languages'
165 id = Column(Integer
, primary_key
=True, nullable
=False)
166 iso3166
= Column(Unicode(2), nullable
=False)
167 name
= Column(Unicode(16), nullable
=False)
169 class Location(TableBase
):
170 __tablename__
= 'locations'
171 __singlename__
= 'location'
172 id = Column(Integer
, primary_key
=True, nullable
=False)
173 region_id
= Column(Integer
, ForeignKey('regions.id'))
174 name
= Column(Unicode(64), nullable
=False)
176 class LocationArea(TableBase
):
177 __tablename__
= 'location_areas'
178 id = Column(Integer
, primary_key
=True, nullable
=False)
179 location_id
= Column(Integer
, ForeignKey('locations.id'), nullable
=False)
180 internal_id
= Column(Integer
, nullable
=False)
181 name
= Column(Unicode(64), nullable
=True)
183 class LocationAreaEncounterRate(TableBase
):
184 __tablename__
= 'location_area_encounter_rates'
185 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), primary_key
=True, nullable
=False, autoincrement
=False)
186 encounter_type_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=True, nullable
=False, autoincrement
=False)
187 rate
= Column(Integer
, nullable
=True)
189 class Machine(TableBase
):
190 __tablename__
= 'machines'
191 machine_number
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
192 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
193 move_id
= Column(Integer
, ForeignKey('moves.id'), nullable
=False)
195 class MoveEffectCategory(TableBase
):
196 __tablename__
= 'move_effect_categories'
197 id = Column(Integer
, primary_key
=True, nullable
=False)
198 name
= Column(Unicode(64), nullable
=False)
199 can_affect_user
= Column(Boolean
, nullable
=False)
201 class MoveEffectCategoryMap(TableBase
):
202 __tablename__
= 'move_effect_category_map'
203 move_effect_id
= Column(Integer
, ForeignKey('move_effects.id'), primary_key
=True, nullable
=False)
204 move_effect_category_id
= Column(Integer
, ForeignKey('move_effect_categories.id'), primary_key
=True, nullable
=False)
205 affects_user
= Column(Boolean
, primary_key
=True, nullable
=False)
207 class MoveDamageClass(TableBase
):
208 __tablename__
= 'move_damage_classes'
209 id = Column(Integer
, primary_key
=True, nullable
=False)
210 name
= Column(Unicode(8), nullable
=False)
211 description
= Column(Unicode(64), nullable
=False)
213 class MoveEffect(TableBase
):
214 __tablename__
= 'move_effects'
215 id = Column(Integer
, primary_key
=True, nullable
=False)
216 priority
= Column(SmallInteger
, nullable
=False)
217 short_effect
= Column(Unicode(256), nullable
=False)
218 effect
= Column(Unicode(5120), nullable
=False)
220 class MoveFlag(TableBase
):
221 __tablename__
= 'move_flags'
222 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
223 move_flag_type_id
= Column(Integer
, ForeignKey('move_flag_types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
225 class MoveFlagType(TableBase
):
226 __tablename__
= 'move_flag_types'
227 id = Column(Integer
, primary_key
=True, nullable
=False)
228 name
= Column(Unicode(32), nullable
=False)
229 description
= Column(rst
.RstTextColumn(128), nullable
=False)
231 class MoveFlavorText(TableBase
):
232 __tablename__
= 'move_flavor_text'
233 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
234 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False, autoincrement
=False)
235 flavor_text
= Column(Unicode(255), nullable
=False)
237 class MoveName(TableBase
):
238 __tablename__
= 'move_names'
239 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
240 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
241 name
= Column(Unicode(16), nullable
=False)
243 class MoveTarget(TableBase
):
244 __tablename__
= 'move_targets'
245 id = Column(Integer
, primary_key
=True, nullable
=False)
246 name
= Column(Unicode(32), nullable
=False)
247 description
= Column(Unicode(128), nullable
=False)
249 class Move(TableBase
):
250 __tablename__
= 'moves'
251 __singlename__
= 'move'
252 id = Column(Integer
, primary_key
=True, nullable
=False)
253 name
= Column(Unicode(12), nullable
=False)
254 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
255 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
256 power
= Column(SmallInteger
)
257 pp
= Column(SmallInteger
, nullable
=False)
258 accuracy
= Column(SmallInteger
)
259 target_id
= Column(Integer
, ForeignKey('move_targets.id'), nullable
=False)
260 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False)
261 effect_id
= Column(Integer
, ForeignKey('move_effects.id'), nullable
=False)
262 effect_chance
= Column(Integer
)
263 contest_type
= Column(Unicode(8), nullable
=False)
264 contest_effect_id
= Column(Integer
, ForeignKey('contest_effects.id'), nullable
=True)
265 super_contest_effect_id
= Column(Integer
, ForeignKey('super_contest_effects.id'), nullable
=False)
267 class Pokedex(TableBase
):
268 __tablename__
= 'pokedexes'
269 id = Column(Integer
, primary_key
=True, nullable
=False)
270 name
= Column(Unicode(16), nullable
=False)
271 description
= Column(Unicode(512))
273 class PokedexVersionGroup(TableBase
):
274 __tablename__
= 'pokedex_version_groups'
275 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
276 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
278 class Pokemon(TableBase
):
279 """The core to this whole mess.
281 Note that I use both 'forme' and 'form' in both code and the database. I
282 only use 'forme' when specifically referring to Pokémon that have multiple
283 distinct species as forms—i.e., different stats or movesets. 'Form' is a
284 more general term referring to any variation within a species, including
285 purely cosmetic forms like Unown.
287 __tablename__
= 'pokemon'
288 __singlename__
= 'pokemon'
289 id = Column(Integer
, primary_key
=True, nullable
=False)
290 name
= Column(Unicode(20), nullable
=False)
291 forme_name
= Column(Unicode(16))
292 forme_base_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
293 generation_id
= Column(Integer
, ForeignKey('generations.id'))
294 evolution_chain_id
= Column(Integer
, ForeignKey('evolution_chains.id'))
295 evolution_parent_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
296 evolution_method_id
= Column(Integer
, ForeignKey('evolution_methods.id'))
297 evolution_parameter
= Column(Unicode(32))
298 height
= Column(Integer
, nullable
=False)
299 weight
= Column(Integer
, nullable
=False)
300 species
= Column(Unicode(16), nullable
=False)
301 color_id
= Column(Integer
, ForeignKey('pokemon_colors.id'), nullable
=False)
302 pokemon_shape_id
= Column(Integer
, ForeignKey('pokemon_shapes.id'), nullable
=False)
303 habitat_id
= Column(Integer
, ForeignKey('pokemon_habitats.id'), nullable
=True)
304 gender_rate
= Column(Integer
, nullable
=False)
305 capture_rate
= Column(Integer
, nullable
=False)
306 base_experience
= Column(Integer
, nullable
=False)
307 base_happiness
= Column(Integer
, nullable
=False)
308 is_baby
= Column(Boolean
, nullable
=False)
309 has_gen4_fem_sprite
= Column(Boolean
, nullable
=False)
310 has_gen4_fem_back_sprite
= Column(Boolean
, nullable
=False)
312 ### Stuff to handle alternate Pokémon forms
315 def national_id(self
):
316 """Returns the National Pokédex number for this Pokémon. Use this
317 instead of the id directly; alternate formes may make the id incorrect.
320 if self
.forme_base_pokemon_id
:
321 return self
.forme_base_pokemon_id
326 """Returns the name of this Pokémon, including its Forme, if any."""
329 return "%s %s" %
(self
.forme_name
.capitalize(), self
.name
)
333 def normal_form(self
):
334 """Returns the normal form for this Pokémon; i.e., this will return
335 regular Deoxys when called on any Deoxys form.
338 if self
.forme_base_pokemon
:
339 return self
.forme_base_pokemon
343 class PokemonAbility(TableBase
):
344 __tablename__
= 'pokemon_abilities'
345 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
346 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
347 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
349 class PokemonColor(TableBase
):
350 __tablename__
= 'pokemon_colors'
351 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
352 name
= Column(Unicode(6), nullable
=False)
354 class PokemonDexNumber(TableBase
):
355 __tablename__
= 'pokemon_dex_numbers'
356 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
357 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
358 pokedex_number
= Column(Integer
, nullable
=False)
360 class PokemonEggGroup(TableBase
):
361 __tablename__
= 'pokemon_egg_groups'
362 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
363 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
365 class PokemonFlavorText(TableBase
):
366 __tablename__
= 'pokemon_flavor_text'
367 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
368 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
369 flavor_text
= Column(Unicode(255), nullable
=False)
371 class PokemonFormGroup(TableBase
):
372 __tablename__
= 'pokemon_form_groups'
373 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
374 description
= Column(Unicode(512), nullable
=False)
376 class PokemonFormSprite(TableBase
):
377 __tablename__
= 'pokemon_form_sprites'
378 id = Column(Integer
, primary_key
=True, nullable
=False)
379 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
380 introduced_in_version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
381 name
= Column(Unicode(16), nullable
=True)
383 class PokemonHabitat(TableBase
):
384 __tablename__
= 'pokemon_habitats'
385 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
386 name
= Column(Unicode(16), nullable
=False)
388 class PokemonItem(TableBase
):
389 __tablename__
= 'pokemon_items'
390 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
391 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
392 item_id
= Column(Integer
, ForeignKey('items.id'), primary_key
=True, nullable
=False, autoincrement
=False)
393 rarity
= Column(Integer
, nullable
=False)
395 class PokemonMove(TableBase
):
396 __tablename__
= 'pokemon_moves'
397 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
398 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
399 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False, index
=True)
400 pokemon_move_method_id
= Column(Integer
, ForeignKey('pokemon_move_methods.id'), primary_key
=True, nullable
=False, autoincrement
=False)
401 level
= Column(Integer
, primary_key
=True, nullable
=True, autoincrement
=False)
402 order
= Column(Integer
, nullable
=True)
404 class PokemonMoveMethod(TableBase
):
405 __tablename__
= 'pokemon_move_methods'
406 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
407 name
= Column(Unicode(64), nullable
=False)
408 description
= Column(Unicode(255), nullable
=False)
410 class PokemonName(TableBase
):
411 __tablename__
= 'pokemon_names'
412 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
413 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
414 name
= Column(Unicode(16), nullable
=False)
416 class PokemonShape(TableBase
):
417 __tablename__
= 'pokemon_shapes'
418 id = Column(Integer
, primary_key
=True, nullable
=False)
419 name
= Column(Unicode(24), nullable
=False)
420 awesome_name
= Column(Unicode(16), nullable
=False)
422 class PokemonStat(TableBase
):
423 __tablename__
= 'pokemon_stats'
424 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
425 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False, autoincrement
=False)
426 base_stat
= Column(Integer
, nullable
=False)
427 effort
= Column(Integer
, nullable
=False)
429 class PokemonType(TableBase
):
430 __tablename__
= 'pokemon_types'
431 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
432 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
433 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
435 class Region(TableBase
):
436 """Major areas of the world: Kanto, Johto, etc."""
437 __tablename__
= 'regions'
438 id = Column(Integer
, primary_key
=True, nullable
=False)
439 name
= Column(Unicode(16), nullable
=False)
441 class Stat(TableBase
):
442 __tablename__
= 'stats'
443 id = Column(Integer
, primary_key
=True, nullable
=False)
444 name
= Column(Unicode(16), nullable
=False)
446 class SuperContestCombo(TableBase
):
447 __tablename__
= 'super_contest_combos'
448 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
449 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
451 class SuperContestEffect(TableBase
):
452 __tablename__
= 'super_contest_effects'
453 id = Column(Integer
, primary_key
=True, nullable
=False)
454 appeal
= Column(SmallInteger
, nullable
=False)
455 flavor_text
= Column(Unicode(64), nullable
=False)
457 class TypeEfficacy(TableBase
):
458 __tablename__
= 'type_efficacy'
459 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
460 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
461 damage_factor
= Column(Integer
, nullable
=False)
463 class Type(TableBase
):
464 __tablename__
= 'types'
465 __singlename__
= 'type'
466 id = Column(Integer
, primary_key
=True, nullable
=False)
467 name
= Column(Unicode(8), nullable
=False)
468 abbreviation
= Column(Unicode(3), nullable
=False)
469 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
470 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False) ## ??? is none; everything else is physical or special
472 class VersionGroup(TableBase
):
473 __tablename__
= 'version_groups'
474 id = Column(Integer
, primary_key
=True, nullable
=False)
475 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
477 class VersionGroupRegion(TableBase
):
478 __tablename__
= 'version_group_regions'
479 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False)
480 region_id
= Column(Integer
, ForeignKey('regions.id'), primary_key
=True, nullable
=False)
482 class Version(TableBase
):
483 __tablename__
= 'versions'
484 id = Column(Integer
, primary_key
=True, nullable
=False)
485 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
486 name
= Column(Unicode(32), nullable
=False)
489 ### Relations down here, to avoid ordering problems
490 ContestCombo
.first
= relation(Move
, primaryjoin
=ContestCombo
.first_move_id
==Move
.id,
491 backref
='contest_combo_first')
492 ContestCombo
.second
= relation(Move
, primaryjoin
=ContestCombo
.second_move_id
==Move
.id,
493 backref
='contest_combo_second')
495 Encounter
.location_area
= relation(LocationArea
, backref
='encounters')
496 Encounter
.pokemon
= relation(Pokemon
, backref
='encounters')
497 Encounter
.version
= relation(Version
, backref
='encounters')
498 Encounter
.slot
= relation(EncounterSlot
, backref
='encounters')
500 EncounterConditionValue
.condition
= relation(EncounterCondition
, backref
='values')
502 Encounter
.condition_value_map
= relation(EncounterConditionValueMap
, backref
='encounter')
503 Encounter
.condition_values
= association_proxy('condition_value_map', 'condition_value')
504 EncounterConditionValueMap
.condition_value
= relation(EncounterConditionValue
,
505 backref
='encounter_map')
507 EncounterSlot
.terrain
= relation(EncounterTerrain
, backref
='slots')
509 EncounterSlot
.condition_map
= relation(EncounterSlotCondition
, backref
='slot')
510 EncounterSlot
.conditions
= association_proxy('condition_map', 'condition')
511 EncounterSlotCondition
.condition
= relation(EncounterCondition
,
514 EvolutionChain
.growth_rate
= relation(GrowthRate
, backref
='evolution_chains')
516 Generation
.versions
= relation(Version
, secondary
=VersionGroup
.__table__
)
517 Generation
.main_region
= relation(Region
)
519 Location
.region
= relation(Region
, backref
='locations')
521 LocationArea
.location
= relation(Location
, backref
='areas')
523 Machine
.version_group
= relation(VersionGroup
)
525 Move
.contest_effect
= relation(ContestEffect
, backref
='moves')
526 Move
.contest_combo_next
= association_proxy('contest_combo_first', 'second')
527 Move
.contest_combo_prev
= association_proxy('contest_combo_second', 'first')
528 Move
.damage_class
= relation(MoveDamageClass
, backref
='moves')
529 Move
.flags
= association_proxy('move_flags', 'flag')
530 Move
.flavor_text
= relation(MoveFlavorText
, order_by
=MoveFlavorText
.generation_id
, backref
='move')
531 Move
.foreign_names
= relation(MoveName
, backref
='pokemon')
532 Move
.generation
= relation(Generation
, backref
='moves')
533 Move
.machines
= relation(Machine
, backref
='move')
534 Move
.move_effect
= relation(MoveEffect
, backref
='moves')
535 Move
.move_flags
= relation(MoveFlag
, backref
='move')
536 Move
.super_contest_effect
= relation(SuperContestEffect
, backref
='moves')
537 Move
.super_contest_combo_next
= association_proxy('super_contest_combo_first', 'second')
538 Move
.super_contest_combo_prev
= association_proxy('super_contest_combo_second', 'first')
539 Move
.target
= relation(MoveTarget
, backref
='moves')
540 Move
.type = relation(Type
, backref
='moves')
542 Move
.effect
= rst
.MoveEffectProperty('effect')
543 Move
.priority
= association_proxy('move_effect', 'priority')
544 Move
.short_effect
= rst
.MoveEffectProperty('short_effect')
546 MoveEffect
.category_map
= relation(MoveEffectCategoryMap
)
547 MoveEffect
.categories
= association_proxy('category_map', 'category')
548 MoveEffectCategoryMap
.category
= relation(MoveEffectCategory
)
550 MoveFlag
.flag
= relation(MoveFlagType
)
552 MoveFlavorText
.generation
= relation(Generation
)
554 MoveName
.language
= relation(Language
)
556 Pokedex
.version_groups
= relation(VersionGroup
, secondary
=PokedexVersionGroup
.__table__
)
558 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
559 order_by
=PokemonAbility
.slot
,
561 Pokemon
.formes
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.forme_base_pokemon_id
,
562 backref
=backref('forme_base_pokemon',
563 remote_side
=[Pokemon
.id]))
564 Pokemon
.pokemon_color
= relation(PokemonColor
, backref
='pokemon')
565 Pokemon
.color
= association_proxy('pokemon_color', 'name')
566 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
567 Pokemon
.egg_groups
= relation(EggGroup
, secondary
=PokemonEggGroup
.__table__
,
568 order_by
=PokemonEggGroup
.egg_group_id
,
570 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
571 Pokemon
.evolution_method
= relation(EvolutionMethod
)
572 Pokemon
.evolution_children
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.evolution_parent_pokemon_id
,
573 backref
=backref('evolution_parent',
574 remote_side
=[Pokemon
.id]))
575 Pokemon
.flavor_text
= relation(PokemonFlavorText
, order_by
=PokemonFlavorText
.pokemon_id
, backref
='pokemon')
576 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
577 Pokemon
.pokemon_habitat
= relation(PokemonHabitat
, backref
='pokemon')
578 Pokemon
.habitat
= association_proxy('pokemon_habitat', 'name')
579 Pokemon
.items
= relation(PokemonItem
)
580 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
581 Pokemon
.shape
= relation(PokemonShape
, backref
='pokemon')
582 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
583 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
585 PokemonDexNumber
.pokedex
= relation(Pokedex
)
587 PokemonFlavorText
.version
= relation(Version
)
589 PokemonItem
.item
= relation(Item
, backref
='pokemon')
590 PokemonItem
.version
= relation(Version
)
592 PokemonFormGroup
.pokemon
= relation(Pokemon
, backref
=backref('form_group',
594 PokemonFormSprite
.pokemon
= relation(Pokemon
, backref
='form_sprites')
595 PokemonFormSprite
.introduced_in
= relation(VersionGroup
)
597 PokemonMove
.pokemon
= relation(Pokemon
, backref
='pokemon_moves')
598 PokemonMove
.version_group
= relation(VersionGroup
)
599 PokemonMove
.machine
= relation(Machine
, backref
='pokemon_moves',
600 primaryjoin
=and_(Machine
.version_group_id
==PokemonMove
.version_group_id
,
601 Machine
.move_id
==PokemonMove
.move_id
),
602 foreign_keys
=[Machine
.version_group_id
, Machine
.move_id
],
604 PokemonMove
.move
= relation(Move
, backref
='pokemon_moves')
605 PokemonMove
.method
= relation(PokemonMoveMethod
)
607 PokemonName
.language
= relation(Language
)
609 PokemonStat
.stat
= relation(Stat
)
611 # This is technically a has-many; Generation.main_region_id -> Region.id
612 Region
.generation
= relation(Generation
, uselist
=False)
613 Region
.version_group_regions
= relation(VersionGroupRegion
, backref
='region',
614 order_by
='VersionGroupRegion.version_group_id')
615 Region
.version_groups
= association_proxy('version_group_regions', 'version_group')
617 SuperContestCombo
.first
= relation(Move
, primaryjoin
=SuperContestCombo
.first_move_id
==Move
.id,
618 backref
='super_contest_combo_first')
619 SuperContestCombo
.second
= relation(Move
, primaryjoin
=SuperContestCombo
.second_move_id
==Move
.id,
620 backref
='super_contest_combo_second')
622 Type
.damage_efficacies
= relation(TypeEfficacy
,
624 ==TypeEfficacy
.damage_type_id
,
625 backref
='damage_type')
626 Type
.target_efficacies
= relation(TypeEfficacy
,
628 ==TypeEfficacy
.target_type_id
,
629 backref
='target_type')
631 Type
.generation
= relation(Generation
, backref
='types')
632 Type
.damage_class
= relation(MoveDamageClass
, backref
='types')
634 Version
.version_group
= relation(VersionGroup
, backref
='versions')
635 Version
.generation
= association_proxy('version_group', 'generation')
637 VersionGroup
.generation
= relation(Generation
, backref
='version_groups')
638 VersionGroup
.version_group_regions
= relation(VersionGroupRegion
, backref
='version_group')
639 VersionGroup
.regions
= association_proxy('version_group_regions', 'region')