From 6ffa4b8d7a33cd2e436df931c1e1bee3ce80d6b6 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 27 Jun 2022 20:25:58 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20contrainte=20SQL=20unicite=20r=C3=A9f.?= =?UTF-8?q?=20comp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/import_refcomp.py | 4 +- .../ee21c76c8183_fix_contrainte_refcomp.py | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/ee21c76c8183_fix_contrainte_refcomp.py diff --git a/app/but/import_refcomp.py b/app/but/import_refcomp.py index ae44a34ce..9acd1c9db 100644 --- a/app/but/import_refcomp.py +++ b/app/but/import_refcomp.py @@ -56,13 +56,13 @@ def orebut_import_refcomp(xml_data: str, dept_id: int, orig_filename=None): try: c = ApcCompetence(**ApcCompetence.attr_from_xml(competence.attrib)) db.session.flush() - except sqlalchemy.exc.IntegrityError: + except sqlalchemy.exc.IntegrityError as exc: # ne devrait plus se produire car pas d'unicité de l'id: donc inutile db.session.rollback() raise ScoValueError( f"""Un référentiel a déjà été chargé avec les mêmes compétences ! ({competence.attrib["id"]}) """ - ) + ) from exc ref.competences.append(c) # --- SITUATIONS situations = competence.find("situations") diff --git a/migrations/versions/ee21c76c8183_fix_contrainte_refcomp.py b/migrations/versions/ee21c76c8183_fix_contrainte_refcomp.py new file mode 100644 index 000000000..0d97b0618 --- /dev/null +++ b/migrations/versions/ee21c76c8183_fix_contrainte_refcomp.py @@ -0,0 +1,37 @@ +"""Corrige contrainte unicité référentiel compétences + +Revision ID: ee21c76c8183 +Revises: c0c225192d61 +Create Date: 2022-06-27 20:18:24.822527 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "ee21c76c8183" +down_revision = "c0c225192d61" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index("ix_apc_competence_id_orebut", table_name="apc_competence") + op.create_index( + op.f("ix_apc_competence_id_orebut"), + "apc_competence", + ["id_orebut"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_apc_competence_id_orebut"), table_name="apc_competence") + op.create_index( + "ix_apc_competence_id_orebut", "apc_competence", ["id_orebut"], unique=False + ) + # ### end Alembic commands ###