From d8e1a34610bd0ba7a498a3bdbae936c77e768ed8 Mon Sep 17 00:00:00 2001 From: Richard Chapman Date: Tue, 3 Oct 2017 11:03:31 +0100 Subject: [PATCH] Added a unique constraint to the notification_id column of the notification_to_email_reply_to table so that each notification can only have one mapping to service_email_reply_to and hence one email address. --- app/models.py | 2 +- migrations/versions/0123_add_noti_to_email_reply.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models.py b/app/models.py index 1103ce4f7..d1909d67c 100644 --- a/app/models.py +++ b/app/models.py @@ -1422,7 +1422,7 @@ class NotificationEmailReplyTo(db.Model): notification_id = db.Column( UUID(as_uuid=True), db.ForeignKey('notifications.id'), - unique=False, + unique=True, index=True, nullable=False, primary_key=True diff --git a/migrations/versions/0123_add_noti_to_email_reply.py b/migrations/versions/0123_add_noti_to_email_reply.py index e7484b327..f16c1605d 100644 --- a/migrations/versions/0123_add_noti_to_email_reply.py +++ b/migrations/versions/0123_add_noti_to_email_reply.py @@ -21,11 +21,10 @@ def upgrade(): sa.ForeignKeyConstraint(['service_email_reply_to_id'], ['service_email_reply_to.id'], ), sa.PrimaryKeyConstraint('notification_id', 'service_email_reply_to_id') ) - op.create_index(op.f('ix_notification_to_email_sender_notification_id'), 'notification_to_email_reply_to', ['notification_id'], unique=False) - op.create_index(op.f('ix_notification_to_email_sender_service_email_reply_to_id'), 'notification_to_email_reply_to', ['service_email_reply_to_id'], unique=False) - + op.create_index(op.f('ix_notification_to_email_reply_to_notification_id'), 'notification_to_email_reply_to', ['notification_id'], unique=True) + op.create_index(op.f('ix_notification_to_email_reply_to_service_email_reply_to_id'), 'notification_to_email_reply_to', ['service_email_reply_to_id'], unique=False) def downgrade(): - op.drop_index(op.f('ix_notification_to_email_sender_service_email_reply_to_id'), table_name='notification_to_email_reply_to') - op.drop_index(op.f('ix_notification_to_email_sender_notification_id'), table_name='notification_to_email_reply_to') + op.drop_index(op.f('ix_notification_to_email_reply_to_service_email_reply_to_id'), table_name='notification_to_email_reply_to') + op.drop_index(op.f('ix_notification_to_email_reply_to_notification_id'), table_name='notification_to_email_reply_to') op.drop_table('notification_to_email_reply_to')