diff --git a/app_new/outlook/models.py b/app_new/outlook/models.py index 45bdda9..1dd5e79 100644 --- a/app_new/outlook/models.py +++ b/app_new/outlook/models.py @@ -95,7 +95,7 @@ class OutlookAttachment(db.Model): __tablename__ = "outlook_attachments" id = db.Column(db.String(100), primary_key=True) # Attachment ID from Microsoft - mail_id = db.Column(db.String(100), db.ForeignKey("outlook_mails.id"), nullable=False) + mail_id = db.Column(db.String(500), db.ForeignKey("outlook_mails.id"), nullable=False) name = db.Column(db.String(500), nullable=False) content_type = db.Column(db.String(100), nullable=True) size = db.Column(db.Integer, default=0) @@ -112,7 +112,7 @@ class OutlookMailInterpretation(db.Model): __tablename__ = "outlook_mail_interpretations" id = db.Column(db.Integer, primary_key=True) - mail_id = db.Column(db.String(100), db.ForeignKey("outlook_mails.id"), nullable=False) + mail_id = db.Column(db.String(500), db.ForeignKey("outlook_mails.id"), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) # Analyse brute (texte de l'IA) @@ -316,4 +316,4 @@ class GmaoContext(db.Model): # Note: Les routes Outlook sont dans app_new/outlook/routes.py -# Les templates sont dans app_new/outlook/templates/ \ No newline at end of file +# Les templates sont dans app_new/outlook/templates/ diff --git a/migrations/versions/d9e3f4a5b6c7_match_outlook_mail_foreign_keys.py b/migrations/versions/d9e3f4a5b6c7_match_outlook_mail_foreign_keys.py new file mode 100644 index 0000000..9416907 --- /dev/null +++ b/migrations/versions/d9e3f4a5b6c7_match_outlook_mail_foreign_keys.py @@ -0,0 +1,107 @@ +"""Match Outlook child foreign keys to the parent mail identifier. + +Revision ID: d9e3f4a5b6c7 +Revises: c8d2e3f4a5b6 +Create Date: 2026-08-14 +""" + +from alembic import op +import sqlalchemy as sa + + +revision = "d9e3f4a5b6c7" +down_revision = "c8d2e3f4a5b6" +branch_labels = None +depends_on = None + + +def upgrade(): + op.drop_constraint( + "outlook_attachments_ibfk_1", "outlook_attachments", type_="foreignkey" + ) + op.drop_constraint( + "outlook_mail_interpretations_ibfk_1", + "outlook_mail_interpretations", + type_="foreignkey", + ) + op.alter_column( + "outlook_mails", + "id", + existing_type=sa.String(length=100), + type_=sa.String(length=500), + existing_nullable=False, + ) + op.alter_column( + "outlook_attachments", + "mail_id", + existing_type=sa.String(length=100), + type_=sa.String(length=500), + existing_nullable=False, + ) + op.alter_column( + "outlook_mail_interpretations", + "mail_id", + existing_type=sa.String(length=100), + type_=sa.String(length=500), + existing_nullable=False, + ) + op.create_foreign_key( + "outlook_attachments_ibfk_1", + "outlook_attachments", + "outlook_mails", + ["mail_id"], + ["id"], + ) + op.create_foreign_key( + "outlook_mail_interpretations_ibfk_1", + "outlook_mail_interpretations", + "outlook_mails", + ["mail_id"], + ["id"], + ) + + +def downgrade(): + op.drop_constraint( + "outlook_mail_interpretations_ibfk_1", + "outlook_mail_interpretations", + type_="foreignkey", + ) + op.drop_constraint( + "outlook_attachments_ibfk_1", "outlook_attachments", type_="foreignkey" + ) + op.alter_column( + "outlook_mail_interpretations", + "mail_id", + existing_type=sa.String(length=500), + type_=sa.String(length=100), + existing_nullable=False, + ) + op.alter_column( + "outlook_attachments", + "mail_id", + existing_type=sa.String(length=500), + type_=sa.String(length=100), + existing_nullable=False, + ) + op.alter_column( + "outlook_mails", + "id", + existing_type=sa.String(length=500), + type_=sa.String(length=100), + existing_nullable=False, + ) + op.create_foreign_key( + "outlook_mail_interpretations_ibfk_1", + "outlook_mail_interpretations", + "outlook_mails", + ["mail_id"], + ["id"], + ) + op.create_foreign_key( + "outlook_attachments_ibfk_1", + "outlook_attachments", + "outlook_mails", + ["mail_id"], + ["id"], + )