"""empty message

Revision ID: 0083_add_perm_types_and_svc_perm
Revises: 0082_add_go_live_template
Create Date: 2017-05-12 11:29:32.664811

"""

# revision identifiers, used by Alembic.
revision = '0083_add_perm_types_and_svc_perm'
down_revision = '0082_add_go_live_template'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    service_permission_types=op.create_table('service_permission_types',
                                             sa.Column('name', sa.String(length=255), nullable=False),
                                             sa.PrimaryKeyConstraint('name'))

    op.bulk_insert(service_permission_types,
                   [
                       {'name': x} for x in {
                           'letter',
                           'email',
                           'sms',
                           'international_sms',
                           'incoming_sms'
                       }
                   ])

    op.create_table('service_permissions',
                    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('permission', sa.String(length=255), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=False),
                    sa.Column('updated_at', sa.DateTime(), nullable=True),
                    sa.ForeignKeyConstraint(['permission'], ['service_permission_types.name'], ),
                    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
                    sa.PrimaryKeyConstraint('service_id', 'permission'))
    op.create_index(op.f('ix_service_permissions_permission'), 'service_permissions', ['permission'], unique=False)
    op.create_index(op.f('ix_service_permissions_service_id'), 'service_permissions', ['service_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_service_permissions_service_id'), table_name='service_permissions')
    op.drop_index(op.f('ix_service_permissions_permission'), table_name='service_permissions')
    op.drop_table('service_permissions')
    op.drop_table('service_permission_types')
    # ### end Alembic commands ###
