mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Fix bug where all notifications were getting a type = email.
Includes a fix to notification and notification_statistics data.
This commit is contained in:
44
migrations/versions/0038_fix_notifications.py
Normal file
44
migrations/versions/0038_fix_notifications.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0038_fix_notifications
|
||||
Revises: 0037_service_sms_sender
|
||||
Create Date: 2016-07-06 13:28:48.381278
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0038_fix_notifications'
|
||||
down_revision = '0037_service_sms_sender'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute('update notifications set notification_type = (select cast(cast(template_type as text) as notification_type) from templates where templates.id= notifications.template_id)')
|
||||
conn = op.get_bind()
|
||||
del_sql = "select n.id, results.* from (select 'failed' as stat_type, count(status) as count, notification_type, date(created_at) as day, service_id " \
|
||||
"from notifications where status in ('temporary-failure', 'permanent-failure', 'technical-failure') group by service_id, notification_type, date(created_at) " \
|
||||
"union select 'delivered' as stat_type, count(status) , notification_type, date(created_at) as day, service_id " \
|
||||
"from notifications where status in ('delivered') group by service_id, notification_type, date(created_at)) as results, " \
|
||||
"notification_statistics n " \
|
||||
"where n.day = results.day and n.service_id = results.service_id order by results.day;"
|
||||
|
||||
results = conn.execute(del_sql)
|
||||
res = results.fetchall()
|
||||
|
||||
for x in res:
|
||||
if x.stat_type == 'delivered' and x.notification_type == 'email':
|
||||
op.execute("update notification_statistics set emails_delivered = {} where id = '{}'".format(x.count, x.id))
|
||||
if x.stat_type == 'failed' and x.notification_type == 'email':
|
||||
op.execute("update notification_statistics set emails_failed = {} where id = '{}'".format(x.count, x.id))
|
||||
if x.stat_type == 'delivered' and x.notification_type == 'sms':
|
||||
op.execute("update notification_statistics set sms_delivered = {} where id = '{}'".format(x.count, x.id))
|
||||
if x.stat_type == 'failed' and x.notification_type == 'sms':
|
||||
op.execute("update notification_statistics set sms_failed = {} where id = '{}'".format(x.count, x.id))
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
### end Alembic commands ###
|
||||
Reference in New Issue
Block a user