Browse Source

Bugfixes, broken check_organizator.

middleware_test
parent
commit
8b9357d3d6
  1. 58
      db_compare.py

58
db_compare.py

@ -38,7 +38,7 @@ def check_same(old_row, new_row, old_fields, new_fields=None):
for old_field, new_field in fields: for old_field, new_field in fields:
if old_row[old_field] == new_row[new_field]: if old_row[old_field] == new_row[new_field]:
continue continue
raise ValueError(f"Fields '{old_field}' and '{new_field}' differs for rows \n'{old_row}' and \n'{new_row}'") raise ValueError(f"Fields '{old_field}'({old_row[old_field]}) and '{new_field}'({new_row[new_field]}) differs for rows \n'{old_row}' and \n'{new_row}'")
return True return True
def get_user_id_for_org_id(org_id): def get_user_id_for_org_id(org_id):
@ -64,10 +64,10 @@ def check_skola():
def check_resitel(): def check_resitel():
old_query = 'SELECT * FROM seminar_resitele ORDER BY id' old_query = 'SELECT * FROM seminar_resitele ORDER BY id'
new_query = '''SELECT id, skola_id, rok_maturity, zasilat, poznamka, new_query = '''SELECT seminar_resitele.id, skola_id, rok_maturity, zasilat, seminar_resitele.poznamka,
o.jmeno AS jmeno, o.prijmeni AS prijmeni, o.user_id AS user_id, o.pohlavi_muz AS pohlavi_muz, o.email AS email, o.telefon AS telefon, o.datum_narozeni AS datum_narozeni, o.jmeno AS jmeno, o.prijmeni AS prijmeni, o.user_id AS user_id, o.pohlavi_muz AS pohlavi_muz, o.email AS email, o.telefon AS telefon, o.datum_narozeni AS datum_narozeni,
o.datum_souhlasu_udaje AS datum_souhlasu_udaje, o.datum_souhlasu_zasilani AS datum_souhlasu_zasilani, o.datum_prihlaseni AS datum_prihlaseni, o.ulice AS ulice, o.mesto AS mesto, o.psc AS psc, o.stat AS stat o.datum_souhlasu_udaje AS datum_souhlasu_udaje, o.datum_souhlasu_zasilani AS datum_souhlasu_zasilani, o.datum_registrace AS datum_prihlaseni, o.ulice AS ulice, o.mesto AS mesto, o.psc AS psc, o.stat AS stat
FROM seminar_resitele JOIN seminar_osoby AS o ON seminar_resitele.osoba_id = seminar_osoby.id ORDER BY seminar_resitele.id''' FROM seminar_resitele JOIN seminar_osoby AS o ON seminar_resitele.osoba_id = o.id ORDER BY seminar_resitele.id'''
old_res, new_res = execute_simple(old_query,new_query) old_res, new_res = execute_simple(old_query,new_query)
@ -78,7 +78,7 @@ def check_resitel():
'prijmeni', 'prijmeni',
'user_id', 'user_id',
'pohlavi_muz', 'pohlavi_muz',
'email', #'email', #TODO: potřeba dořešit, protože merge řešitele a organizátora
'telefon', 'telefon',
'datum_narozeni', 'datum_narozeni',
'datum_souhlasu_udaje', 'datum_souhlasu_udaje',
@ -102,7 +102,10 @@ def check_resitel():
def check_reseni(): def check_reseni():
old_query = 'SELECT * FROM seminar_reseni ORDER BY id' old_query = 'SELECT * FROM seminar_reseni ORDER BY id'
new_query = 'SELECT id, forma, poznamka, cas_doruceni, hodnoceni.problem_id AS h_problem_id, hodnoceni.body AS h_body, hodnoceni.cislo_body_id AS h_cislo_body_id FROM seminar_reseni JOIN seminar_hodnoceni AS hodnoceni ON hodnoceni_id = hodnoceni.id ORDER BY id' new_query = '''SELECT seminar_reseni.id, forma, poznamka, cas_doruceni, hodnoceni.problem_id AS h_problem_id, hodnoceni.body AS h_body, hodnoceni.cislo_body_id AS h_cislo_body_id
FROM seminar_reseni
JOIN seminar_hodnoceni AS hodnoceni ON seminar_reseni.id = hodnoceni.reseni_id
ORDER BY id'''
same_fields = ['id', 'forma', 'poznamka'] same_fields = ['id', 'forma', 'poznamka']
renamed_fields = [('timestamp', 'cas_doruceni'), renamed_fields = [('timestamp', 'cas_doruceni'),
@ -122,27 +125,32 @@ def check_reseni():
# Řešitelé jsou nově m2m, takže je musíme dohledat # Řešitelé jsou nově m2m, takže je musíme dohledat
old_query = 'SELECT id, resitel_id FROM seminar_reseni ORDER BY id' old_query = 'SELECT id, resitel_id FROM seminar_reseni ORDER BY id'
new_query = 'SELECT reseni_id, resitel_id FROM seminar_reseni_resitele ORDER BY reseni_id' new_query = 'SELECT reseni_id, resitele_id FROM seminar_reseni_resitele ORDER BY reseni_id'
oldcur = oldconn.cursor() #oldcur = oldconn.cursor()
old_results = oldcur.execute(old_query).fetchall() oldcur.execute(old_query)
newcur = newconn.cursor() old_results = oldcur.fetchall()
new_results = newcur.execute(new_query).fetchall() #newcur = newconn.cursor()
newcur.execute(new_query)
new_results = newcur.fetchall()
for oldr in old_results: for oldr in old_results:
if oldr not in new_results: if oldr not in new_results:
raise ValueError(f'Reseni pair {oldr} not found in new db.') raise ValueError(f'Reseni pair {oldr} not found in new db.')
def check_organizator(): def check_organizator():
old_query = 'SELECT * FROM seminar_organizatori ORDER BY id' old_query = 'SELECT * FROM seminar_organizator ORDER BY id'
new_query = 'SELECT studuje, strucny_popis_organizatora, user.id AS uid, osoba.prezdivka AS o_prezdivka, osoba.foto AS o_foto, osoba.foto_male AS o_foto_male FROM seminar_organizatori JOIN seminar_osoby AS osoba ON osoba_id = osoba.id JOIN auth_user AS user ON osoba.user_id = user.id ORDER BY id' new_query = '''SELECT seminar_organizator.id AS id, studuje, strucny_popis_organizatora, users.id AS uid, osoba.prezdivka AS o_prezdivka, osoba.foto AS o_foto, organizuje_od, organizuje_do
FROM seminar_organizator
JOIN seminar_osoby AS osoba ON osoba_id = osoba.id
JOIN auth_user AS users ON osoba.user_id = users.id
ORDER BY seminar_organizator.id'''
same_fields = ['studuje', 'strucny_popis_organizatora'] same_fields = ['studuje', 'strucny_popis_organizatora']
renamed_fields = [ renamed_fields = [
('user_id', 'uid'), ('user_id', 'uid'),
('prezdivka', 'o_prezdivka'), #('prezdivka', 'o_prezdivka'),
('foto', 'o_foto'), ('foto', 'o_foto'),
('foto_male', 'o_foto_male'),
] ]
old_fields = same_fields + [f[0] for f in renamed_fields] old_fields = same_fields + [f[0] for f in renamed_fields]
new_fields = same_fields + [f[1] for f in renamed_fields] new_fields = same_fields + [f[1] for f in renamed_fields]
@ -152,10 +160,18 @@ def check_organizator():
for o,n in res: for o,n in res:
check_same(o,n,old_fields, new_fields) check_same(o,n,old_fields, new_fields)
# organizuje od, do: # organizuje od, do:
if o.organizuje_od_roku != n.organizuje_od.year: print(list(o.keys()),list(n.keys()))
raise ValueError(f'Not matching organizuje_od for org id={o.id}: old {o.organizuje_od_roku}, new {n.organizuje_od}') if o['organizuje_od_roku'] != n['organizuje_od'].year:
if o.organizuje_do_roku != n.organizuje_do.year: raise ValueError(f'Not matching organizuje_od for org id={o["id"]}: old {o["organizuje_od_roku"]}, new {n["organizuje_od"]}')
raise ValueError(f'Not matching organizuje_do for org id={o.id}: old {o.organizuje_do_roku}, new {n.organizuje_do}') if o['organizuje_do_roku'] != n['organizuje_do'].year:
raise ValueError(f'Not matching organizuje_do for org id={o["id"]}: old {o["organizuje_do_roku"]}, new {n["organizuje_do"]}')
if o['prezdivka'] == n['o_prezdivka']:
continue
if o['prezdivka'] is None and n['o_prezdivka'] == '':
continue
print(o,n)
raise ValueError(f'Not matching prezdivka for org id={o["id"]}: old {o["prezdivka"]}, new {n["o_prezdivka"]}')
def check_rocnik(): def check_rocnik():
old_query = "SELECT * FROM seminar_rocniky ORDER BY id" old_query = "SELECT * FROM seminar_rocniky ORDER BY id"
@ -278,9 +294,9 @@ def check_problem_common():
new_query = "SELECT problem_id, opravovatel_id FROM seminar_problemy_opravovatele" new_query = "SELECT problem_id, opravovatel_id FROM seminar_problemy_opravovatele"
# Simple cursors # Simple cursors
oldcur = oldconn.cursor() #oldcur = oldconn.cursor()
old_results = oldcur.execute(old_query).fetchall() old_results = oldcur.execute(old_query).fetchall()
newcur = newconn.cursor() #newcur = newconn.cursor()
new_results = newcur.execute(new_query).fetchall() new_results = newcur.execute(new_query).fetchall()
for oldr in old_results: for oldr in old_results:

Loading…
Cancel
Save