diff --git a/app/models/raw_sql_init.py b/app/models/raw_sql_init.py index 0e57c3aee3..54f01cf9f5 100644 --- a/app/models/raw_sql_init.py +++ b/app/models/raw_sql_init.py @@ -35,6 +35,18 @@ BEGIN END LOOP; END; $$ LANGUAGE plpgsql; + +-- Fonction pour anonymisation: +-- inspirée par https://www.simononsoftware.com/random-string-in-postgresql/ +CREATE FUNCTION random_text_md5( integer ) returns text + LANGUAGE SQL + AS $$ + select upper( substring( (SELECT string_agg(md5(random()::TEXT), '') + FROM generate_series( + 1, + CEIL($1 / 32.)::integer) + ), 1, $1) ); + $$; """ ) db.session.commit() diff --git a/app/scodoc/sco_dump_db.py b/app/scodoc/sco_dump_db.py index 529afca01f..4f793d5fa1 100644 --- a/app/scodoc/sco_dump_db.py +++ b/app/scodoc/sco_dump_db.py @@ -205,7 +205,9 @@ def _drop_ano_db(ano_db_name): """drop temp database if it exists""" existing_databases = [ s.split("|")[0].strip() - for s in subprocess.check_output(["psql", "-l"]).split("\n")[3:] + for s in subprocess.check_output(["psql", "-l"]) + .decode(scu.SCO_ENCODING) + .split("\n")[3:] ] if ano_db_name not in existing_databases: log("_drop_ano_db: no temp db, nothing to drop")