Fix: contrainte SQL unicite réf. comp.

This commit is contained in:
Emmanuel Viennet 2022-06-27 20:25:58 +02:00
parent 4e02928c04
commit 6ffa4b8d7a
2 changed files with 39 additions and 2 deletions

View File

@ -56,13 +56,13 @@ def orebut_import_refcomp(xml_data: str, dept_id: int, orig_filename=None):
try: try:
c = ApcCompetence(**ApcCompetence.attr_from_xml(competence.attrib)) c = ApcCompetence(**ApcCompetence.attr_from_xml(competence.attrib))
db.session.flush() 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 # ne devrait plus se produire car pas d'unicité de l'id: donc inutile
db.session.rollback() db.session.rollback()
raise ScoValueError( raise ScoValueError(
f"""Un référentiel a déjà été chargé avec les mêmes compétences ! ({competence.attrib["id"]}) 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) ref.competences.append(c)
# --- SITUATIONS # --- SITUATIONS
situations = competence.find("situations") situations = competence.find("situations")

View File

@ -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 ###