From a0a7f5d33217cd2ad32b7eea20237707201b8bbe Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 1 Jun 2021 23:07:30 +0200 Subject: [PATCH] =?UTF-8?q?Ty=20jednodu=C5=A1=C5=A1=C3=AD=20Pavlovy=20?= =?UTF-8?q?=C4=8D=C3=A1sti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db_compare.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/db_compare.py b/db_compare.py index e21a860b..29775d3a 100644 --- a/db_compare.py +++ b/db_compare.py @@ -54,5 +54,104 @@ def check_skola(): for o,n in res: check_same(o,n,['id','aesop_id','izo','nazev','kratky_nazev','ulice','mesto','psc','stat','je_zs','je_ss','poznamka']) +def check_resitel(): + old_query = 'SELECT * FROM seminar_resitele ORDER BY id' + new_query = 'SELECT * FROM seminar_resitele JOIN seminar_osoby ON seminar_resitele.osoba_id = seminar_osoby.id ORDER BY seminar_resitele.id' + + old_res, new_res = execute_simple(old_query,new_query) + + res = zip(old_res,new_res) + + fields_osoba = [ + 'jmeno', + 'prijmeni', + 'user', + 'pohlavi_muz', + 'email', + 'telefon', + 'datum_narozeni', + 'datum_souhlasu_udaje', + 'datum_souhlasu_zasilani', + 'datum_prihlaseni', + 'ulice', + 'mesto', + 'psc', + 'stat', + ] + fields_keep = [ + 'id', + 'skola_id', + 'rok_maturity', + 'zasilat', + 'poznamka', + ] + fields_old = fields_keep+fields_osoba + fields_new = fields_keep + ['seminar_osoby.'+f for f in fields_osoba] + for o,n in res: + check_same(o,n,fields_old, fields_new) + +def check_reseni(): + old_query = 'SELECT * FROM seminar_reseni ORDER BY id' + new_query = 'SELECT * FROM seminar_reseni JOIN seminar_hodnoceni AS hodnoceni ON hodnoceni_id = hodnoceni.id ORDER BY id' + + same_fields = ['id', 'forma', 'poznamka'] + renamed_fields = [('timestamp', 'cas_doruceni'), + # Also moved fields + ('problem_id', 'hodnoceni.problem_id'), + ('body', 'hodnoceni.body'), + ('cislo_body_id', 'hodnoceni.cislo_body_id'), + ] + old_fields = same_fields + [f[0] for f in renamed_fields] + new_fields = same_fields + [f[1] for f in renamed_fields] + + old_res, new_res = execute_simple(old_query,new_query) + + res = zip(old_res,new_res) + + for o,n in res: + check_same(o,n,old_fields, new_fields) + + # Ř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' + + oldcur = oldconn.cursor() + old_results = oldcur.execute(old_query).fetchall() + newcur = newconn.cursor() + new_results = newcur.execute(old_query).fetchall() + + for oldr in old_results: + if oldr not in new_results: + raise ValueError(f'Pair {oldr} not found in new db.') + +def check_organizator(): + old_query = 'SELECT * FROM seminar_organizatori ORDER BY id' + new_query = 'SELECT * 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' + + same_fields = ['studuje', 'strucny_popis_organizatora'] + renamed_fields = [ + ('user_id', 'user.id'), + ('prezdivka', 'osoba.prezdivka'), + ('foto', 'osoba.foto'), + ('foto_male', 'osoba.foto_male'), + ] + old_fields = same_fields + [f[0] for f in renamed_fields] + new_fields = same_fields + [f[1] for f in renamed_fields] + + old_res, new_res = execute_simple(old_query,new_query) + res = zip(old_res, new_res) + 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}') + + + check_skola() +check_resitel() +check_reseni() +check_organizator()