Merge branch 'master' into add-template-version

Conflicts:
	tests/app/dao/test_notification_dao.py
This commit is contained in:
Rebecca Law
2016-05-12 09:49:35 +01:00
25 changed files with 718 additions and 190 deletions

View File

@@ -15,7 +15,6 @@ import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('provider_rates',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('valid_from', sa.DateTime(), nullable=False),
@@ -33,12 +32,9 @@ def upgrade():
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_provider_statistics_service_id'), 'provider_statistics', ['service_id'], unique=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_provider_statistics_service_id'), table_name='provider_statistics')
op.drop_table('provider_statistics')
op.drop_table('provider_rates')
### end Alembic commands ###

View File

@@ -0,0 +1,73 @@
"""empty message
Revision ID: 0011_ad_provider_details
Revises: 0010_events_table
Create Date: 2016-05-05 09:14:29.328841
"""
# revision identifiers, used by Alembic.
revision = '0011_ad_provider_details'
down_revision = '0010_events_table'
import uuid
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table('provider_details',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('display_name', sa.String(), nullable=False),
sa.Column('identifier', sa.String(), nullable=False),
sa.Column('priority', sa.Integer(), nullable=False),
sa.Column('notification_type', sa.Enum('email', 'sms', 'letter', name='notification_type'), nullable=False),
sa.Column('active', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.add_column('provider_rates', sa.Column('provider_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_index(op.f('ix_provider_rates_provider_id'), 'provider_rates', ['provider_id'], unique=False)
op.create_foreign_key("provider_rate_to_provider_fk", 'provider_rates', 'provider_details', ['provider_id'], ['id'])
op.add_column('provider_statistics', sa.Column('provider_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_index(op.f('ix_provider_statistics_provider_id'), 'provider_statistics', ['provider_id'], unique=False)
op.create_foreign_key('provider_stats_to_provider_fk', 'provider_statistics', 'provider_details', ['provider_id'], ['id'])
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values ('{}', 'MMG', 'mmg', 10, 'sms', true)".format(str(uuid.uuid4()))
)
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values ('{}', 'Firetext', 'firetext', 20, 'sms', true)".format(str(uuid.uuid4()))
)
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values ('{}', 'AWS SES', 'ses', 10, 'email', true)".format(str(uuid.uuid4()))
)
op.execute(
"UPDATE provider_rates set provider_id = (select id from provider_details where identifier = 'mmg') where provider = 'mmg'"
)
op.execute(
"UPDATE provider_rates set provider_id = (select id from provider_details where identifier = 'firetext') where provider = 'firetext'"
)
op.execute(
"UPDATE provider_rates set provider_id = (select id from provider_details where identifier = 'ses') where provider = 'ses'"
)
op.execute(
"UPDATE provider_statistics set provider_id = (select id from provider_details where identifier = 'mmg') where provider = 'mmg'"
)
op.execute(
"UPDATE provider_statistics set provider_id = (select id from provider_details where identifier = 'firetext') where provider = 'firetext'"
)
op.execute(
"UPDATE provider_statistics set provider_id = (select id from provider_details where identifier = 'ses') where provider = 'ses'"
)
def downgrade():
op.drop_index(op.f('ix_provider_statistics_provider_id'), table_name='provider_statistics')
op.drop_column('provider_statistics', 'provider_id')
op.drop_index(op.f('ix_provider_rates_provider_id'), table_name='provider_rates')
op.drop_column('provider_rates', 'provider_id')
op.drop_table('provider_details')
op.execute('drop type notification_type')

View File

@@ -0,0 +1,80 @@
"""empty message
Revision ID: 0012_complete_provider_details
Revises: 0011_ad_provider_details
Create Date: 2016-05-05 09:18:26.926275
"""
# revision identifiers, used by Alembic.
revision = '0012_complete_provider_details'
down_revision = '0011_ad_provider_details'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import ENUM
def upgrade():
op.alter_column('provider_rates', 'provider_id',
existing_type=postgresql.UUID(),
nullable=False)
op.drop_column('provider_rates', 'provider')
op.alter_column('provider_statistics', 'provider_id',
existing_type=postgresql.UUID(),
nullable=False)
op.drop_column('provider_statistics', 'provider')
op.execute('drop type providers')
def downgrade():
provider_enum = ENUM('loadtesting', 'firetext', 'mmg', 'ses', 'twilio', name='providers', create_type=True)
provider_enum.create(op.get_bind(), checkfirst=False)
op.add_column('provider_statistics', sa.Column('provider', provider_enum, autoincrement=False, nullable=True))
op.alter_column('provider_statistics', 'provider_id',
existing_type=postgresql.UUID(),
nullable=True)
op.add_column('provider_rates', sa.Column('provider', provider_enum, autoincrement=False, nullable=True))
op.alter_column('provider_rates', 'provider_id',
existing_type=postgresql.UUID(),
nullable=True)
op.execute(
"UPDATE provider_rates set provider = 'mmg' where provider_id = (select id from provider_details where identifier = 'mmg')"
)
op.execute(
"UPDATE provider_rates set provider = 'firetext' where provider_id = (select id from provider_details where identifier = 'firetext')"
)
op.execute(
"UPDATE provider_rates set provider = 'ses' where provider_id = (select id from provider_details where identifier = 'ses')"
)
op.execute(
"UPDATE provider_rates set provider = 'loadtesting' where provider_id = (select id from provider_details where identifier = 'loadtesting')"
)
op.execute(
"UPDATE provider_statistics set provider = 'mmg' where provider_id = (select id from provider_details where identifier = 'mmg')"
)
op.execute(
"UPDATE provider_statistics set provider = 'firetext' where provider_id = (select id from provider_details where identifier = 'firetext')"
)
op.execute(
"UPDATE provider_statistics set provider = 'ses' where provider_id = (select id from provider_details where identifier = 'ses')"
)
op.execute(
"UPDATE provider_statistics set provider = 'loadtesting' where provider_id = (select id from provider_details where identifier = 'loadtesting')"
)
op.alter_column('provider_rates', 'provider',
existing_type=postgresql.UUID(),
nullable=False)
op.alter_column('provider_statistics', 'provider',
existing_type=postgresql.UUID(),
nullable=False)