1 from sqlalchemy
import Column
, ForeignKey
, MetaData
, Table
2 from sqlalchemy
.ext
.declarative
import declarative_base
3 from sqlalchemy
.orm
import 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'), nullable
=False)
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 habitat
= Column(Unicode(16), nullable
=False)
105 gender_rate
= Column(Integer
, nullable
=False)
106 capture_rate
= Column(Integer
, nullable
=False)
107 base_experience
= Column(Integer
, nullable
=False)
108 base_happiness
= Column(Integer
, nullable
=False)
109 gen1_internal_id
= Column(Integer
)
110 is_baby
= Column(Boolean
, nullable
=False)
111 has_dp_fem_sprite
= Column(Boolean
, nullable
=False)
112 has_dp_fem_back_sprite
= Column(Boolean
, nullable
=False)
114 class PokemonAbility(TableBase
):
115 __tablename__
= 'pokemon_abilities'
116 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
117 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
118 slot
= Column(Integer
, primary_key
=True, nullable
=False)
120 class PokemonDexNumber(TableBase
):
121 __tablename__
= 'pokemon_dex_numbers'
122 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
123 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False)
124 pokedex_number
= Column(Integer
, nullable
=False)
126 class PokemonEggGroup(TableBase
):
127 __tablename__
= 'pokemon_egg_groups'
128 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
129 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False)
131 class PokemonFlavorText(TableBase
):
132 __tablename__
= 'pokemon_flavor_text'
133 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
134 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False)
135 flavor
= Column(Unicode(255), nullable
=False)
137 class PokemonName(TableBase
):
138 __tablename__
= 'pokemon_names'
139 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
140 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False)
141 name
= Column(Unicode(16), nullable
=False)
143 class PokemonStat(TableBase
):
144 __tablename__
= 'pokemon_stats'
145 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
146 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False)
147 base_stat
= Column(Integer
, nullable
=False)
148 effort
= Column(Integer
, nullable
=False)
150 class PokemonType(TableBase
):
151 __tablename__
= 'pokemon_types'
152 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False)
153 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
154 slot
= Column(Integer
, primary_key
=True, nullable
=False)
156 class Stat(TableBase
):
157 __tablename__
= 'stats'
158 id = Column(Integer
, primary_key
=True, nullable
=False)
159 name
= Column(Unicode(16), nullable
=False)
161 class TypeEfficacy(TableBase
):
162 __tablename__
= 'type_efficacy'
163 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False)
164 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False)
165 damage_factor
= Column(Integer
, nullable
=False)
167 class Type(TableBase
):
168 __tablename__
= 'types'
169 id = Column(Integer
, primary_key
=True, nullable
=False)
170 name
= Column(Unicode(8), nullable
=False)
171 abbreviation
= Column(Unicode(3), nullable
=False)
173 class VersionGroup(TableBase
):
174 __tablename__
= 'version_groups'
175 id = Column(Integer
, primary_key
=True, nullable
=False)
176 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
178 class Version(TableBase
):
179 __tablename__
= 'versions'
180 id = Column(Integer
, primary_key
=True, nullable
=False)
181 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
182 name
= Column(Unicode(32), nullable
=False)
185 ### Relations down here, to avoid ordering problems
186 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
187 order_by
=PokemonAbility
.slot
,
189 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
190 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
191 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
192 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
193 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
194 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
196 PokemonDexNumber
.generation
= relation(Generation
)
198 PokemonName
.language
= relation(Language
)
200 PokemonStat
.stat
= relation(Stat
)
202 Type
.damage_efficacies
= relation(TypeEfficacy
,
204 ==TypeEfficacy
.damage_type_id
,
205 backref
='damage_type')
206 Type
.target_efficacies
= relation(TypeEfficacy
,
208 ==TypeEfficacy
.target_type_id
,
209 backref
='target_type')