Skip to content

Commit

Permalink
Taxref v17 migrate tests commands + improve reporting (#515)
Browse files Browse the repository at this point in the history
* Correction commande taxref info

* Taxref v17: ajout commande test de la migration

* Déplacement données examples pour les tests

* Improve split reporting
  • Loading branch information
amandine-sahl authored Aug 7, 2024
1 parent 848994c commit 03705c1
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 280 deletions.
18 changes: 0 additions & 18 deletions apptax/taxonomie/commands/migrate_taxref/commands_v16.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from apptax.taxonomie.commands.migrate_taxref.test_commands_v16 import (
populate_data,
clean_data,
test_import_taxref_v16,
)

from flask import Blueprint

import importlib
Expand Down Expand Up @@ -197,15 +191,3 @@ def import_and_format_dbc_status():
"""
truncate_bdc_statuts()
import_bdc_statuts_v16(logger)


@migrate_to_v16.command()
@with_appcontext
def test_taxref_v16_migration():
populate_data()
try:
test_import_taxref_v16()
except AssertionError as e:
raise (e)
finally:
clean_data()
2 changes: 1 addition & 1 deletion apptax/taxonomie/commands/migrate_taxref/commands_v17.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def apply_changes(
db.session.commit()

logger.info("Vacuum the database... (cette opération peut être longue)")
with db.session.connection(execution_options={"isolation_level": "AUTOCOMMIT"}) as conn:
with db.engine.connect() as conn:
conn.execute(text("VACUUM FULL VERBOSE"))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,17 @@ WHERE NOT i.array_agg = f.array_agg;
ALTER TABLE tmp_taxref_changes.split_analyze ADD cas varchar(50);

UPDATE tmp_taxref_changes.split_analyze SET cas = 'split'
WHERE i_array_agg @> f_array_agg AND NOT i_array_agg = f_array_agg ;
WHERE i_array_agg @> f_array_agg AND NOT i_array_agg = f_array_agg;

UPDATE tmp_taxref_changes.split_analyze SET cas = 'merge'
WHERE f_array_agg @> i_array_agg AND NOT i_array_agg = f_array_agg AND cas IS NULL;


UPDATE tmp_taxref_changes.split_analyze SET cas = 'split and merge'
WHERE NOT i_array_agg @> f_array_agg --grappe initial non incluse totalement dans la grappe finale
AND i_array_agg && f_array_agg -- grappe finale contient au moins un élément de la grappe initiale
AND NOT i_array_agg = f_array_agg AND cas IS NULL;

UPDATE tmp_taxref_changes.split_analyze SET cas = CONCAT(cas || ' - ', 'update cd_ref')
WHERE i_cd_ref = f_cd_ref;

7 changes: 4 additions & 3 deletions apptax/taxonomie/commands/migrate_taxref/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@
SELECT
t.regne, t.group1_inpn, t.group2_inpn,
s.i_cd_ref, s.i_array_agg AS i_cd_noms, t.nom_valide AS i_nom_valid,
s.f_cd_ref, s.f_array_agg AS f_cd_noms, it.nom_valide AS f_nom_valid
s.f_cd_ref, s.f_array_agg AS f_cd_noms, it.nom_valide AS f_nom_valid,
cas
FROM tmp_taxref_changes.split_analyze s
JOIN taxonomie.taxref t
ON t.cd_nom = s.i_cd_ref
JOIN taxonomie.import_taxref it
ON it.cd_nom = s.f_cd_ref
WHERE cas = 'split';
WHERE not cas IS NULL;
"""

EXPORT_QUERIES_NB_SPLIT = """
SELECT count(*) FROM tmp_taxref_changes.split_analyze WHERE cas = 'split'
SELECT count(*) FROM tmp_taxref_changes.split_analyze WHERE cas ilike '%split%'
"""
Loading

0 comments on commit 03705c1

Please sign in to comment.