Skip to content

Commit

Permalink
Ajout option --keep-cdnom pour empecher la suppression des cd_noms ma…
Browse files Browse the repository at this point in the history
…nquants - cf #306
  • Loading branch information
amandine-sahl committed Mar 14, 2022
1 parent e8bfd28 commit 2ae98b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 11 additions & 5 deletions apptax/migrations/taxref/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,30 @@ def import_taxref_v15():


@routes.cli.command()
def test_changes_detection():
@click.option("--keep-cdnom", is_flag=True)
def test_changes_detection(keep_cdnom):
"""Analyse des répercussions de changement de taxref
:param keep-cdnom: Indique si l'on souhaite concerver les cd_noms manquant au lieu de les supprimer
:type keep-cdnom: boolean
3 étapes :
- Detection des cd_noms manquants
- Création d'une copie de travail de bib_noms
- Analyse des modifications taxonomique (split, merge, ...) et
de leur répercussion sur les attributs et medias de taxhub
"""
# Analyse des changements à venir
analyse_taxref_changes(without_substitution=False)
analyse_taxref_changes(without_substitution=False, keep_missing_cd_nom=keep_cdnom)


@routes.cli.command()
@click.option("--keep-oldtaxref", is_flag=True)
@click.option("--keep-oldbdc", is_flag=True)
@click.option("--keep-cdnom", is_flag=True)
@click.option("--script_predetection", type=click.Path(exists=True))
@click.option("--script_postdetection", type=click.Path(exists=True))
def apply_changes(keep_oldtaxref, keep_oldbdc, script_predetection, script_postdetection):
def apply_changes(keep_oldtaxref, keep_oldbdc, keep_cdnom, script_predetection, script_postdetection):
"""Procédure de migration de taxref
Taxref v14 vers v15
Application des changements import des données dans les tables taxref et bdc_status
Expand All @@ -72,14 +77,15 @@ def apply_changes(keep_oldtaxref, keep_oldbdc, script_predetection, script_postd
:type keep-oldtaxref: boolean
:param keep-oldbdc: Indique si l'on souhaite concerver l'ancienne version du referentiel bdc_status
:type keep-oldbdc: boolean
:param keep-cdnom: Indique si l'on souhaite concerver les cd_noms manquant au lieu de les supprimer
:type keep-cdnom: boolean
:param script_predetection: Emplacement d'un fichier sql de correction avant la detection des changements
:type script_predetection: Path
:param script_postdetection: Emplacement d'un fichier sql de correction après la detection des changements
:type script_postdetection: Path
"""

# Analyse des changements à venir
analyse_taxref_changes(without_substitution=False)
analyse_taxref_changes(without_substitution=False, keep_missing_cd_nom=keep_cdnom)

# Save taxref and bdc_status data
save_data(14, keep_oldtaxref, keep_oldbdc)
Expand Down
14 changes: 9 additions & 5 deletions apptax/migrations/taxref/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)


def analyse_taxref_changes(without_substitution=True):
def analyse_taxref_changes(without_substitution=True, keep_missing_cd_nom=False):
"""
Analyse des répercussions de changement de taxref
Expand All @@ -30,13 +30,13 @@ def analyse_taxref_changes(without_substitution=True):
de leur répercussion sur les attributs et medias de taxhub
"""
# test if deleted cd_nom can be correct without manual intervention
if test_missing_cd_nom(without_substitution):
# And keep_missing_cd_nom is not set
if test_missing_cd_nom(without_substitution) and not keep_missing_cd_nom:
logger.error("Some cd_nom will disappear without substitute. You can't continue migration. Analyse exports files")
# TODO ??? Force exit or not ??? https://github.com/PnX-SI/TaxHub/issues/306
exit()

# Test missing cd_nom
create_copy_bib_noms()
create_copy_bib_noms(keep_missing_cd_nom)

# Change detection and repport
nb_of_conflict = detect_changes()
Expand All @@ -46,7 +46,7 @@ def analyse_taxref_changes(without_substitution=True):
exit()


def create_copy_bib_noms():
def create_copy_bib_noms(keep_missing_cd_nom=False):
"""
Création d'une table copie de bib_noms
"""
Expand All @@ -59,6 +59,10 @@ def create_copy_bib_noms():
)
)
db.session.execute(query)
if keep_missing_cd_nom:
db.session.execute(text("""
UPDATE taxonomie.tmp_bib_noms_copy tbnc SET deleted = FALSE WHERE deleted = TRUE;
"""))
db.session.commit()


Expand Down

0 comments on commit 2ae98b1

Please sign in to comment.