Remove a bad test
[zzz-pokedex.git] / scripts / set_pokemon_order.py
1 #!/usr/bin/env python2
2
3 import sqlite3
4
5 conn = sqlite3.connect("pokedex/data/pokedex.sqlite")
6
7 cur = conn.execute(
8 """select p.id, p.name, pf.name
9 from pokemon p
10 join evolution_chains ec on p.evolution_chain_id = ec.id
11 left join pokemon_forms pf on p.id = pf.unique_pokemon_id
12 order by ec.id, is_baby = 0, coalesce(pf.form_base_pokemon_id, p.id),
13 pf."order", pf.name
14 ;""")
15
16 idmap = []
17
18 for i, row in enumerate(cur):
19 idmap.append((1 + i, row[0]))
20
21 conn.executemany(
22 """update pokemon set "order" = ? where id = ?""",
23 idmap,
24 )
25
26 conn.commit()
27