Use the notification types enum for the notifications.notification_type.

Reuse EMAIL_TYPE in template_types and notification_types.
This commit is contained in:
Rebecca Law
2016-06-29 11:50:54 +01:00
parent 60e159e3c0
commit 25db1bce74
6 changed files with 35 additions and 27 deletions

View File

@@ -13,10 +13,11 @@ 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) '
notification_types = sa.Enum('email', 'sms', 'letter', name='notification_type')
op.add_column('notifications', sa.Column('notification_type', notification_types, nullable=True))
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)')
op.alter_column('notifications', 'notification_type', nullable=False)