From f992240192d486937bac3e3acc95310e1b531cb0 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 1 Jul 2016 16:30:45 +0100 Subject: [PATCH] make notification.key_type not nullable set to 'normal' for all existing notifications, and all job notifications also created as 'normal' - so if your eg reporting service hits notify, it gets notifications created from both API calls and front-end csv jobs. --- app/models.py | 2 +- .../versions/0036_notif_key_type_not_null.py | 27 +++++++++++++++++++ tests/app/dao/test_notification_dao.py | 6 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 migrations/versions/0036_notif_key_type_not_null.py diff --git a/app/models.py b/app/models.py index cd6186e33..fef1fe487 100644 --- a/app/models.py +++ b/app/models.py @@ -349,7 +349,7 @@ class Notification(db.Model): template_version = db.Column(db.Integer, nullable=False) api_key_id = db.Column(UUID(as_uuid=True), db.ForeignKey('api_keys.id'), index=True, unique=False) api_key = db.relationship('ApiKey') - key_type = db.Column(db.String, db.ForeignKey('key_types.name'), index=True, unique=False) + key_type = db.Column(db.String, db.ForeignKey('key_types.name'), index=True, unique=False, nullable=False) content_char_count = db.Column(db.Integer, nullable=True) notification_type = db.Column(notification_types, nullable=False) created_at = db.Column( diff --git a/migrations/versions/0036_notif_key_type_not_null.py b/migrations/versions/0036_notif_key_type_not_null.py new file mode 100644 index 000000000..fa81d09d8 --- /dev/null +++ b/migrations/versions/0036_notif_key_type_not_null.py @@ -0,0 +1,27 @@ +"""notification_api_key_not_nullable + +Revision ID: 0036_notif_key_type_not_null +Revises: 0035_notification_type +Create Date: 2016-07-01 16:01:16.892638 + +""" + +# revision identifiers, used by Alembic. +revision = '0036_notif_key_type_not_null' +down_revision = '0035_notification_type' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.execute("update notifications set key_type = 'normal' where key_type is null") + op.alter_column('notifications', 'key_type', existing_type=sa.VARCHAR(length=255), nullable=False) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.alter_column('notifications', 'key_type', existing_type=sa.VARCHAR(length=255), nullable=True) + ### end Alembic commands ### diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index d073e81f3..bedecaeb4 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -14,7 +14,8 @@ from app.models import ( Job, NotificationStatistics, TemplateStatistics, - NOTIFICATION_STATUS_TYPES + NOTIFICATION_STATUS_TYPES, + KEY_TYPE_NORMAL ) from app.dao.notifications_dao import ( @@ -976,7 +977,8 @@ 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 + 'notification_type': sample_template.template_type, + 'key_type': KEY_TYPE_NORMAL } if job_id: data.update({'job_id': job_id})