Bugfixes, broken check_organizator.
This commit is contained in:
parent
52f5259040
commit
8b9357d3d6
1 changed files with 37 additions and 21 deletions
|
@ -38,7 +38,7 @@ def check_same(old_row, new_row, old_fields, new_fields=None):
|
|||
for old_field, new_field in fields:
|
||||
if old_row[old_field] == new_row[new_field]:
|
||||
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
|
||||
|
||||
def get_user_id_for_org_id(org_id):
|
||||
|
@ -64,10 +64,10 @@ def check_skola():
|
|||
|
||||
def check_resitel():
|
||||
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.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
|
||||
FROM seminar_resitele JOIN seminar_osoby AS o ON seminar_resitele.osoba_id = seminar_osoby.id ORDER BY seminar_resitele.id'''
|
||||
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 = o.id ORDER BY seminar_resitele.id'''
|
||||
|
||||
old_res, new_res = execute_simple(old_query,new_query)
|
||||
|
||||
|
@ -78,7 +78,7 @@ def check_resitel():
|
|||
'prijmeni',
|
||||
'user_id',
|
||||
'pohlavi_muz',
|
||||
'email',
|
||||
#'email', #TODO: potřeba dořešit, protože merge řešitele a organizátora
|
||||
'telefon',
|
||||
'datum_narozeni',
|
||||
'datum_souhlasu_udaje',
|
||||
|
@ -102,7 +102,10 @@ def check_resitel():
|
|||
|
||||
def check_reseni():
|
||||
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']
|
||||
renamed_fields = [('timestamp', 'cas_doruceni'),
|
||||
|
@ -122,27 +125,32 @@ def check_reseni():
|
|||
|
||||
# Řešitelé jsou nově m2m, takže je musíme dohledat
|
||||
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()
|
||||
old_results = oldcur.execute(old_query).fetchall()
|
||||
newcur = newconn.cursor()
|
||||
new_results = newcur.execute(new_query).fetchall()
|
||||
#oldcur = oldconn.cursor()
|
||||
oldcur.execute(old_query)
|
||||
old_results = oldcur.fetchall()
|
||||
#newcur = newconn.cursor()
|
||||
newcur.execute(new_query)
|
||||
new_results = newcur.fetchall()
|
||||
|
||||
for oldr in old_results:
|
||||
if oldr not in new_results:
|
||||
raise ValueError(f'Reseni pair {oldr} not found in new db.')
|
||||
|
||||
def check_organizator():
|
||||
old_query = 'SELECT * FROM seminar_organizatori 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'
|
||||
old_query = 'SELECT * FROM seminar_organizator 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']
|
||||
renamed_fields = [
|
||||
('user_id', 'uid'),
|
||||
('prezdivka', 'o_prezdivka'),
|
||||
#('prezdivka', 'o_prezdivka'),
|
||||
('foto', 'o_foto'),
|
||||
('foto_male', 'o_foto_male'),
|
||||
]
|
||||
old_fields = same_fields + [f[0] 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:
|
||||
check_same(o,n,old_fields, new_fields)
|
||||
# organizuje od, do:
|
||||
if o.organizuje_od_roku != n.organizuje_od.year:
|
||||
raise ValueError(f'Not matching organizuje_od for org id={o.id}: old {o.organizuje_od_roku}, new {n.organizuje_od}')
|
||||
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}')
|
||||
print(list(o.keys()),list(n.keys()))
|
||||
if o['organizuje_od_roku'] != n['organizuje_od'].year:
|
||||
raise ValueError(f'Not matching organizuje_od for org id={o["id"]}: old {o["organizuje_od_roku"]}, new {n["organizuje_od"]}')
|
||||
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():
|
||||
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"
|
||||
|
||||
# Simple cursors
|
||||
oldcur = oldconn.cursor()
|
||||
#oldcur = oldconn.cursor()
|
||||
old_results = oldcur.execute(old_query).fetchall()
|
||||
newcur = newconn.cursor()
|
||||
#newcur = newconn.cursor()
|
||||
new_results = newcur.execute(new_query).fetchall()
|
||||
|
||||
for oldr in old_results:
|
||||
|
|
Loading…
Reference in a new issue