From f095fa1ddf5fd2d9aa793b02f6e00d7f5a380507 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 3 Sep 2018 16:48:08 +0100 Subject: [PATCH] Add unique constraint to email branding domain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Brandings with a domain set should be considered canonical. It doesn’t make sense to have the same domain set on multiple different email brands – you can’t tell which one to use. --- app/models.py | 2 +- .../versions/0223_add_domain_constraint.py | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/0223_add_domain_constraint.py diff --git a/app/models.py b/app/models.py index 39e7b2716..353b6e56c 100644 --- a/app/models.py +++ b/app/models.py @@ -207,7 +207,7 @@ class EmailBranding(db.Model): logo = db.Column(db.String(255), nullable=True) name = db.Column(db.String(255), nullable=True) text = db.Column(db.String(255), nullable=True) - domain = db.Column(db.Text, nullable=True) + domain = db.Column(db.Text, unique=True, nullable=True) brand_type = db.Column( db.String(255), db.ForeignKey('branding_type.name'), diff --git a/migrations/versions/0223_add_domain_constraint.py b/migrations/versions/0223_add_domain_constraint.py new file mode 100644 index 000000000..4b8f8d915 --- /dev/null +++ b/migrations/versions/0223_add_domain_constraint.py @@ -0,0 +1,20 @@ +""" +Revision ID: 0223_add_domain_constraint +Revises: 0222_drop_service_branding +Create Date: 2018-08-24 13:36:49.346156 + """ +from alembic import op + + +revision = '0223_add_domain_constraint' +down_revision = '0222_drop_service_branding' + + +def upgrade(): + + op.create_unique_constraint('uq_email_branding_domain', 'email_branding', ['domain']) + + +def downgrade(): + + op.drop_constraint('uq_email_branding_domain', 'email_branding')