MonScoDocEssai/migrations/versions/d84bc592584e_extension_unaccent.py
Emmanuel Viennet 8e1cb055f6 - corrige saisi stage sur entreprise (fix #642)
- clé étrangère sur Identite dans EntrepriseStageApprentissage
- nouveau mécanisme pour le choix d'étudiant via auto-completion
  (ajout de autoComplete.js-10.2.7)
- nouveau point d'API: /etudiants/name/<string:start> (et son test unitaire)
2023-06-01 17:58:30 +02:00

61 lines
1.5 KiB
Python

"""Extension unaccent
Revision ID: d84bc592584e
Revises: b8df1b913c79
Create Date: 2023-06-01 13:46:52.927951
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker # added by ev
# revision identifiers, used by Alembic.
revision = "d84bc592584e"
down_revision = "b8df1b913c79"
branch_labels = None
depends_on = None
Session = sessionmaker()
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
bind = op.get_bind()
session = Session(bind=bind)
# Ajout extension pour recherches sans accents:
session.execute(sa.text("""CREATE EXTENSION IF NOT EXISTS "unaccent";"""))
# Clé étrangère sur identite
session.execute(
sa.text(
"""UPDATE are_stages_apprentissages
SET etudid = NULL
WHERE are_stages_apprentissages.etudid NOT IN (
SELECT id
FROM Identite
);
"""
)
)
with op.batch_alter_table("are_stages_apprentissages", schema=None) as batch_op:
batch_op.create_foreign_key(
"are_stages_apprentissages_etudid_fkey",
"identite",
["etudid"],
["id"],
ondelete="CASCADE",
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("are_stages_apprentissages", schema=None) as batch_op:
batch_op.drop_constraint(
"are_stages_apprentissages_etudid_fkey", type_="foreignkey"
)
# ### end Alembic commands ###