1 from sqlalchemy
import Column
, ForeignKey
, MetaData
, Table
2 from sqlalchemy
.ext
.declarative
import declarative_base
3 from sqlalchemy
.orm
import backref
, relation
4 from sqlalchemy
.types
import *
5 from sqlalchemy
.databases
.mysql
import *
8 TableBase
= declarative_base(metadata
=metadata
)
10 class Ability(TableBase
):
11 __tablename__
= 'abilities'
12 id = Column(Integer
, primary_key
=True, nullable
=False)
13 name
= Column(Unicode(24), nullable
=False)
14 flavor_text
= Column(Unicode(64), nullable
=False)
15 effect
= Column(Unicode(255), nullable
=False)
17 class ContestEffect(TableBase
):
18 __tablename__
= 'contest_effects'
19 id = Column(Integer
, primary_key
=True, nullable
=False)
20 appeal
= Column(SmallInteger
, nullable
=False)
21 jam
= Column(SmallInteger
, nullable
=False)
22 flavor
= Column(Unicode(255), nullable
=False)
23 effect
= Column(Unicode(255), nullable
=False)
25 class EggGroup(TableBase
):
26 __tablename__
= 'egg_groups'
27 id = Column(Integer
, primary_key
=True, nullable
=False)
28 name
= Column(Unicode(16), nullable
=False)
30 class Encounter(TableBase
):
31 __tablename__
= 'encounters'
32 id = Column(Integer
, primary_key
=True, nullable
=False)
33 version_id
= Column(Integer
, ForeignKey('versions.id'), nullable
=False, autoincrement
=False)
34 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), nullable
=False, autoincrement
=False)
35 encounter_type_slot_id
= Column(Integer
, ForeignKey('encounter_type_slots.id'), nullable
=False, autoincrement
=False)
36 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), nullable
=True, autoincrement
=False)
37 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), nullable
=False, autoincrement
=False)
38 min_level
= Column(Integer
, nullable
=False, autoincrement
=False)
39 max_level
= Column(Integer
, nullable
=False, autoincrement
=False)
41 class EncounterCondition(TableBase
):
42 __tablename__
= 'encounter_conditions'
43 id = Column(Integer
, primary_key
=True, nullable
=False)
44 encounter_condition_group_id
= Column(Integer
, ForeignKey('encounter_condition_groups.id'), primary_key
=False, nullable
=False, autoincrement
=False)
45 name
= Column(Unicode(64), nullable
=False)
47 class EncounterConditionGroup(TableBase
):
48 __tablename__
= 'encounter_condition_groups'
49 id = Column(Integer
, primary_key
=True, nullable
=False)
50 name
= Column(Unicode(64), nullable
=False)
52 class EncounterType(TableBase
):
53 __tablename__
= 'encounter_types'
54 id = Column(Integer
, primary_key
=True, nullable
=False)
55 name
= Column(Unicode(64), nullable
=False)
57 class EncounterTypeSlot(TableBase
):
58 __tablename__
= 'encounter_type_slots'
59 id = Column(Integer
, primary_key
=True, nullable
=False)
60 encounter_type_id
= Column(Integer
, ForeignKey('encounter_types.id'), primary_key
=False, nullable
=False, autoincrement
=False)
61 encounter_condition_group_id
= Column(Integer
, ForeignKey('encounter_condition_groups.id'), primary_key
=False, nullable
=True, autoincrement
=False)
62 rarity
= Column(Integer
, nullable
=False, autoincrement
=False)
64 class EvolutionChain(TableBase
):
65 __tablename__
= 'evolution_chains'
66 id = Column(Integer
, primary_key
=True, nullable
=False)
67 growth_rate_id
= Column(Integer
, ForeignKey('growth_rates.id'), nullable
=False)
68 steps_to_hatch
= Column(Integer
, nullable
=False)
69 baby_trigger_item
= Column(Unicode(12))
71 class EvolutionMethod(TableBase
):
72 __tablename__
= 'evolution_methods'
73 id = Column(Integer
, primary_key
=True, nullable
=False)
74 name
= Column(Unicode(64), nullable
=False)
75 description
= Column(Unicode(255), nullable
=False)
77 class Generation(TableBase
):
78 __tablename__
= 'generations'
79 id = Column(Integer
, primary_key
=True, nullable
=False)
80 name
= Column(Unicode(16), nullable
=False)
81 main_region
= Column(Unicode(16), nullable
=False)
83 class GrowthRate(TableBase
):
84 __tablename__
= 'growth_rates'
85 id = Column(Integer
, primary_key
=True, nullable
=False)
86 name
= Column(Unicode(16), nullable
=False)
87 formula
= Column(Unicode(255), nullable
=False)
89 class Language(TableBase
):
90 __tablename__
= 'languages'
91 id = Column(Integer
, primary_key
=True, nullable
=False)
92 name
= Column(Unicode(16), nullable
=False)
94 class Location(TableBase
):
95 __tablename__
= 'locations'
96 id = Column(Integer
, primary_key
=True, nullable
=False)
97 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
98 name
= Column(Unicode(64), nullable
=False)
100 class LocationArea(TableBase
):
101 __tablename__
= 'location_areas'
102 id = Column(Integer
, primary_key
=True, nullable
=False)
103 location_id
= Column(Integer
, ForeignKey('locations.id'), nullable
=False)
104 internal_id
= Column(Integer
, nullable
=False)
105 name
= Column(Unicode(64), nullable
=True)
107 class MoveEffect(TableBase
):
108 __tablename__
= 'move_effects'
109 id = Column(Integer
, primary_key
=True, nullable
=False)
110 priority
= Column(SmallInteger
, nullable
=False)
111 short_effect
= Column(Unicode(128), nullable
=False)
112 effect
= Column(Unicode(255), nullable
=False)
114 class MoveTarget(TableBase
):
115 __tablename__
= 'move_targets'
116 id = Column(Integer
, primary_key
=True, nullable
=False)
117 name
= Column(Unicode(32), nullable
=False)
118 description
= Column(Unicode(128), nullable
=False)
120 class Move(TableBase
):
121 __tablename__
= 'moves'
122 id = Column(Integer
, primary_key
=True, nullable
=False)
123 name
= Column(Unicode(12), nullable
=False)
124 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
125 power
= Column(SmallInteger
)
126 pp
= Column(SmallInteger
, nullable
=False)
127 accuracy
= Column(SmallInteger
)
128 target_id
= Column(Integer
, ForeignKey('move_targets.id'), nullable
=False)
129 category
= Column(Unicode(8), nullable
=False)
130 effect_id
= Column(Integer
, ForeignKey('move_effects.id'), nullable
=False)
131 effect_chance
= Column(Integer
)
132 contest_type
= Column(Unicode(8), nullable
=False)
133 contest_effect_id
= Column(Integer
, ForeignKey('contest_effects.id'), nullable
=False)
134 super_contest_effect_id
= Column(Integer
, nullable
=False)
136 class Pokemon(TableBase
):
137 __tablename__
= 'pokemon'
138 id = Column(Integer
, primary_key
=True, nullable
=False)
139 name
= Column(Unicode(20), nullable
=False)
140 forme_name
= Column(Unicode(16))
141 forme_base_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
142 generation_id
= Column(Integer
, ForeignKey('generations.id'))
143 evolution_chain_id
= Column(Integer
, ForeignKey('evolution_chains.id'))
144 evolution_parent_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
145 evolution_method_id
= Column(Integer
, ForeignKey('evolution_methods.id'))
146 evolution_parameter
= Column(Unicode(32))
147 height
= Column(Integer
, nullable
=False)
148 weight
= Column(Integer
, nullable
=False)
149 species
= Column(Unicode(16), nullable
=False)
150 color
= Column(Unicode(6), nullable
=False)
151 pokemon_shape_id
= Column(Integer
, ForeignKey('pokemon_shapes.id'), nullable
=False)
152 habitat
= Column(Unicode(16), nullable
=False)
153 gender_rate
= Column(Integer
, nullable
=False)
154 capture_rate
= Column(Integer
, nullable
=False)
155 base_experience
= Column(Integer
, nullable
=False)
156 base_happiness
= Column(Integer
, nullable
=False)
157 gen1_internal_id
= Column(Integer
)
158 is_baby
= Column(Boolean
, nullable
=False)
159 has_gen4_fem_sprite
= Column(Boolean
, nullable
=False)
160 has_gen4_fem_back_sprite
= Column(Boolean
, nullable
=False)
162 class PokemonAbility(TableBase
):
163 __tablename__
= 'pokemon_abilities'
164 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
165 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
166 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
168 class PokemonDexNumber(TableBase
):
169 __tablename__
= 'pokemon_dex_numbers'
170 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
171 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False, autoincrement
=False)
172 pokedex_number
= Column(Integer
, nullable
=False)
174 class PokemonEggGroup(TableBase
):
175 __tablename__
= 'pokemon_egg_groups'
176 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
177 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
179 class PokemonFlavorText(TableBase
):
180 __tablename__
= 'pokemon_flavor_text'
181 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
182 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
183 flavor_text
= Column(Unicode(255), nullable
=False)
185 class PokemonName(TableBase
):
186 __tablename__
= 'pokemon_names'
187 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
188 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
189 name
= Column(Unicode(16), nullable
=False)
191 class PokemonShape(TableBase
):
192 __tablename__
= 'pokemon_shapes'
193 id = Column(Integer
, primary_key
=True, nullable
=False)
194 name
= Column(Unicode(24), nullable
=False)
195 awesome_name
= Column(Unicode(16), nullable
=False)
197 class PokemonStat(TableBase
):
198 __tablename__
= 'pokemon_stats'
199 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
200 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False, autoincrement
=False)
201 base_stat
= Column(Integer
, nullable
=False)
202 effort
= Column(Integer
, nullable
=False)
204 class PokemonType(TableBase
):
205 __tablename__
= 'pokemon_types'
206 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
207 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
208 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
210 class Stat(TableBase
):
211 __tablename__
= 'stats'
212 id = Column(Integer
, primary_key
=True, nullable
=False)
213 name
= Column(Unicode(16), nullable
=False)
215 class TypeEfficacy(TableBase
):
216 __tablename__
= 'type_efficacy'
217 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
218 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
219 damage_factor
= Column(Integer
, nullable
=False)
221 class Type(TableBase
):
222 __tablename__
= 'types'
223 id = Column(Integer
, primary_key
=True, nullable
=False)
224 name
= Column(Unicode(8), nullable
=False)
225 abbreviation
= Column(Unicode(3), nullable
=False)
227 class VersionGroup(TableBase
):
228 __tablename__
= 'version_groups'
229 id = Column(Integer
, primary_key
=True, nullable
=False)
230 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
232 class Version(TableBase
):
233 __tablename__
= 'versions'
234 id = Column(Integer
, primary_key
=True, nullable
=False)
235 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
236 name
= Column(Unicode(32), nullable
=False)
239 ### Relations down here, to avoid ordering problems
240 Encounter
.pokemon
= relation(Pokemon
, backref
='encounters')
241 Encounter
.version
= relation(Version
, backref
='encounters')
242 Encounter
.location_area
= relation(LocationArea
, backref
='encounters')
243 Encounter
.slot
= relation(EncounterTypeSlot
, backref
='encounters')
244 Encounter
.condition
= relation(EncounterCondition
, backref
='encounters')
246 EncounterCondition
.group
= relation(EncounterConditionGroup
,
247 backref
='conditions')
249 EncounterTypeSlot
.type = relation(EncounterType
, backref
='slots')
251 EvolutionChain
.growth_rate
= relation(GrowthRate
, backref
='evolution_chains')
253 LocationArea
.location
= relation(Location
, backref
='areas')
255 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
256 order_by
=PokemonAbility
.slot
,
258 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
259 Pokemon
.egg_groups
= relation(EggGroup
, secondary
=PokemonEggGroup
.__table__
,
260 order_by
=PokemonEggGroup
.egg_group_id
,
262 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
263 Pokemon
.evolution_method
= relation(EvolutionMethod
)
264 Pokemon
.evolution_children
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.evolution_parent_pokemon_id
,
265 backref
=backref('evolution_parent',
266 remote_side
=[Pokemon
.id]))
267 Pokemon
.flavor_text
= relation(PokemonFlavorText
, backref
='pokemon')
268 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
269 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
270 Pokemon
.shape
= relation(PokemonShape
, backref
='pokemon')
271 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
272 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
274 PokemonDexNumber
.generation
= relation(Generation
)
276 PokemonFlavorText
.version
= relation(Version
)
278 PokemonName
.language
= relation(Language
)
280 PokemonStat
.stat
= relation(Stat
)
282 Type
.damage_efficacies
= relation(TypeEfficacy
,
284 ==TypeEfficacy
.damage_type_id
,
285 backref
='damage_type')
286 Type
.target_efficacies
= relation(TypeEfficacy
,
288 ==TypeEfficacy
.target_type_id
,
289 backref
='target_type')
291 Version
.generation
= relation(Generation
, secondary
=VersionGroup
.__table__
,