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 EvolutionChain(TableBase
):
31 __tablename__
= 'evolution_chains'
32 id = Column(Integer
, primary_key
=True, nullable
=False)
33 growth_rate_id
= Column(Integer
, ForeignKey('growth_rates.id'), nullable
=False)
34 steps_to_hatch
= Column(Integer
, nullable
=False)
35 baby_trigger_item
= Column(Unicode(12))
37 class EvolutionMethod(TableBase
):
38 __tablename__
= 'evolution_methods'
39 id = Column(Integer
, primary_key
=True, nullable
=False)
40 name
= Column(Unicode(64), nullable
=False)
41 description
= Column(Unicode(255), nullable
=False)
43 class Generation(TableBase
):
44 __tablename__
= 'generations'
45 id = Column(Integer
, primary_key
=True, nullable
=False)
46 name
= Column(Unicode(16), nullable
=False)
47 main_region
= Column(Unicode(16), nullable
=False)
49 class GrowthRate(TableBase
):
50 __tablename__
= 'growth_rates'
51 id = Column(Integer
, primary_key
=True, nullable
=False)
52 name
= Column(Unicode(16), nullable
=False)
53 formula
= Column(Unicode(255), nullable
=False)
55 class Language(TableBase
):
56 __tablename__
= 'languages'
57 id = Column(Integer
, primary_key
=True, nullable
=False)
58 name
= Column(Unicode(16), nullable
=False)
60 class MoveEffect(TableBase
):
61 __tablename__
= 'move_effects'
62 id = Column(Integer
, primary_key
=True, nullable
=False)
63 priority
= Column(SmallInteger
, nullable
=False)
64 short_effect
= Column(Unicode(128), nullable
=False)
65 effect
= Column(Unicode(255), nullable
=False)
67 class MoveTarget(TableBase
):
68 __tablename__
= 'move_targets'
69 id = Column(Integer
, primary_key
=True, nullable
=False)
70 name
= Column(Unicode(32), nullable
=False)
71 description
= Column(Unicode(128), nullable
=False)
73 class Move(TableBase
):
74 __tablename__
= 'moves'
75 id = Column(Integer
, primary_key
=True, nullable
=False)
76 name
= Column(Unicode(12), nullable
=False)
77 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
78 power
= Column(SmallInteger
)
79 pp
= Column(SmallInteger
, nullable
=False)
80 accuracy
= Column(SmallInteger
)
81 target_id
= Column(Integer
, ForeignKey('move_targets.id'), nullable
=False)
82 category
= Column(Unicode(8), nullable
=False)
83 effect_id
= Column(Integer
, ForeignKey('move_effects.id'), nullable
=False)
84 effect_chance
= Column(Integer
)
85 contest_type
= Column(Unicode(8), nullable
=False)
86 contest_effect_id
= Column(Integer
, ForeignKey('contest_effects.id'), nullable
=False)
87 super_contest_effect_id
= Column(Integer
, nullable
=False)
89 class Pokemon(TableBase
):
90 __tablename__
= 'pokemon'
91 id = Column(Integer
, primary_key
=True, nullable
=False)
92 name
= Column(Unicode(20), nullable
=False)
93 forme_name
= Column(Unicode(16))
94 forme_base_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
95 generation_id
= Column(Integer
, ForeignKey('generations.id'))
96 evolution_chain_id
= Column(Integer
, ForeignKey('evolution_chains.id'))
97 evolution_parent_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
98 evolution_method_id
= Column(Integer
, ForeignKey('evolution_methods.id'))
99 evolution_parameter
= Column(Unicode(32))
100 height
= Column(Integer
, nullable
=False)
101 weight
= Column(Integer
, nullable
=False)
102 species
= Column(Unicode(16), nullable
=False)
103 color
= Column(Unicode(6), nullable
=False)
104 pokemon_shape_id
= Column(Integer
, ForeignKey('pokemon_shapes.id'), nullable
=False)
105 habitat
= Column(Unicode(16), nullable
=False)
106 gender_rate
= Column(Integer
, nullable
=False)
107 capture_rate
= Column(Integer
, nullable
=False)
108 base_experience
= Column(Integer
, nullable
=False)
109 base_happiness
= Column(Integer
, nullable
=False)
110 gen1_internal_id
= Column(Integer
)
111 is_baby
= Column(Boolean
, nullable
=False)
112 has_dp_fem_sprite
= Column(Boolean
, nullable
=False)
113 has_dp_fem_back_sprite
= Column(Boolean
, nullable
=False)
115 class PokemonAbility(TableBase
):
116 __tablename__
= 'pokemon_abilities'
117 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
118 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
119 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
121 class PokemonDexNumber(TableBase
):
122 __tablename__
= 'pokemon_dex_numbers'
123 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
124 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False, autoincrement
=False)
125 pokedex_number
= Column(Integer
, nullable
=False)
127 class PokemonEggGroup(TableBase
):
128 __tablename__
= 'pokemon_egg_groups'
129 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
130 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
132 class PokemonFlavorText(TableBase
):
133 __tablename__
= 'pokemon_flavor_text'
134 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
135 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
136 flavor_text
= Column(Unicode(255), nullable
=False)
138 class PokemonName(TableBase
):
139 __tablename__
= 'pokemon_names'
140 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
141 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
142 name
= Column(Unicode(16), nullable
=False)
144 class PokemonShape(TableBase
):
145 __tablename__
= 'pokemon_shapes'
146 id = Column(Integer
, primary_key
=True, nullable
=False)
147 name
= Column(Unicode(24), nullable
=False)
148 awesome_name
= Column(Unicode(16), nullable
=False)
150 class PokemonStat(TableBase
):
151 __tablename__
= 'pokemon_stats'
152 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
153 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False, autoincrement
=False)
154 base_stat
= Column(Integer
, nullable
=False)
155 effort
= Column(Integer
, nullable
=False)
157 class PokemonType(TableBase
):
158 __tablename__
= 'pokemon_types'
159 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
160 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
161 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
163 class Stat(TableBase
):
164 __tablename__
= 'stats'
165 id = Column(Integer
, primary_key
=True, nullable
=False)
166 name
= Column(Unicode(16), nullable
=False)
168 class TypeEfficacy(TableBase
):
169 __tablename__
= 'type_efficacy'
170 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
171 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
172 damage_factor
= Column(Integer
, nullable
=False)
174 class Type(TableBase
):
175 __tablename__
= 'types'
176 id = Column(Integer
, primary_key
=True, nullable
=False)
177 name
= Column(Unicode(8), nullable
=False)
178 abbreviation
= Column(Unicode(3), nullable
=False)
180 class VersionGroup(TableBase
):
181 __tablename__
= 'version_groups'
182 id = Column(Integer
, primary_key
=True, nullable
=False)
183 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
185 class Version(TableBase
):
186 __tablename__
= 'versions'
187 id = Column(Integer
, primary_key
=True, nullable
=False)
188 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
189 name
= Column(Unicode(32), nullable
=False)
192 ### Relations down here, to avoid ordering problems
193 EvolutionChain
.growth_rate
= relation(GrowthRate
, backref
='evolution_chains')
194 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
195 order_by
=PokemonAbility
.slot
,
197 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
198 Pokemon
.egg_groups
= relation(EggGroup
, secondary
=PokemonEggGroup
.__table__
,
199 order_by
=PokemonEggGroup
.egg_group_id
,
201 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
202 Pokemon
.evolution_method
= relation(EvolutionMethod
)
203 Pokemon
.evolution_children
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.evolution_parent_pokemon_id
,
204 backref
=backref('evolution_parent',
205 remote_side
=[Pokemon
.id]))
206 Pokemon
.flavor_text
= relation(PokemonFlavorText
, backref
='pokemon')
207 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
208 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
209 Pokemon
.shape
= relation(PokemonShape
, backref
='pokemon')
210 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
211 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
213 PokemonDexNumber
.generation
= relation(Generation
)
215 PokemonFlavorText
.version
= relation(Version
)
217 PokemonName
.language
= relation(Language
)
219 PokemonStat
.stat
= relation(Stat
)
221 Type
.damage_efficacies
= relation(TypeEfficacy
,
223 ==TypeEfficacy
.damage_type_id
,
224 backref
='damage_type')
225 Type
.target_efficacies
= relation(TypeEfficacy
,
227 ==TypeEfficacy
.target_type_id
,
228 backref
='target_type')