Add notification_type to notification table.

It seems like an oversight not to include the notification type in the notifcation.
When updating statistics a query to the template table is required to get the type, this update will mean that query does not have to happen.
This commit is contained in:
Rebecca Law
2016-06-29 11:23:02 +01:00
parent 340abae82c
commit 60e159e3c0
6 changed files with 35 additions and 3 deletions

View File

@@ -157,7 +157,8 @@ def send_sms(self, service_id, notification_id, encrypted_notification, created_
job_row_number=notification.get('row_number', None),
status='created',
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
personalisation=notification.get('personalisation')
personalisation=notification.get('personalisation'),
notification_type='sms'
)
dao_create_notification(notification_db_object, TEMPLATE_TYPE_SMS)
@@ -202,7 +203,8 @@ def send_email(service_id, notification_id, encrypted_notification, created_at,
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
sent_at=sent_at,
sent_by=provider.get_name(),
personalisation=notification.get('personalisation')
personalisation=notification.get('personalisation'),
notification_type='email'
)
dao_create_notification(notification_db_object, TEMPLATE_TYPE_EMAIL)

View File

@@ -345,6 +345,7 @@ class Notification(db.Model):
api_key = db.relationship('ApiKey')
key_type = db.Column(db.String, db.ForeignKey('key_types.name'), index=True, unique=False)
content_char_count = db.Column(db.Integer, nullable=True)
notification_type = db.Column(db.String(), nullable=False)
created_at = db.Column(
db.DateTime,
index=False,

View File

@@ -0,0 +1,26 @@
"""empty message
Revision ID: 0035_notification_type
Revises: 0034_pwd_changed_at_not_null
Create Date: 2016-06-29 10:48:55.955317
"""
# revision identifiers, used by Alembic.
revision = '0035_notification_type'
down_revision = '0034_pwd_changed_at_not_null'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('notifications', sa.Column('notification_type', sa.String(), nullable=True))
op.execute('update notifications set notification_type = (select distinct(template_type) '
'from templates where templates.id = notifications.template_id)')
op.alter_column('notifications', 'notification_type', nullable=False)
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('notifications', 'notification_type')
### end Alembic commands ###

View File

@@ -46,6 +46,7 @@ def _notification_json(template, to, personalisation=None, job_id=None, row_numb
"template": str(template.id),
"template_version": template.version,
"to": to,
"notification_type": template.template_type
}
if personalisation:
notification.update({"personalisation": personalisation})

View File

@@ -351,7 +351,8 @@ def sample_notification(notify_db,
'reference': reference,
'created_at': created_at,
'content_char_count': content_char_count,
'personalisation': personalisation
'personalisation': personalisation,
'notification_type': template.template_type
}
if job_row_number:
data['job_row_number'] = job_row_number

View File

@@ -976,6 +976,7 @@ def _notification_json(sample_template, job_id=None, id=None, status=None):
'template_version': sample_template.version,
'created_at': datetime.utcnow(),
'content_char_count': 160,
'notification_type': sample_template.template_type
}
if job_id:
data.update({'job_id': job_id})