Fix cascade sur modimpl/abs

This commit is contained in:
Emmanuel Viennet 2023-03-15 19:13:45 +01:00
parent 5e79e97930
commit 9f45f1ee71
2 changed files with 44 additions and 3 deletions

View File

@ -24,10 +24,8 @@ class Absence(db.Model):
# moduleimpid concerne (optionnel): # moduleimpid concerne (optionnel):
moduleimpl_id = db.Column( moduleimpl_id = db.Column(
db.Integer, db.Integer,
db.ForeignKey("notes_moduleimpl.id"), db.ForeignKey("notes_moduleimpl.id", ondelete="SET NULL"),
) )
# XXX TODO: contrainte ajoutée: vérifier suppression du module
# (mettre à NULL sans supprimer)
def to_dict(self): def to_dict(self):
data = { data = {

View File

@ -0,0 +1,43 @@
"""fix_cascade_abs_mod
Revision ID: 6520faf67508
Revises: 19a608ebc9b7
Create Date: 2023-03-15 19:07:15.152610
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "6520faf67508"
down_revision = "19a608ebc9b7"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("absences_moduleimpl_id_fkey", "absences", type_="foreignkey")
op.create_foreign_key(
"absences_moduleimpl_id_fkey",
"absences",
"notes_moduleimpl",
["moduleimpl_id"],
["id"],
ondelete="SET NULL",
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("absences_moduleimpl_id_fkey", "absences", type_="foreignkey")
op.create_foreign_key(
"absences_moduleimpl_id_fkey",
"absences",
"notes_moduleimpl",
["moduleimpl_id"],
["id"],
)
# ### end Alembic commands ###