Migration to create the ft_notification_status table

Added the migration for the `ft_notification_status` table which will be
used to look up the counts for notifications by various different
fields.

The `job_id` column is non-nullable because we want to include it in the
composite primary key. For notifications which weren't part of a job,
the `job_id` will be set to `0000-00000-0000-00000` when populating the
data.
This commit is contained in:
Katie Smith
2018-05-03 16:40:54 +01:00
parent a9bd189a24
commit bb9eb367b7

View File

@@ -0,0 +1,39 @@
"""
Revision ID: 0188_add_ft_notification_status
Revises: 0187_another_letter_org
Create Date: 2018-05-03 10:10:41.824981
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0188_add_ft_notification_status'
down_revision = '0187_another_letter_org'
def upgrade():
op.create_table('ft_notification_status',
sa.Column('bst_date', sa.Date(), nullable=False),
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('notification_type', sa.Text(), nullable=False),
sa.Column('key_type', sa.Text(), nullable=False),
sa.Column('notification_status', sa.Text(), nullable=False),
sa.Column('notification_count', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('bst_date', 'template_id', 'service_id', 'job_id', 'notification_type', 'key_type', 'notification_status')
)
op.create_index(op.f('ix_ft_notification_status_bst_date'), 'ft_notification_status', ['bst_date'], unique=False)
op.create_index(op.f('ix_ft_notification_status_job_id'), 'ft_notification_status', ['job_id'], unique=False)
op.create_index(op.f('ix_ft_notification_status_service_id'), 'ft_notification_status', ['service_id'], unique=False)
op.create_index(op.f('ix_ft_notification_status_template_id'), 'ft_notification_status', ['template_id'], unique=False)
def downgrade():
op.drop_index(op.f('ix_ft_notification_status_bst_date'), table_name='ft_notification_status')
op.drop_index(op.f('ix_ft_notification_status_template_id'), table_name='ft_notification_status')
op.drop_index(op.f('ix_ft_notification_status_service_id'), table_name='ft_notification_status')
op.drop_index(op.f('ix_ft_notification_status_job_id'), table_name='ft_notification_status')
op.drop_table('ft_notification_status')