Merge branch 'main' into notify-300b

This commit is contained in:
stvnrlly
2023-08-31 10:28:44 -04:00
706 changed files with 40498 additions and 30898 deletions

View File

@@ -7,219 +7,385 @@ Create Date: 2016-04-07 17:22:12.147542
"""
# revision identifiers, used by Alembic.
revision = '0001_restart_migrations'
revision = "0001_restart_migrations"
down_revision = None
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('services',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('message_limit', sa.BigInteger(), nullable=False),
sa.Column('restricted', sa.Boolean(), nullable=False),
sa.Column('email_from', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email_from'),
sa.UniqueConstraint('name')
op.create_table(
"services",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("active", sa.Boolean(), nullable=False),
sa.Column("message_limit", sa.BigInteger(), nullable=False),
sa.Column("restricted", sa.Boolean(), nullable=False),
sa.Column("email_from", sa.Text(), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("email_from"),
sa.UniqueConstraint("name"),
)
op.create_table('users',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('email_address', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('_password', sa.String(), nullable=False),
sa.Column('mobile_number', sa.String(), nullable=False),
sa.Column('password_changed_at', sa.DateTime(), nullable=True),
sa.Column('logged_in_at', sa.DateTime(), nullable=True),
sa.Column('failed_login_count', sa.Integer(), nullable=False),
sa.Column('state', sa.String(), nullable=False),
sa.Column('platform_admin', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"users",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("email_address", sa.String(length=255), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("_password", sa.String(), nullable=False),
sa.Column("mobile_number", sa.String(), nullable=False),
sa.Column("password_changed_at", sa.DateTime(), nullable=True),
sa.Column("logged_in_at", sa.DateTime(), nullable=True),
sa.Column("failed_login_count", sa.Integer(), nullable=False),
sa.Column("state", sa.String(), nullable=False),
sa.Column("platform_admin", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_users_email_address'), 'users', ['email_address'], unique=True)
op.create_index(op.f('ix_users_name'), 'users', ['name'], unique=False)
op.create_table('api_keys',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('secret', sa.String(length=255), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('expiry_date', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('secret'),
sa.UniqueConstraint('service_id', 'name', name='uix_service_to_key_name')
op.create_index(
op.f("ix_users_email_address"), "users", ["email_address"], unique=True
)
op.create_index(op.f('ix_api_keys_service_id'), 'api_keys', ['service_id'], unique=False)
op.create_table('invited_users',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('email_address', sa.String(length=255), nullable=False),
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('status', sa.Enum('pending', 'accepted', 'cancelled', name='invited_users_status_types'), nullable=False),
sa.Column('permissions', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_index(op.f("ix_users_name"), "users", ["name"], unique=False)
op.create_table(
"api_keys",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("secret", sa.String(length=255), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("expiry_date", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("secret"),
sa.UniqueConstraint("service_id", "name", name="uix_service_to_key_name"),
)
op.create_index(op.f('ix_invited_users_service_id'), 'invited_users', ['service_id'], unique=False)
op.create_index(op.f('ix_invited_users_user_id'), 'invited_users', ['user_id'], unique=False)
op.create_table('notification_statistics',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('day', sa.String(length=255), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('emails_requested', sa.BigInteger(), nullable=False),
sa.Column('emails_delivered', sa.BigInteger(), nullable=False),
sa.Column('emails_failed', sa.BigInteger(), nullable=False),
sa.Column('sms_requested', sa.BigInteger(), nullable=False),
sa.Column('sms_delivered', sa.BigInteger(), nullable=False),
sa.Column('sms_failed', sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('service_id', 'day', name='uix_service_to_day')
op.create_index(
op.f("ix_api_keys_service_id"), "api_keys", ["service_id"], unique=False
)
op.create_index(op.f('ix_notification_statistics_service_id'), 'notification_statistics', ['service_id'], unique=False)
op.create_table('permissions',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('permission', sa.Enum('manage_users', 'manage_templates', 'manage_settings', 'send_texts', 'send_emails', 'send_letters', 'manage_api_keys', 'platform_admin', 'view_activity', name='permission_types'), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('service_id', 'user_id', 'permission', name='uix_service_user_permission')
op.create_table(
"invited_users",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("email_address", sa.String(length=255), nullable=False),
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column(
"status",
sa.Enum(
"pending", "accepted", "cancelled", name="invited_users_status_types"
),
nullable=False,
),
sa.Column("permissions", sa.String(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_permissions_service_id'), 'permissions', ['service_id'], unique=False)
op.create_index(op.f('ix_permissions_user_id'), 'permissions', ['user_id'], unique=False)
op.create_table('templates',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('template_type', sa.Enum('sms', 'email', 'letter', name='template_type'), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('content', sa.Text(), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('subject', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('subject')
op.create_index(
op.f("ix_invited_users_service_id"),
"invited_users",
["service_id"],
unique=False,
)
op.create_index(op.f('ix_templates_service_id'), 'templates', ['service_id'], unique=False)
op.create_table('user_to_service',
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.UniqueConstraint('user_id', 'service_id', name='uix_user_to_service')
op.create_index(
op.f("ix_invited_users_user_id"), "invited_users", ["user_id"], unique=False
)
op.create_table('verify_codes',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('_code', sa.String(), nullable=False),
sa.Column('code_type', sa.Enum('email', 'sms', name='verify_code_types'), nullable=False),
sa.Column('expiry_datetime', sa.DateTime(), nullable=False),
sa.Column('code_used', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"notification_statistics",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("day", sa.String(length=255), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("emails_requested", sa.BigInteger(), nullable=False),
sa.Column("emails_delivered", sa.BigInteger(), nullable=False),
sa.Column("emails_failed", sa.BigInteger(), nullable=False),
sa.Column("sms_requested", sa.BigInteger(), nullable=False),
sa.Column("sms_delivered", sa.BigInteger(), nullable=False),
sa.Column("sms_failed", sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("service_id", "day", name="uix_service_to_day"),
)
op.create_index(op.f('ix_verify_codes_user_id'), 'verify_codes', ['user_id'], unique=False)
op.create_table('jobs',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('original_file_name', sa.String(), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('status', sa.Enum('pending', 'in progress', 'finished', 'sending limits exceeded', name='job_status_types'), nullable=False),
sa.Column('notification_count', sa.Integer(), nullable=False),
sa.Column('notifications_sent', sa.Integer(), nullable=False),
sa.Column('processing_started', sa.DateTime(), nullable=True),
sa.Column('processing_finished', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_index(
op.f("ix_notification_statistics_service_id"),
"notification_statistics",
["service_id"],
unique=False,
)
op.create_index(op.f('ix_jobs_service_id'), 'jobs', ['service_id'], unique=False)
op.create_index(op.f('ix_jobs_template_id'), 'jobs', ['template_id'], unique=False)
op.create_table('template_statistics',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('usage_count', sa.BigInteger(), nullable=False),
sa.Column('day', sa.Date(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"permissions",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column(
"permission",
sa.Enum(
"manage_users",
"manage_templates",
"manage_settings",
"send_texts",
"send_emails",
"send_letters",
"manage_api_keys",
"platform_admin",
"view_activity",
name="permission_types",
),
nullable=False,
),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint(
"service_id", "user_id", "permission", name="uix_service_user_permission"
),
)
op.create_index(op.f('ix_template_statistics_day'), 'template_statistics', ['day'], unique=False)
op.create_index(op.f('ix_template_statistics_service_id'), 'template_statistics', ['service_id'], unique=False)
op.create_index(op.f('ix_template_statistics_template_id'), 'template_statistics', ['template_id'], unique=False)
op.create_table('notifications',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('to', sa.String(), nullable=False),
sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('sent_at', sa.DateTime(), nullable=True),
sa.Column('sent_by', sa.String(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('status', sa.Enum('sending', 'delivered', 'failed', name='notification_status_types'), nullable=False),
sa.Column('reference', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_index(
op.f("ix_permissions_service_id"), "permissions", ["service_id"], unique=False
)
op.create_index(
op.f("ix_permissions_user_id"), "permissions", ["user_id"], unique=False
)
op.create_table(
"templates",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column(
"template_type",
sa.Enum("sms", "email", "letter", name="template_type"),
nullable=False,
),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("content", sa.Text(), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("subject", sa.Text(), nullable=True),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("subject"),
)
op.create_index(
op.f("ix_templates_service_id"), "templates", ["service_id"], unique=False
)
op.create_table(
"user_to_service",
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.UniqueConstraint("user_id", "service_id", name="uix_user_to_service"),
)
op.create_table(
"verify_codes",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("_code", sa.String(), nullable=False),
sa.Column(
"code_type",
sa.Enum("email", "sms", name="verify_code_types"),
nullable=False,
),
sa.Column("expiry_datetime", sa.DateTime(), nullable=False),
sa.Column("code_used", sa.Boolean(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_verify_codes_user_id"), "verify_codes", ["user_id"], unique=False
)
op.create_table(
"jobs",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("original_file_name", sa.String(), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("template_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column(
"status",
sa.Enum(
"pending",
"in progress",
"finished",
"sending limits exceeded",
name="job_status_types",
),
nullable=False,
),
sa.Column("notification_count", sa.Integer(), nullable=False),
sa.Column("notifications_sent", sa.Integer(), nullable=False),
sa.Column("processing_started", sa.DateTime(), nullable=True),
sa.Column("processing_finished", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["template_id"],
["templates.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_jobs_service_id"), "jobs", ["service_id"], unique=False)
op.create_index(op.f("ix_jobs_template_id"), "jobs", ["template_id"], unique=False)
op.create_table(
"template_statistics",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("template_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("usage_count", sa.BigInteger(), nullable=False),
sa.Column("day", sa.Date(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["template_id"],
["templates.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_template_statistics_day"), "template_statistics", ["day"], unique=False
)
op.create_index(
op.f("ix_template_statistics_service_id"),
"template_statistics",
["service_id"],
unique=False,
)
op.create_index(
op.f("ix_template_statistics_template_id"),
"template_statistics",
["template_id"],
unique=False,
)
op.create_table(
"notifications",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("to", sa.String(), nullable=False),
sa.Column("job_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("template_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("sent_at", sa.DateTime(), nullable=True),
sa.Column("sent_by", sa.String(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column(
"status",
sa.Enum("sending", "delivered", "failed", name="notification_status_types"),
nullable=False,
),
sa.Column("reference", sa.String(), nullable=True),
sa.ForeignKeyConstraint(
["job_id"],
["jobs.id"],
),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["template_id"],
["templates.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_notifications_job_id"), "notifications", ["job_id"], unique=False
)
op.create_index(
op.f("ix_notifications_reference"), "notifications", ["reference"], unique=False
)
op.create_index(
op.f("ix_notifications_service_id"),
"notifications",
["service_id"],
unique=False,
)
op.create_index(
op.f("ix_notifications_template_id"),
"notifications",
["template_id"],
unique=False,
)
op.create_index(op.f('ix_notifications_job_id'), 'notifications', ['job_id'], unique=False)
op.create_index(op.f('ix_notifications_reference'), 'notifications', ['reference'], unique=False)
op.create_index(op.f('ix_notifications_service_id'), 'notifications', ['service_id'], unique=False)
op.create_index(op.f('ix_notifications_template_id'), 'notifications', ['template_id'], unique=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_notifications_template_id'), table_name='notifications')
op.drop_index(op.f('ix_notifications_service_id'), table_name='notifications')
op.drop_index(op.f('ix_notifications_reference'), table_name='notifications')
op.drop_index(op.f('ix_notifications_job_id'), table_name='notifications')
op.drop_table('notifications')
op.drop_index(op.f('ix_template_statistics_template_id'), table_name='template_statistics')
op.drop_index(op.f('ix_template_statistics_service_id'), table_name='template_statistics')
op.drop_index(op.f('ix_template_statistics_day'), table_name='template_statistics')
op.drop_table('template_statistics')
op.drop_index(op.f('ix_jobs_template_id'), table_name='jobs')
op.drop_index(op.f('ix_jobs_service_id'), table_name='jobs')
op.drop_table('jobs')
op.drop_index(op.f('ix_verify_codes_user_id'), table_name='verify_codes')
op.drop_table('verify_codes')
op.drop_table('user_to_service')
op.drop_index(op.f('ix_templates_service_id'), table_name='templates')
op.drop_table('templates')
op.drop_index(op.f('ix_permissions_user_id'), table_name='permissions')
op.drop_index(op.f('ix_permissions_service_id'), table_name='permissions')
op.drop_table('permissions')
op.drop_index(op.f('ix_notification_statistics_service_id'), table_name='notification_statistics')
op.drop_table('notification_statistics')
op.drop_index(op.f('ix_invited_users_user_id'), table_name='invited_users')
op.drop_index(op.f('ix_invited_users_service_id'), table_name='invited_users')
op.drop_table('invited_users')
op.drop_index(op.f('ix_api_keys_service_id'), table_name='api_keys')
op.drop_table('api_keys')
op.drop_index(op.f('ix_users_name'), table_name='users')
op.drop_index(op.f('ix_users_email_address'), table_name='users')
op.drop_table('users')
op.drop_table('services')
op.drop_index(op.f("ix_notifications_template_id"), table_name="notifications")
op.drop_index(op.f("ix_notifications_service_id"), table_name="notifications")
op.drop_index(op.f("ix_notifications_reference"), table_name="notifications")
op.drop_index(op.f("ix_notifications_job_id"), table_name="notifications")
op.drop_table("notifications")
op.drop_index(
op.f("ix_template_statistics_template_id"), table_name="template_statistics"
)
op.drop_index(
op.f("ix_template_statistics_service_id"), table_name="template_statistics"
)
op.drop_index(op.f("ix_template_statistics_day"), table_name="template_statistics")
op.drop_table("template_statistics")
op.drop_index(op.f("ix_jobs_template_id"), table_name="jobs")
op.drop_index(op.f("ix_jobs_service_id"), table_name="jobs")
op.drop_table("jobs")
op.drop_index(op.f("ix_verify_codes_user_id"), table_name="verify_codes")
op.drop_table("verify_codes")
op.drop_table("user_to_service")
op.drop_index(op.f("ix_templates_service_id"), table_name="templates")
op.drop_table("templates")
op.drop_index(op.f("ix_permissions_user_id"), table_name="permissions")
op.drop_index(op.f("ix_permissions_service_id"), table_name="permissions")
op.drop_table("permissions")
op.drop_index(
op.f("ix_notification_statistics_service_id"),
table_name="notification_statistics",
)
op.drop_table("notification_statistics")
op.drop_index(op.f("ix_invited_users_user_id"), table_name="invited_users")
op.drop_index(op.f("ix_invited_users_service_id"), table_name="invited_users")
op.drop_table("invited_users")
op.drop_index(op.f("ix_api_keys_service_id"), table_name="api_keys")
op.drop_table("api_keys")
op.drop_index(op.f("ix_users_name"), table_name="users")
op.drop_index(op.f("ix_users_email_address"), table_name="users")
op.drop_table("users")
op.drop_table("services")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-04-15 12:12:46.383782
"""
# revision identifiers, used by Alembic.
revision = '0002_add_content_char_count'
down_revision = '0001_restart_migrations'
revision = "0002_add_content_char_count"
down_revision = "0001_restart_migrations"
from alembic import op
import sqlalchemy as sa
@@ -17,11 +17,13 @@ from sqlalchemy.sql import table, column
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('notifications', sa.Column('content_char_count', sa.Integer(), nullable=True))
op.add_column(
"notifications", sa.Column("content_char_count", sa.Integer(), nullable=True)
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('notifications', 'content_char_count')
op.drop_column("notifications", "content_char_count")
### end Alembic commands ###

View File

@@ -7,50 +7,68 @@ Create Date: 2016-04-19 13:01:54.519821
"""
# revision identifiers, used by Alembic.
revision = '0003_add_service_history'
down_revision = '0002_add_content_char_count'
revision = "0003_add_service_history"
down_revision = "0002_add_content_char_count"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('services_history',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('message_limit', sa.BigInteger(), nullable=False),
sa.Column('restricted', sa.Boolean(), nullable=False),
sa.Column('email_from', sa.Text(), nullable=False),
sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', 'version')
op.create_table(
"services_history",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("active", sa.Boolean(), nullable=False),
sa.Column("message_limit", sa.BigInteger(), nullable=False),
sa.Column("restricted", sa.Boolean(), nullable=False),
sa.Column("email_from", sa.Text(), nullable=False),
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("version", sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint("id", "version"),
)
op.create_index(
op.f("ix_services_history_created_by_id"),
"services_history",
["created_by_id"],
unique=False,
)
op.add_column(
"services",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.add_column("services", sa.Column("version", sa.Integer(), nullable=True))
op.create_index(
op.f("ix_services_created_by_id"), "services", ["created_by_id"], unique=False
)
op.create_foreign_key(
"fk_services_created_by_id", "services", "users", ["created_by_id"], ["id"]
)
op.create_index(op.f('ix_services_history_created_by_id'), 'services_history', ['created_by_id'], unique=False)
op.add_column('services', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column('services', sa.Column('version', sa.Integer(), nullable=True))
op.create_index(op.f('ix_services_created_by_id'), 'services', ['created_by_id'], unique=False)
op.create_foreign_key('fk_services_created_by_id', 'services', 'users', ['created_by_id'], ['id'])
op.get_bind()
op.execute('UPDATE services SET created_by_id = (SELECT user_id FROM user_to_service WHERE services.id = user_to_service.service_id LIMIT 1)')
op.execute('UPDATE services SET version = 1')
op.execute('INSERT INTO services_history SELECT * FROM services')
op.execute(
"UPDATE services SET created_by_id = (SELECT user_id FROM user_to_service WHERE services.id = user_to_service.service_id LIMIT 1)"
)
op.execute("UPDATE services SET version = 1")
op.execute("INSERT INTO services_history SELECT * FROM services")
op.alter_column('services', 'created_by_id', nullable=False)
op.alter_column('services', 'version', nullable=False)
op.alter_column("services", "created_by_id", nullable=False)
op.alter_column("services", "version", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('fk_services_created_by_id', 'services', type_='foreignkey')
op.drop_index(op.f('ix_services_created_by_id'), table_name='services')
op.drop_column('services', 'version')
op.drop_column('services', 'created_by_id')
op.drop_index(op.f('ix_services_history_created_by_id'), table_name='services_history')
op.drop_table('services_history')
op.drop_constraint("fk_services_created_by_id", "services", type_="foreignkey")
op.drop_index(op.f("ix_services_created_by_id"), table_name="services")
op.drop_column("services", "version")
op.drop_column("services", "created_by_id")
op.drop_index(
op.f("ix_services_history_created_by_id"), table_name="services_history"
)
op.drop_table("services_history")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-04-20 13:59:01.132535
"""
# revision identifiers, used by Alembic.
revision = '0004_notification_stats_date'
down_revision = '0003_add_service_history'
revision = "0004_notification_stats_date"
down_revision = "0003_add_service_history"
from alembic import op
import sqlalchemy as sa
@@ -16,34 +16,51 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('uix_service_to_day', 'notification_statistics')
op.alter_column('notification_statistics', 'day', new_column_name='day_string')
op.add_column('notification_statistics', sa.Column('day', sa.Date(), nullable=True))
op.drop_constraint("uix_service_to_day", "notification_statistics")
op.alter_column("notification_statistics", "day", new_column_name="day_string")
op.add_column("notification_statistics", sa.Column("day", sa.Date(), nullable=True))
op.get_bind()
op.execute("UPDATE notification_statistics ns1 SET day = (SELECT to_date(day_string, 'YYYY-MM-DD') FROM notification_statistics ns2 WHERE ns1.id = ns2.id)")
op.execute(
"UPDATE notification_statistics ns1 SET day = (SELECT to_date(day_string, 'YYYY-MM-DD') FROM notification_statistics ns2 WHERE ns1.id = ns2.id)"
)
op.alter_column('notification_statistics', 'day', nullable=False)
op.create_index(op.f('ix_notification_statistics_day'), 'notification_statistics', ['day'], unique=False)
op.drop_column('notification_statistics', 'day_string')
op.create_unique_constraint('uix_service_to_day', 'notification_statistics', columns=['service_id', 'day'])
op.alter_column("notification_statistics", "day", nullable=False)
op.create_index(
op.f("ix_notification_statistics_day"),
"notification_statistics",
["day"],
unique=False,
)
op.drop_column("notification_statistics", "day_string")
op.create_unique_constraint(
"uix_service_to_day", "notification_statistics", columns=["service_id", "day"]
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_notification_statistics_day'), table_name='notification_statistics')
op.drop_constraint('uix_service_to_day', 'notification_statistics')
op.drop_index(
op.f("ix_notification_statistics_day"), table_name="notification_statistics"
)
op.drop_constraint("uix_service_to_day", "notification_statistics")
op.alter_column('notification_statistics', 'day', new_column_name='day_date')
op.add_column('notification_statistics', sa.Column('day', sa.String(), nullable=True))
op.alter_column("notification_statistics", "day", new_column_name="day_date")
op.add_column(
"notification_statistics", sa.Column("day", sa.String(), nullable=True)
)
op.get_bind()
op.execute("UPDATE notification_statistics ns1 SET day = (SELECT to_char(day_date, 'YYYY-MM-DD') FROM notification_statistics ns2 WHERE ns1.id = ns2.id)")
op.execute(
"UPDATE notification_statistics ns1 SET day = (SELECT to_char(day_date, 'YYYY-MM-DD') FROM notification_statistics ns2 WHERE ns1.id = ns2.id)"
)
op.alter_column('notification_statistics', 'day', nullable=False)
op.drop_column('notification_statistics', 'day_date')
op.create_unique_constraint('uix_service_to_day', 'notification_statistics', columns=['service_id', 'day'])
op.alter_column("notification_statistics", "day", nullable=False)
op.drop_column("notification_statistics", "day_date")
op.create_unique_constraint(
"uix_service_to_day", "notification_statistics", columns=["service_id", "day"]
)
### end Alembic commands ###

View File

@@ -7,34 +7,38 @@ Create Date: 2016-04-20 15:13:42.229197
"""
# revision identifiers, used by Alembic.
revision = '0005_add_provider_stats'
down_revision = '0004_notification_stats_date'
revision = "0005_add_provider_stats"
down_revision = "0004_notification_stats_date"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table('provider_rates',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('valid_from', sa.DateTime(), nullable=False),
sa.Column('provider', sa.Enum('mmg', 'twilio', 'firetext', 'ses', 'sns', name='providers'), nullable=False),
sa.Column('rate', sa.Numeric(), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"provider_statistics",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("day", sa.Date(), nullable=False),
sa.Column("provider", sa.Enum("ses", "sns", name="providers"), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("unit_count", sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table('provider_statistics',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('day', sa.Date(), nullable=False),
sa.Column('provider', sa.Enum('mmg', 'twilio', 'firetext', 'ses', 'sns', name='providers'), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('unit_count', sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_index(
op.f("ix_provider_statistics_service_id"),
"provider_statistics",
["service_id"],
unique=False,
)
op.create_index(op.f('ix_provider_statistics_service_id'), 'provider_statistics', ['service_id'], unique=False)
def downgrade():
op.drop_index(op.f('ix_provider_statistics_service_id'), table_name='provider_statistics')
op.drop_table('provider_statistics')
op.drop_table('provider_rates')
op.drop_index(
op.f("ix_provider_statistics_service_id"), table_name="provider_statistics"
)
op.drop_table("provider_statistics")

View File

@@ -7,58 +7,83 @@ Create Date: 2016-04-20 17:21:38.541766
"""
# revision identifiers, used by Alembic.
revision = '0006_api_keys_history'
down_revision = '0005_add_provider_stats'
revision = "0006_api_keys_history"
down_revision = "0005_add_provider_stats"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('api_keys_history',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('secret', sa.String(length=255), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('expiry_date', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', 'version')
op.create_table(
"api_keys_history",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("secret", sa.String(length=255), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("expiry_date", sa.DateTime(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("version", sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint("id", "version"),
)
op.create_index(op.f('ix_api_keys_history_created_by_id'), 'api_keys_history', ['created_by_id'], unique=False)
op.create_index(op.f('ix_api_keys_history_service_id'), 'api_keys_history', ['service_id'], unique=False)
op.add_column('api_keys', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('api_keys', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column('api_keys', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('api_keys', sa.Column('version', sa.Integer(), nullable=True))
op.create_index(
op.f("ix_api_keys_history_created_by_id"),
"api_keys_history",
["created_by_id"],
unique=False,
)
op.create_index(
op.f("ix_api_keys_history_service_id"),
"api_keys_history",
["service_id"],
unique=False,
)
op.add_column("api_keys", sa.Column("created_at", sa.DateTime(), nullable=True))
op.add_column(
"api_keys",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.add_column("api_keys", sa.Column("updated_at", sa.DateTime(), nullable=True))
op.add_column("api_keys", sa.Column("version", sa.Integer(), nullable=True))
op.get_bind()
op.execute('UPDATE api_keys SET created_by_id = (SELECT user_id FROM user_to_service WHERE api_keys.service_id = user_to_service.service_id LIMIT 1)')
op.execute('UPDATE api_keys SET version = 1, created_at = now()')
op.execute('INSERT INTO api_keys_history (id, name, secret, service_id, expiry_date, created_at, updated_at, created_by_id, version) SELECT id, name, secret, service_id, expiry_date, created_at, updated_at, created_by_id, version FROM api_keys')
op.execute(
"UPDATE api_keys SET created_by_id = (SELECT user_id FROM user_to_service WHERE api_keys.service_id = user_to_service.service_id LIMIT 1)"
)
op.execute("UPDATE api_keys SET version = 1, created_at = now()")
op.execute(
"INSERT INTO api_keys_history (id, name, secret, service_id, expiry_date, created_at, updated_at, created_by_id, version) SELECT id, name, secret, service_id, expiry_date, created_at, updated_at, created_by_id, version FROM api_keys"
)
op.alter_column('api_keys', 'created_at', nullable=False)
op.alter_column('api_keys', 'created_by_id', nullable=False)
op.alter_column('api_keys', 'version', nullable=False)
op.alter_column("api_keys", "created_at", nullable=False)
op.alter_column("api_keys", "created_by_id", nullable=False)
op.alter_column("api_keys", "version", nullable=False)
op.create_index(op.f('ix_api_keys_created_by_id'), 'api_keys', ['created_by_id'], unique=False)
op.create_foreign_key('fk_api_keys_created_by_id', 'api_keys', 'users', ['created_by_id'], ['id'])
op.create_index(
op.f("ix_api_keys_created_by_id"), "api_keys", ["created_by_id"], unique=False
)
op.create_foreign_key(
"fk_api_keys_created_by_id", "api_keys", "users", ["created_by_id"], ["id"]
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('fk_api_keys_created_by_id', 'api_keys', type_='foreignkey')
op.drop_index(op.f('ix_api_keys_created_by_id'), table_name='api_keys')
op.drop_column('api_keys', 'version')
op.drop_column('api_keys', 'updated_at')
op.drop_column('api_keys', 'created_by_id')
op.drop_column('api_keys', 'created_at')
op.drop_index(op.f('ix_api_keys_history_service_id'), table_name='api_keys_history')
op.drop_index(op.f('ix_api_keys_history_created_by_id'), table_name='api_keys_history')
op.drop_table('api_keys_history')
op.drop_constraint("fk_api_keys_created_by_id", "api_keys", type_="foreignkey")
op.drop_index(op.f("ix_api_keys_created_by_id"), table_name="api_keys")
op.drop_column("api_keys", "version")
op.drop_column("api_keys", "updated_at")
op.drop_column("api_keys", "created_by_id")
op.drop_column("api_keys", "created_at")
op.drop_index(op.f("ix_api_keys_history_service_id"), table_name="api_keys_history")
op.drop_index(
op.f("ix_api_keys_history_created_by_id"), table_name="api_keys_history"
)
op.drop_table("api_keys_history")
### end Alembic commands ###

View File

@@ -7,64 +7,96 @@ Create Date: 2016-04-22 09:51:55.615891
"""
# revision identifiers, used by Alembic.
revision = '0007_template_history'
down_revision = '0006_api_keys_history'
revision = "0007_template_history"
down_revision = "0006_api_keys_history"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('templates_history',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('template_type', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('content', sa.Text(), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('subject', sa.Text(), nullable=True),
sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', 'version')
op.create_table(
"templates_history",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("template_type", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("content", sa.Text(), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("subject", sa.Text(), nullable=True),
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("version", sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint("id", "version"),
)
op.create_index(op.f('ix_templates_history_created_by_id'), 'templates_history', ['created_by_id'], unique=False)
op.create_index(op.f('ix_templates_history_service_id'), 'templates_history', ['service_id'], unique=False)
op.add_column('templates', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column('templates', sa.Column('version', sa.Integer(), nullable=True))
op.create_index(
op.f("ix_templates_history_created_by_id"),
"templates_history",
["created_by_id"],
unique=False,
)
op.create_index(
op.f("ix_templates_history_service_id"),
"templates_history",
["service_id"],
unique=False,
)
op.add_column(
"templates",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.add_column("templates", sa.Column("version", sa.Integer(), nullable=True))
op.get_bind()
op.execute('UPDATE templates SET created_by_id = (SELECT user_id FROM user_to_service WHERE templates.service_id = user_to_service.service_id LIMIT 1)')
op.execute('UPDATE templates SET version = 1, created_at = now()')
op.execute((
'INSERT INTO templates_history (id, name, template_type, created_at, updated_at, content, service_id, subject, version)'
' SELECT id, name, template_type, created_at, updated_at, content, service_id, subject, version FROM templates'))
op.execute(
"UPDATE templates SET created_by_id = (SELECT user_id FROM user_to_service WHERE templates.service_id = user_to_service.service_id LIMIT 1)"
)
op.execute("UPDATE templates SET version = 1, created_at = now()")
op.execute(
(
"INSERT INTO templates_history (id, name, template_type, created_at, updated_at, content, service_id, subject, version)"
" SELECT id, name, template_type, created_at, updated_at, content, service_id, subject, version FROM templates"
)
)
op.alter_column("templates", "created_at", nullable=False)
op.alter_column("templates", "created_by_id", nullable=False)
op.alter_column("templates", "version", nullable=False)
op.alter_column('templates', 'created_at', nullable=False)
op.alter_column('templates', 'created_by_id', nullable=False)
op.alter_column('templates', 'version', nullable=False)
op.create_index(op.f('ix_templates_created_by_id'), 'templates', ['created_by_id'], unique=False)
op.create_foreign_key("fk_templates_created_by_id", 'templates', 'users', ['created_by_id'], ['id'])
op.create_index(
op.f("ix_templates_created_by_id"), "templates", ["created_by_id"], unique=False
)
op.create_foreign_key(
"fk_templates_created_by_id", "templates", "users", ["created_by_id"], ["id"]
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("fk_templates_created_by_id", 'templates', type_='foreignkey')
op.drop_index(op.f('ix_templates_created_by_id'), table_name='templates')
op.drop_column('templates', 'version')
op.drop_column('templates', 'created_by_id')
op.alter_column('api_keys_history', 'created_by_id',
existing_type=postgresql.UUID(),
nullable=True)
op.alter_column('api_keys_history', 'created_at',
existing_type=postgresql.TIMESTAMP(),
nullable=True)
op.drop_index(op.f('ix_templates_history_service_id'), table_name='templates_history')
op.drop_index(op.f('ix_templates_history_created_by_id'), table_name='templates_history')
op.drop_table('templates_history')
op.drop_constraint("fk_templates_created_by_id", "templates", type_="foreignkey")
op.drop_index(op.f("ix_templates_created_by_id"), table_name="templates")
op.drop_column("templates", "version")
op.drop_column("templates", "created_by_id")
op.alter_column(
"api_keys_history",
"created_by_id",
existing_type=postgresql.UUID(),
nullable=True,
)
op.alter_column(
"api_keys_history",
"created_at",
existing_type=postgresql.TIMESTAMP(),
nullable=True,
)
op.drop_index(
op.f("ix_templates_history_service_id"), table_name="templates_history"
)
op.drop_index(
op.f("ix_templates_history_created_by_id"), table_name="templates_history"
)
op.drop_table("templates_history")
### end Alembic commands ###

View File

@@ -7,27 +7,30 @@ Create Date: 2016-04-25 14:16:49.787229
"""
# revision identifiers, used by Alembic.
revision = '0008_archive_template'
down_revision = '0007_template_history'
revision = "0008_archive_template"
down_revision = "0007_template_history"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('templates', sa.Column('archived', sa.Boolean(), nullable=True))
op.add_column('templates_history', sa.Column('archived', sa.Boolean(), nullable=True))
op.add_column("templates", sa.Column("archived", sa.Boolean(), nullable=True))
op.add_column(
"templates_history", sa.Column("archived", sa.Boolean(), nullable=True)
)
op.get_bind()
op.execute('UPDATE templates SET archived = FALSE')
op.execute('UPDATE templates_history set archived = FALSE')
op.alter_column('templates', 'archived', nullable=False)
op.alter_column('templates', 'archived', nullable=False)
op.execute("UPDATE templates SET archived = FALSE")
op.execute("UPDATE templates_history set archived = FALSE")
op.alter_column("templates", "archived", nullable=False)
op.alter_column("templates", "archived", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('templates_history', 'archived')
op.drop_column('templates', 'archived')
op.drop_column("templates_history", "archived")
op.drop_column("templates", "archived")
### end Alembic commands ###

View File

@@ -7,28 +7,35 @@ Create Date: 2016-04-26 14:54:56.852642
"""
# revision identifiers, used by Alembic.
revision = '0009_created_by_for_jobs'
down_revision = '0008_archive_template'
revision = "0009_created_by_for_jobs"
down_revision = "0008_archive_template"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('jobs', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_index(op.f('ix_jobs_created_by_id'), 'jobs', ['created_by_id'], unique=False)
op.create_foreign_key(None, 'jobs', 'users', ['created_by_id'], ['id'])
op.add_column(
"jobs", sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True)
)
op.create_index(
op.f("ix_jobs_created_by_id"), "jobs", ["created_by_id"], unique=False
)
op.create_foreign_key(None, "jobs", "users", ["created_by_id"], ["id"])
op.get_bind()
op.execute('UPDATE jobs SET created_by_id = \
(SELECT user_id FROM user_to_service WHERE jobs.service_id = user_to_service.service_id LIMIT 1)')
op.alter_column('jobs', 'created_by_id', nullable=False)
op.execute(
"UPDATE jobs SET created_by_id = \
(SELECT user_id FROM user_to_service WHERE jobs.service_id = user_to_service.service_id LIMIT 1)"
)
op.alter_column("jobs", "created_by_id", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'jobs', type_='foreignkey')
op.drop_index(op.f('ix_jobs_created_by_id'), table_name='jobs')
op.drop_column('jobs', 'created_by_id')
op.drop_constraint(None, "jobs", type_="foreignkey")
op.drop_index(op.f("ix_jobs_created_by_id"), table_name="jobs")
op.drop_column("jobs", "created_by_id")
### end Alembic commands ###

View File

@@ -7,26 +7,28 @@ Create Date: 2016-04-26 13:08:42.892813
"""
# revision identifiers, used by Alembic.
revision = '0010_events_table'
down_revision = '0009_created_by_for_jobs'
revision = "0010_events_table"
down_revision = "0009_created_by_for_jobs"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('events',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('event_type', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('data', postgresql.JSON(), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"events",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("event_type", sa.String(length=255), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("data", postgresql.JSON(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('events')
op.drop_table("events")
### end Alembic commands ###

View File

@@ -7,8 +7,10 @@ Create Date: 2016-05-05 09:14:29.328841
"""
# revision identifiers, used by Alembic.
revision = '0011_ad_provider_details'
down_revision = '0010_events_table'
from sqlalchemy import text
revision = "0011_ad_provider_details"
down_revision = "0010_events_table"
import uuid
@@ -16,53 +18,56 @@ 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.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.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()))
conn = op.get_bind()
input_params = {"id": uuid.uuid4()}
conn.execute(
text(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values (:id, 'AWS SES', 'ses', 10, 'email', true)"
),
input_params,
)
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(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values ('{}', 'AWS SNS', 'sns', 10, 'sms', 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_rates set provider_id = (select id from provider_details where identifier = 'sns') where provider = 'sns'"
)
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'"
input_params = {"id": uuid.uuid4()}
conn.execute(
text(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values (:id, 'AWS SNS', 'sns', 10, 'sms', true)"
),
input_params,
)
op.execute(
"UPDATE provider_statistics set provider_id = (select id from provider_details where identifier = 'ses') where provider = 'ses'"
@@ -71,12 +76,11 @@ def upgrade():
"UPDATE provider_statistics set provider_id = (select id from provider_details where identifier = 'sns') where provider = 'sns'"
)
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')
op.drop_index(
op.f("ix_provider_statistics_provider_id"), table_name="provider_statistics"
)
op.drop_column("provider_statistics", "provider_id")
op.drop_table("provider_details")
op.execute("drop type notification_type")

View File

@@ -7,8 +7,8 @@ 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'
revision = "0012_complete_provider_details"
down_revision = "0011_ad_provider_details"
from alembic import op
import sqlalchemy as sa
@@ -17,52 +17,31 @@ 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')
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 = ENUM("loadtesting", "ses", 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.add_column(
"provider_statistics",
sa.Column("provider", provider_enum, autoincrement=False, nullable=True),
)
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.alter_column(
"provider_statistics",
"provider_id",
existing_type=postgresql.UUID(),
nullable=True,
)
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')"
)
@@ -70,11 +49,9 @@ def downgrade():
"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)
op.alter_column(
"provider_statistics",
"provider",
existing_type=postgresql.UUID(),
nullable=False,
)

View File

@@ -1,27 +0,0 @@
"""empty message
Revision ID: 0013_add_loadtest_client
Revises: 0012_complete_provider_details
Create Date: 2016-05-05 09:14:29.328841
"""
# revision identifiers, used by Alembic.
revision = '0013_add_loadtest_client'
down_revision = '0012_complete_provider_details'
import uuid
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values ('{}', 'Loadtesting', 'loadtesting', 30, 'sms', true)".format(str(uuid.uuid4()))
)
def downgrade():
op.drop_table('provider_details')

View File

@@ -1,37 +1,46 @@
"""empty message
Revision ID: 0014_add_template_version
Revises: 0013_add_loadtest_client
Revises: 0012_complete_provider_details
Create Date: 2016-05-11 16:00:51.478012
"""
# revision identifiers, used by Alembic.
revision = '0014_add_template_version'
down_revision = '0013_add_loadtest_client'
revision = "0014_add_template_version"
down_revision = "0012_complete_provider_details"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.add_column('jobs', sa.Column('template_version', sa.Integer(), nullable=True))
op.add_column("jobs", sa.Column("template_version", sa.Integer(), nullable=True))
op.get_bind()
op.execute('update jobs set template_version = (select version from templates where id = template_id)')
op.add_column('notifications', sa.Column('template_version', sa.Integer(), nullable=True))
op.execute('update notifications set template_version = (select version from templates where id = template_id)')
op.alter_column('jobs', 'template_version', nullable=False)
op.alter_column('notifications', 'template_version', nullable=False)
op.execute(
"update jobs set template_version = (select version from templates where id = template_id)"
)
op.add_column(
"notifications", sa.Column("template_version", sa.Integer(), nullable=True)
)
op.execute(
"update notifications set template_version = (select version from templates where id = template_id)"
)
op.alter_column("jobs", "template_version", nullable=False)
op.alter_column("notifications", "template_version", nullable=False)
# fix template_history where created_by_id is not set.
query = "update templates_history set created_by_id = " \
" (select created_by_id from templates " \
" where templates.id = templates_history.id " \
" and templates.version = templates_history.version) " \
"where templates_history.created_by_id is null"
query = (
"update templates_history set created_by_id = "
" (select created_by_id from templates "
" where templates.id = templates_history.id "
" and templates.version = templates_history.version) "
"where templates_history.created_by_id is null"
)
op.execute(query)
def downgrade():
op.drop_column('notifications', 'template_version')
op.drop_column('jobs', 'template_version')
op.drop_column("notifications", "template_version")
op.drop_column("jobs", "template_version")

View File

@@ -7,48 +7,69 @@ Create Date: 2016-05-16 13:55:27.179748
"""
# revision identifiers, used by Alembic.
revision = '0015_fix_template_data'
down_revision = '0014_add_template_version'
revision = "0015_fix_template_data"
down_revision = "0014_add_template_version"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.get_bind()
query = 'update templates_history set created_by_id = ' \
'(select created_by_id from templates where templates.id = templates_history.id) ' \
'where created_by_id is null'
query = (
"update templates_history set created_by_id = "
"(select created_by_id from templates where templates.id = templates_history.id) "
"where created_by_id is null"
)
op.execute(query)
op.execute('update templates_history set archived = False')
op.alter_column('api_keys_history', 'created_at',
existing_type=postgresql.TIMESTAMP(),
nullable=False)
op.alter_column('api_keys_history', 'created_by_id',
existing_type=postgresql.UUID(),
nullable=False)
op.alter_column('templates_history', 'archived',
existing_type=sa.BOOLEAN(),
nullable=False)
op.alter_column('templates_history', 'created_by_id',
existing_type=postgresql.UUID(),
nullable=False)
op.execute("update templates_history set archived = False")
op.alter_column(
"api_keys_history",
"created_at",
existing_type=postgresql.TIMESTAMP(),
nullable=False,
)
op.alter_column(
"api_keys_history",
"created_by_id",
existing_type=postgresql.UUID(),
nullable=False,
)
op.alter_column(
"templates_history", "archived", existing_type=sa.BOOLEAN(), nullable=False
)
op.alter_column(
"templates_history",
"created_by_id",
existing_type=postgresql.UUID(),
nullable=False,
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('templates_history', 'created_by_id',
existing_type=postgresql.UUID(),
nullable=True)
op.alter_column('templates_history', 'archived',
existing_type=sa.BOOLEAN(),
nullable=True)
op.alter_column('api_keys_history', 'created_by_id',
existing_type=postgresql.UUID(),
nullable=True)
op.alter_column('api_keys_history', 'created_at',
existing_type=postgresql.TIMESTAMP(),
nullable=True)
op.alter_column(
"templates_history",
"created_by_id",
existing_type=postgresql.UUID(),
nullable=True,
)
op.alter_column(
"templates_history", "archived", existing_type=sa.BOOLEAN(), nullable=True
)
op.alter_column(
"api_keys_history",
"created_by_id",
existing_type=postgresql.UUID(),
nullable=True,
)
op.alter_column(
"api_keys_history",
"created_at",
existing_type=postgresql.TIMESTAMP(),
nullable=True,
)
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-05-17 09:59:49.032865
"""
# revision identifiers, used by Alembic.
revision = '0016_reply_to_email'
down_revision = '0015_fix_template_data'
revision = "0016_reply_to_email"
down_revision = "0015_fix_template_data"
from alembic import op
import sqlalchemy as sa
@@ -16,13 +16,18 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('reply_to_email_address', sa.Text(), nullable=True))
op.add_column('services_history', sa.Column('reply_to_email_address', sa.Text(), nullable=True))
op.add_column(
"services", sa.Column("reply_to_email_address", sa.Text(), nullable=True)
)
op.add_column(
"services_history",
sa.Column("reply_to_email_address", sa.Text(), nullable=True),
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('services_history', 'reply_to_email_address')
op.drop_column('services', 'reply_to_email_address')
op.drop_column("services_history", "reply_to_email_address")
op.drop_column("services", "reply_to_email_address")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-05-17 11:23:36.881219
"""
# revision identifiers, used by Alembic.
revision = '0017_add_failure_types'
down_revision = '0016_reply_to_email'
revision = "0017_add_failure_types"
down_revision = "0016_reply_to_email"
from alembic import op
import sqlalchemy as sa
@@ -18,32 +18,46 @@ from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
status_type = sa.Enum('sending', 'delivered', 'failed',
'technical-failure', 'temporary-failure', 'permanent-failure',
name='notification_status_type')
status_type = sa.Enum(
"sending",
"delivered",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
name="notification_status_type",
)
status_type.create(op.get_bind())
op.add_column('notifications', sa.Column('new_status', status_type, nullable=True))
op.execute('update notifications set new_status = CAST(CAST(status as text) as notification_status_type)')
op.alter_column('notifications', 'status', new_column_name='old_status')
op.alter_column('notifications', 'new_status', new_column_name='status')
op.drop_column('notifications', 'old_status')
op.add_column("notifications", sa.Column("new_status", status_type, nullable=True))
op.execute(
"update notifications set new_status = CAST(CAST(status as text) as notification_status_type)"
)
op.alter_column("notifications", "status", new_column_name="old_status")
op.alter_column("notifications", "new_status", new_column_name="status")
op.drop_column("notifications", "old_status")
op.get_bind()
op.execute('DROP TYPE notification_status_types')
op.alter_column('notifications', 'status', nullable=False)
op.execute("DROP TYPE notification_status_types")
op.alter_column("notifications", "status", nullable=False)
def downgrade():
status_type = sa.Enum('sending', 'delivered', 'failed',
name='notification_status_types')
status_type = sa.Enum(
"sending", "delivered", "failed", name="notification_status_types"
)
status_type.create(op.get_bind())
op.add_column('notifications', sa.Column('old_status', status_type, nullable=True))
op.add_column("notifications", sa.Column("old_status", status_type, nullable=True))
op.execute("update notifications set status = 'failed' where status in ('technical-failure', 'temporary-failure', 'permanent-failure')")
op.execute('update notifications set old_status = CAST(CAST(status as text) as notification_status_types)')
op.alter_column('notifications', 'status', new_column_name='new_status')
op.alter_column('notifications', 'old_status', new_column_name='status')
op.drop_column('notifications', 'new_status')
op.execute(
"update notifications set status = 'failed' where status in ('technical-failure', 'temporary-failure', 'permanent-failure')"
)
op.execute(
"update notifications set old_status = CAST(CAST(status as text) as notification_status_types)"
)
op.alter_column("notifications", "status", new_column_name="new_status")
op.alter_column("notifications", "old_status", new_column_name="status")
op.drop_column("notifications", "new_status")
op.get_bind()
op.execute('DROP TYPE notification_status_type')
op.alter_column('notifications', 'status', nullable=False)
op.execute("DROP TYPE notification_status_type")
op.alter_column("notifications", "status", nullable=False)

View File

@@ -7,8 +7,8 @@ Create Date: 2016-05-18 09:39:22.512042
"""
# revision identifiers, used by Alembic.
revision = '0018_remove_subject_uniqueness'
down_revision = '0017_add_failure_types'
revision = "0018_remove_subject_uniqueness"
down_revision = "0017_add_failure_types"
from alembic import op
import sqlalchemy as sa
@@ -16,11 +16,11 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('templates_subject_key', 'templates', type_='unique')
op.drop_constraint("templates_subject_key", "templates", type_="unique")
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint('templates_subject_key', 'templates', ['subject'])
op.create_unique_constraint("templates_subject_key", "templates", ["subject"])
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-05-18 15:04:24.513071
"""
# revision identifiers, used by Alembic.
revision = '0019_add_job_row_number'
down_revision = '0018_remove_subject_uniqueness'
revision = "0019_add_job_row_number"
down_revision = "0018_remove_subject_uniqueness"
from alembic import op
import sqlalchemy as sa
@@ -16,11 +16,13 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('notifications', sa.Column('job_row_number', sa.Integer(), nullable=True))
op.add_column(
"notifications", sa.Column("job_row_number", sa.Integer(), nullable=True)
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('notifications', 'job_row_number')
op.drop_column("notifications", "job_row_number")
### end Alembic commands ###

View File

@@ -7,17 +7,22 @@ Create Date: 2016-05-20 15:15:03.850862
"""
# revision identifiers, used by Alembic.
revision = '0020_template_history_fix'
down_revision = '0019_add_job_row_number'
revision = "0020_template_history_fix"
down_revision = "0019_add_job_row_number"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.get_bind()
op.execute('update templates_history t set updated_at = (select updated_at from templates_history th where t.version = th.version -1 and t.id = th.id and t.version != 1)')
op.execute('update templates_history th set updated_at = (select t.updated_at from templates_history h, templates t where h.id = t.id and h.version = t.version and th.id = h.id) where (th.id, th.version) = (select t.id, t.version from templates t where t.id = th.id and t.version = th.version)')
op.get_bind()
op.execute(
"update templates_history t set updated_at = (select updated_at from templates_history th where t.version = th.version -1 and t.id = th.id and t.version != 1)"
)
op.execute(
"update templates_history th set updated_at = (select t.updated_at from templates_history h, templates t where h.id = t.id and h.version = t.version and th.id = h.id) where (th.id, th.version) = (select t.id, t.version from templates t where t.id = th.id and t.version = th.version)"
)
def downgrade():
pass

View File

@@ -7,8 +7,10 @@ Create Date: 2016-05-23 15:05:25.109346
"""
# revision identifiers, used by Alembic.
revision = '0021_add_delivered_failed_counts'
down_revision = '0020_template_history_fix'
from sqlalchemy import text
revision = "0021_add_delivered_failed_counts"
down_revision = "0020_template_history_fix"
from alembic import op
import sqlalchemy as sa
@@ -16,33 +18,51 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('jobs', sa.Column('notifications_delivered', sa.Integer(), nullable=True))
op.add_column('jobs', sa.Column('notifications_failed', sa.Integer(), nullable=True))
op.add_column(
"jobs", sa.Column("notifications_delivered", sa.Integer(), nullable=True)
)
op.add_column(
"jobs", sa.Column("notifications_failed", sa.Integer(), nullable=True)
)
conn = op.get_bind()
results = conn.execute("select distinct job_id from notifications")
res = results.fetchall()
for x in res:
if x.job_id:
op.execute("update jobs set notifications_delivered = ("
"select count(status) from notifications where status = 'delivered' and job_id = '{}' "
"group by job_id)"
"where jobs.id = '{}'".format(x.job_id, x.job_id))
input_params = {"job_id": x.job_id}
conn.execute(
text(
"update jobs set notifications_delivered = ("
"select count(status) from notifications where status = 'delivered' and job_id = :job_id "
"group by job_id)"
"where jobs.id = :job_id"
),
input_params,
)
op.execute("update jobs set notifications_failed = ("
"select count(status) from notifications "
"where status in ('failed','technical-failure', 'temporary-failure', 'permanent-failure') "
"and job_id = '{}' group by job_id)"
"where jobs.id = '{}'".format(x.job_id, x.job_id))
op.execute("update jobs set notifications_delivered = 0 where notifications_delivered is null")
op.execute("update jobs set notifications_failed = 0 where notifications_failed is null")
op.alter_column('jobs', 'notifications_delivered', nullable=False)
op.alter_column('jobs', 'notifications_failed', nullable=False)
conn.execute(
text(
"update jobs set notifications_failed = ("
"select count(status) from notifications "
"where status in ('failed','technical-failure', 'temporary-failure', 'permanent-failure') "
"and job_id = :job_id group by job_id)"
"where jobs.id = :job_id"
),
input_params,
)
op.execute(
"update jobs set notifications_delivered = 0 where notifications_delivered is null"
)
op.execute(
"update jobs set notifications_failed = 0 where notifications_failed is null"
)
op.alter_column("jobs", "notifications_delivered", nullable=False)
op.alter_column("jobs", "notifications_failed", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('jobs', 'notifications_failed')
op.drop_column('jobs', 'notifications_delivered')
op.drop_column("jobs", "notifications_failed")
op.drop_column("jobs", "notifications_delivered")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-05-25 15:47:32.568097
"""
# revision identifiers, used by Alembic.
revision = '0022_add_pending_status'
down_revision = '0021_add_delivered_failed_counts'
revision = "0022_add_pending_status"
down_revision = "0021_add_delivered_failed_counts"
from alembic import op
import sqlalchemy as sa
@@ -16,36 +16,53 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
status_type = sa.Enum('sending', 'delivered', 'pending', 'failed',
'technical-failure', 'temporary-failure', 'permanent-failure',
name='notify_status_types')
status_type = sa.Enum(
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
name="notify_status_types",
)
status_type.create(op.get_bind())
op.add_column('notifications', sa.Column('new_status', status_type, nullable=True))
op.execute('update notifications set new_status = CAST(CAST(status as text) as notify_status_types)')
op.alter_column('notifications', 'status', new_column_name='old_status')
op.alter_column('notifications', 'new_status', new_column_name='status')
op.drop_column('notifications', 'old_status')
op.add_column("notifications", sa.Column("new_status", status_type, nullable=True))
op.execute(
"update notifications set new_status = CAST(CAST(status as text) as notify_status_types)"
)
op.alter_column("notifications", "status", new_column_name="old_status")
op.alter_column("notifications", "new_status", new_column_name="status")
op.drop_column("notifications", "old_status")
op.get_bind()
op.execute('DROP TYPE notification_status_type')
op.alter_column('notifications', 'status', nullable=False)
op.execute("DROP TYPE notification_status_type")
op.alter_column("notifications", "status", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
status_type = sa.Enum('sending', 'delivered', 'failed',
'technical-failure', 'temporary-failure', 'permanent-failure',
name='notification_status_type')
status_type = sa.Enum(
"sending",
"delivered",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
name="notification_status_type",
)
status_type.create(op.get_bind())
op.add_column('notifications', sa.Column('old_status', status_type, nullable=True))
op.add_column("notifications", sa.Column("old_status", status_type, nullable=True))
op.execute("update notifications set status = 'sending' where status = 'pending'")
op.execute('update notifications set old_status = CAST(CAST(status as text) as notification_status_type)')
op.alter_column('notifications', 'status', new_column_name='new_status')
op.alter_column('notifications', 'old_status', new_column_name='status')
op.drop_column('notifications', 'new_status')
op.execute(
"update notifications set old_status = CAST(CAST(status as text) as notification_status_type)"
)
op.alter_column("notifications", "status", new_column_name="new_status")
op.alter_column("notifications", "old_status", new_column_name="status")
op.drop_column("notifications", "new_status")
op.get_bind()
op.execute('DROP TYPE notify_status_types')
op.alter_column('notifications', 'status', nullable=False)
op.execute("DROP TYPE notify_status_types")
op.alter_column("notifications", "status", nullable=False)
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-05-31 11:11:45.979594
"""
# revision identifiers, used by Alembic.
revision = '0023_add_research_mode'
down_revision = '0022_add_pending_status'
revision = "0023_add_research_mode"
down_revision = "0022_add_pending_status"
from alembic import op
import sqlalchemy as sa
@@ -16,13 +16,15 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('research_mode', sa.Boolean(), nullable=True))
op.add_column('services_history', sa.Column('research_mode', sa.Boolean(), nullable=True))
op.add_column("services", sa.Column("research_mode", sa.Boolean(), nullable=True))
op.add_column(
"services_history", sa.Column("research_mode", sa.Boolean(), nullable=True)
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('services_history', 'research_mode')
op.drop_column('services', 'research_mode')
op.drop_column("services_history", "research_mode")
op.drop_column("services", "research_mode")
### end Alembic commands ###

View File

@@ -7,16 +7,17 @@ Create Date: 2016-05-31 11:11:45.979594
"""
# revision identifiers, used by Alembic.
revision = '0024_add_research_mode_defaults'
down_revision = '0023_add_research_mode'
revision = "0024_add_research_mode_defaults"
down_revision = "0023_add_research_mode"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.execute('update services set research_mode = false')
op.execute('update services_history set research_mode = false')
op.execute("update services set research_mode = false")
op.execute("update services_history set research_mode = false")
def downgrade():
pass
pass

View File

@@ -10,55 +10,89 @@ Create Date: 2016-06-01 14:17:01.963181
from datetime import datetime
from alembic import op
from sqlalchemy import text
from app.hashing import hashpw
import uuid
revision = '0025_notify_service_data'
down_revision = '0024_add_research_mode_defaults'
revision = "0025_notify_service_data"
down_revision = "0024_add_research_mode_defaults"
user_id= '6af522d0-2915-4e52-83a3-3690455a5fe6'
service_id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
user_id = "6af522d0-2915-4e52-83a3-3690455a5fe6"
service_id = "d6aa2c68-a2d9-4437-ab19-3ae8eb202553"
def upgrade():
password = hashpw(str(uuid.uuid4()))
op.get_bind()
conn = op.get_bind()
user_insert = """INSERT INTO users (id, name, email_address, created_at, failed_login_count, _password, mobile_number, state, platform_admin)
VALUES ('{}', 'Notify service user', 'testsender@dispostable.com', '{}', 0,'{}', '+441234123412', 'active', False)
VALUES (:user_id, 'Notify service user', 'testsender@dispostable.com', :time_now, 0,:password, '+441234123412', 'active', False)
"""
op.execute(user_insert.format(user_id, datetime.utcnow(), password))
conn.execute(
text(user_insert),
user_id=user_id,
time_now=datetime.utcnow(),
password=password,
)
service_history_insert = """INSERT INTO services_history (id, name, created_at, active, message_limit, restricted, research_mode, email_from, created_by_id, reply_to_email_address, version)
VALUES ('{}', 'Notify service', '{}', True, 1000, False, False, 'testsender@dispostable.com',
'{}', 'testsender@dispostable.com', 1)
VALUES (:service_id, 'Notify service', :time_now, True, 1000, False, False, 'testsender@dispostable.com',
:user_id, 'testsender@dispostable.com', 1)
"""
op.execute(service_history_insert.format(service_id, datetime.utcnow(), user_id))
conn.execute(
text(service_history_insert),
service_id=service_id,
time_now=datetime.utcnow(),
user_id=user_id,
)
service_insert = """INSERT INTO services (id, name, created_at, active, message_limit, restricted, research_mode, email_from, created_by_id, reply_to_email_address, version)
VALUES ('{}', 'Notify service', '{}', True, 1000, False, False, 'testsender@dispostable.com',
'{}', 'testsender@dispostable.com', 1)
VALUES (:service_id, 'Notify service', :time_now, True, 1000, False, False, 'testsender@dispostable.com',
:user_id, 'testsender@dispostable.com', 1)
"""
op.execute(service_insert.format(service_id, datetime.utcnow(), user_id))
user_to_service_insert = """INSERT INTO user_to_service (user_id, service_id) VALUES ('{}', '{}')"""
op.execute(user_to_service_insert.format(user_id, service_id))
conn.execute(
text(service_insert),
service_id=service_id,
time_now=datetime.utcnow(),
user_id=user_id,
)
user_to_service_insert = """INSERT INTO user_to_service (user_id, service_id) VALUES (:user_id, :service_id)"""
conn.execute(text(user_to_service_insert), user_id=user_id, service_id=service_id)
template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at,
content, archived, service_id,
subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
VALUES (:template_id, :template_name, :template_type, :time_now,
:content, False, :service_id, :subject, :user_id, 1)
"""
template_insert = """INSERT INTO templates (id, name, template_type, created_at,
content, archived, service_id, subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
VALUES (:template_id, :template_name, :template_type, :time_now,
:content, False, :service_id, :subject, :user_id, 1)
"""
email_verification_content = \
"""Hi ((name)),\n\nTo complete your registration for GOV.UK Notify please click the link below\n\n((url))"""
op.execute(template_history_insert.format(uuid.uuid4(), 'Notify email verification code', 'email',
datetime.utcnow(), email_verification_content, service_id,
'Confirm GOV.UK Notify registration', user_id))
op.execute(template_insert.format('ece42649-22a8-4d06-b87f-d52d5d3f0a27', 'Notify email verification code', 'email',
datetime.utcnow(), email_verification_content, service_id,
'Confirm GOV.UK Notify registration', user_id))
email_verification_content = """Hi ((name)),\n\nTo complete your registration for GOV.UK Notify please click the link below\n\n((url))"""
conn.execute(
text(template_history_insert),
template_id=uuid.uuid4(),
template_name="Notify email verification code",
template_type="email",
time_now=datetime.utcnow(),
content=email_verification_content,
service_id=service_id,
subject="Confirm GOV.UK Notify registration",
user_id=user_id,
)
conn.execute(
text(template_insert),
template_id="ece42649-22a8-4d06-b87f-d52d5d3f0a27",
template_name="Notify email verification code",
template_type="email",
time_now=datetime.utcnow(),
content=email_verification_content,
service_id=service_id,
subject="Confirm GOV.UK Notify registration",
user_id=user_id,
)
invitation_subject = "((user_name)) has invited you to collaborate on ((service_name)) on GOV.UK Notify"
invitation_content = """((user_name)) has invited you to collaborate on ((service_name)) on GOV.UK Notify.\n\n
@@ -66,41 +100,108 @@ def upgrade():
Click this link to create an account on GOV.UK Notify:\n((url))\n\n
This invitation will stop working at midnight tomorrow. This is to keep ((service_name)) secure.
"""
op.execute(template_history_insert.format('4f46df42-f795-4cc4-83bb-65ca312f49cc', 'Notify invitation email',
'email', datetime.utcnow(), invitation_content, service_id,
invitation_subject, user_id))
op.execute(template_insert.format('4f46df42-f795-4cc4-83bb-65ca312f49cc', 'Notify invitation email',
'email', datetime.utcnow(), invitation_content, service_id,
invitation_subject, user_id))
conn.execute(
text(template_history_insert),
template_id="4f46df42-f795-4cc4-83bb-65ca312f49cc",
template_name="Notify invitation email",
template_type="email",
time_now=datetime.utcnow(),
content=invitation_content,
service_id=service_id,
subject=invitation_subject,
user_id=user_id,
)
conn.execute(
text(template_insert),
template_id="4f46df42-f795-4cc4-83bb-65ca312f49cc",
template_name="Notify invitation email",
template_type="email",
time_now=datetime.utcnow(),
content=invitation_content,
service_id=service_id,
subject=invitation_subject,
user_id=user_id,
)
sms_code_content = '((verify_code)) is your US Notify authentication code'
op.execute(template_history_insert.format('36fb0730-6259-4da1-8a80-c8de22ad4246', 'Notify SMS verify code',
'sms', datetime.utcnow(), sms_code_content, service_id, None, user_id))
sms_code_content = "((verify_code)) is your US Notify authentication code"
conn.execute(
text(template_history_insert),
template_id="36fb0730-6259-4da1-8a80-c8de22ad4246",
template_name="Notify SMS verify code",
template_type="sms",
time_now=datetime.utcnow(),
content=sms_code_content,
service_id=service_id,
subject=None,
user_id=user_id,
)
op.execute(template_insert.format('36fb0730-6259-4da1-8a80-c8de22ad4246', 'Notify SMS verify code',
'sms', datetime.utcnow(), sms_code_content, service_id, None, user_id))
conn.execute(
text(template_insert),
template_id="36fb0730-6259-4da1-8a80-c8de22ad4246",
template_name="Notify SMS verify code",
template_type="sms",
time_now=datetime.utcnow(),
content=sms_code_content,
service_id=service_id,
subject=None,
user_id=user_id,
)
password_reset_content = "Hi ((user_name)),\n\n" \
"We received a request to reset your password on GOV.UK Notify.\n\n" \
"If you didn''t request this email, you can ignore it " \
"your password has not been changed.\n\n" \
"To reset your password, click this link:\n\n" \
"((url))"
password_reset_content = (
"Hi ((user_name)),\n\n"
"We received a request to reset your password on GOV.UK Notify.\n\n"
"If you didn''t request this email, you can ignore it "
"your password has not been changed.\n\n"
"To reset your password, click this link:\n\n"
"((url))"
)
op.execute(template_history_insert.format('474e9242-823b-4f99-813d-ed392e7f1201', 'Notify password reset email',
'email', datetime.utcnow(), password_reset_content, service_id,
'Reset your GOV.UK Notify password', user_id))
op.execute(template_insert.format('474e9242-823b-4f99-813d-ed392e7f1201', 'Notify password reset email',
'email', datetime.utcnow(), password_reset_content, service_id,
'Reset your GOV.UK Notify password', user_id))
conn.execute(
text(template_history_insert),
template_id="474e9242-823b-4f99-813d-ed392e7f1201",
template_name="Notify password reset email",
template_type="email",
time_now=datetime.utcnow(),
content=password_reset_content,
service_id=service_id,
subject="Reset your GOV.UK Notify password",
user_id=user_id,
)
conn.execute(
text(template_insert),
template_id="474e9242-823b-4f99-813d-ed392e7f1201",
template_name="Notify password reset email",
template_type="email",
time_now=datetime.utcnow(),
content=password_reset_content,
service_id=service_id,
subject="Reset your GOV.UK Notify password",
user_id=user_id,
)
def downgrade():
op.get_bind()
op.execute("delete from templates where service_id = '{}'".format(service_id))
op.execute("delete from templates_history where service_id = '{}'".format(service_id))
op.execute("delete from user_to_service where service_id = '{}'".format(service_id))
op.execute("delete from services_history where id = '{}'".format(service_id))
op.execute("delete from services where id = '{}'".format(service_id))
op.execute("delete from users where id = '{}'".format(user_id))
conn = op.get_bind()
conn.execute(
text("delete from templates where service_id = :service_id"),
service_id=service_id,
)
conn.execute(
text("delete from templates_history where service_id = :service_id"),
service_id=service_id,
)
conn.execute(
text("delete from user_to_service where service_id = :service_id"),
service_id=service_id,
)
conn.execute(
text("delete from services_history where id = :service_id"),
service_id=service_id,
)
conn.execute(
text("delete from services where id = :service_id"), service_id=service_id
)
conn.execute(
text("delete from users where id = :service_id"), service_id=service_id
)

View File

@@ -7,8 +7,8 @@ Create Date: 2016-06-07 09:51:07.343334
"""
# revision identifiers, used by Alembic.
revision = '0026_rename_notify_service'
down_revision = '0025_notify_service_data'
revision = "0026_rename_notify_service"
down_revision = "0025_notify_service_data"
from alembic import op
import sqlalchemy as sa
@@ -17,8 +17,12 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.get_bind()
op.execute("update services set name = 'GOV.UK Notify' where id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'")
op.execute("update services_history set name = 'GOV.UK Notify' where id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'")
op.execute(
"update services set name = 'GOV.UK Notify' where id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'"
)
op.execute(
"update services_history set name = 'GOV.UK Notify' where id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'"
)
### end Alembic commands ###

View File

@@ -1,35 +0,0 @@
"""empty message
Revision ID: 0027_update_provider_rates
Revises: 0026_rename_notify_service
Create Date: 2016-06-08 01:00:00.000000
"""
# revision identifiers, used by Alembic.
revision = '0027_update_provider_rates'
down_revision = '0026_rename_notify_service'
from alembic import op
import sqlalchemy as sa
from datetime import datetime
import uuid
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.get_bind()
op.execute((
"INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES ('{}', '{}', 1.8, "
"(SELECT id FROM provider_details WHERE identifier = 'mmg'))").format(uuid.uuid4(), datetime.utcnow()))
op.execute((
"INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES ('{}', '{}', 2.5, "
"(SELECT id FROM provider_details WHERE identifier = 'firetext'))").format(uuid.uuid4(), datetime.utcnow()))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.get_bind()
op.execute("DELETE FROM provider_rates")
### end Alembic commands ###

View File

@@ -1,7 +1,7 @@
"""empty message
Revision ID: 0028_fix_reg_template_history
Revises: 0027_update_provider_rates
Revises: 0026_rename_notify_service
Create Date: 2016-06-13 11:04:15.888017
"""
@@ -9,30 +9,44 @@ Create Date: 2016-06-13 11:04:15.888017
# revision identifiers, used by Alembic.
from datetime import datetime
revision = '0028_fix_reg_template_history'
down_revision = '0027_update_provider_rates'
from sqlalchemy import text
revision = "0028_fix_reg_template_history"
down_revision = "0026_rename_notify_service"
from alembic import op
import sqlalchemy as sa
service_id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
user_id= '6af522d0-2915-4e52-83a3-3690455a5fe6'
service_id = "d6aa2c68-a2d9-4437-ab19-3ae8eb202553"
user_id = "6af522d0-2915-4e52-83a3-3690455a5fe6"
def upgrade():
op.get_bind()
op.execute("delete from templates_history where name = 'Notify email verification code'")
op.execute(
"delete from templates_history where name = 'Notify email verification code'"
)
template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at,
content, archived, service_id,
subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
VALUES (:id, :name, :type, :time_now, :content, False, :service_id, :subject, :user_id, 1)
"""
email_verification_content = \
"""Hi ((name)),\n\nTo complete your registration for GOV.UK Notify please click the link below\n\n((url))"""
op.execute(template_history_insert.format('ece42649-22a8-4d06-b87f-d52d5d3f0a27',
'Notify email verification code', 'email',
datetime.utcnow(), email_verification_content, service_id,
'Confirm GOV.UK Notify registration', user_id))
email_verification_content = """Hi ((name)),\n\nTo complete your registration for GOV.UK Notify please click the link below\n\n((url))"""
input_params = {
"id": "ece42649-22a8-4d06-b87f-d52d5d3f0a27",
"name": "Notify email verification code",
"type": "email",
"time_now": datetime.utcnow(),
"content": email_verification_content,
"service_id": service_id,
"subject": "Confirm GOV.UK Notify registration",
"user_id": user_id,
}
conn = op.get_bind()
conn.execute(text(template_history_insert), input_params)
def downgrade():
### commands auto generated by Alembic - please adjust! ###

View File

@@ -7,17 +7,30 @@ Create Date: 2016-06-13 15:15:34.035984
"""
# revision identifiers, used by Alembic.
revision = '0029_fix_email_from'
down_revision = '0028_fix_reg_template_history'
from sqlalchemy import text
revision = "0029_fix_email_from"
down_revision = "0028_fix_reg_template_history"
from alembic import op
import sqlalchemy as sa
service_id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
service_id = "d6aa2c68-a2d9-4437-ab19-3ae8eb202553"
def upgrade():
op.get_bind()
op.execute("update services set email_from = 'testsender' where id = '{}'".format(service_id))
op.execute("update services_history set email_from = 'testsender' where id = '{}'".format(service_id))
conn = op.get_bind()
input_params = {"service_id": service_id}
conn.execute(
text("update services set email_from = 'testsender' where id = :service_id"),
input_params,
)
conn.execute(
text(
"update services_history set email_from = 'testsender' where id = :service_id"
),
input_params,
)
def downgrade():

View File

@@ -10,20 +10,20 @@ Create Date: 2016-06-15 15:51:41.355149
from sqlalchemy.dialects import postgresql
revision = '0030_service_id_not_null'
down_revision = '0029_fix_email_from'
revision = "0030_service_id_not_null"
down_revision = "0029_fix_email_from"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column('permissions', 'service_id',
existing_type=postgresql.UUID(),
nullable=True)
op.alter_column(
"permissions", "service_id", existing_type=postgresql.UUID(), nullable=True
)
def downgrade():
op.alter_column('permissions', 'service_id',
existing_type=postgresql.UUID(),
nullable=False)
op.alter_column(
"permissions", "service_id", existing_type=postgresql.UUID(), nullable=False
)

View File

@@ -7,8 +7,8 @@ Create Date: 2016-06-20 10:39:50.892847
"""
# revision identifiers, used by Alembic.
revision = '0031_store_personalisation'
down_revision = '0030_service_id_not_null'
revision = "0031_store_personalisation"
down_revision = "0030_service_id_not_null"
from alembic import op
import sqlalchemy as sa
@@ -16,11 +16,13 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('notifications', sa.Column('_personalisation', sa.String(), nullable=True))
op.add_column(
"notifications", sa.Column("_personalisation", sa.String(), nullable=True)
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('notifications', '_personalisation')
op.drop_column("notifications", "_personalisation")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-06-21 11:29:28.963615
"""
# revision identifiers, used by Alembic.
revision = '0032_notification_created_status'
down_revision = '0031_store_personalisation'
revision = "0032_notification_created_status"
down_revision = "0031_store_personalisation"
from alembic import op
import sqlalchemy as sa
@@ -16,35 +16,54 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
status_type = sa.Enum('created', 'sending', 'delivered', 'pending', 'failed',
'technical-failure', 'temporary-failure', 'permanent-failure',
name='notify_status_type')
status_type = sa.Enum(
"created",
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
name="notify_status_type",
)
status_type.create(op.get_bind())
op.add_column('notifications', sa.Column('new_status', status_type, nullable=True))
op.execute('update notifications set new_status = CAST(CAST(status as text) as notify_status_type)')
op.alter_column('notifications', 'status', new_column_name='old_status')
op.alter_column('notifications', 'new_status', new_column_name='status')
op.drop_column('notifications', 'old_status')
op.add_column("notifications", sa.Column("new_status", status_type, nullable=True))
op.execute(
"update notifications set new_status = CAST(CAST(status as text) as notify_status_type)"
)
op.alter_column("notifications", "status", new_column_name="old_status")
op.alter_column("notifications", "new_status", new_column_name="status")
op.drop_column("notifications", "old_status")
op.get_bind()
op.execute('DROP TYPE notify_status_types')
op.alter_column('notifications', 'status', nullable=False)
op.execute("DROP TYPE notify_status_types")
op.alter_column("notifications", "status", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
status_type = sa.Enum('sending', 'delivered', 'pending', 'failed',
'technical-failure', 'temporary-failure', 'permanent-failure',
name='notify_status_types')
status_type = sa.Enum(
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
name="notify_status_types",
)
status_type.create(op.get_bind())
op.add_column('notifications', sa.Column('old_status', status_type, nullable=True))
op.add_column("notifications", sa.Column("old_status", status_type, nullable=True))
op.execute("update notifications set status = 'sending' where status = 'created'")
op.execute('update notifications set old_status = CAST(CAST(status as text) as notify_status_types)')
op.alter_column('notifications', 'status', new_column_name='new_status')
op.alter_column('notifications', 'old_status', new_column_name='status')
op.drop_column('notifications', 'new_status')
op.execute(
"update notifications set old_status = CAST(CAST(status as text) as notify_status_types)"
)
op.alter_column("notifications", "status", new_column_name="new_status")
op.alter_column("notifications", "old_status", new_column_name="status")
op.drop_column("notifications", "new_status")
op.get_bind()
op.execute('DROP TYPE notify_status_type')
op.alter_column('notifications', 'status', nullable=False)
op.execute("DROP TYPE notify_status_type")
op.alter_column("notifications", "status", nullable=False)
### end Alembic commands ###

View File

@@ -7,53 +7,82 @@ Create Date: 2016-06-24 12:02:10.915817
"""
# revision identifiers, used by Alembic.
revision = '0033_api_key_type'
down_revision = '0032_notification_created_status'
revision = "0033_api_key_type"
down_revision = "0032_notification_created_status"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('key_types',
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('name')
op.create_table(
"key_types",
sa.Column("name", sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint("name"),
)
op.add_column(
"api_keys", sa.Column("key_type", sa.String(length=255), nullable=True)
)
op.add_column(
"api_keys_history", sa.Column("key_type", sa.String(length=255), nullable=True)
)
op.add_column(
"notifications",
sa.Column("api_key_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.add_column(
"notifications", sa.Column("key_type", sa.String(length=255), nullable=True)
)
op.add_column('api_keys', sa.Column('key_type', sa.String(length=255), nullable=True))
op.add_column('api_keys_history', sa.Column('key_type', sa.String(length=255), nullable=True))
op.add_column('notifications', sa.Column('api_key_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column('notifications', sa.Column('key_type', sa.String(length=255), nullable=True))
op.create_index(op.f('ix_api_keys_key_type'), 'api_keys', ['key_type'], unique=False)
op.create_index(op.f('ix_api_keys_history_key_type'), 'api_keys_history', ['key_type'], unique=False)
op.create_index(op.f('ix_notifications_api_key_id'), 'notifications', ['api_key_id'], unique=False)
op.create_index(op.f('ix_notifications_key_type'), 'notifications', ['key_type'], unique=False)
op.create_foreign_key(None, 'api_keys', 'key_types', ['key_type'], ['name'])
op.create_foreign_key(None, 'notifications', 'api_keys', ['api_key_id'], ['id'])
op.create_foreign_key(None, 'notifications', 'key_types', ['key_type'], ['name'])
op.create_index(
op.f("ix_api_keys_key_type"), "api_keys", ["key_type"], unique=False
)
op.create_index(
op.f("ix_api_keys_history_key_type"),
"api_keys_history",
["key_type"],
unique=False,
)
op.create_index(
op.f("ix_notifications_api_key_id"),
"notifications",
["api_key_id"],
unique=False,
)
op.create_index(
op.f("ix_notifications_key_type"), "notifications", ["key_type"], unique=False
)
op.create_foreign_key(None, "api_keys", "key_types", ["key_type"], ["name"])
op.create_foreign_key(None, "notifications", "api_keys", ["api_key_id"], ["id"])
op.create_foreign_key(None, "notifications", "key_types", ["key_type"], ["name"])
op.execute("insert into key_types values ('normal'), ('team')")
op.execute("update api_keys set key_type = 'normal'")
op.execute("update api_keys_history set key_type = 'normal'")
op.alter_column('api_keys', 'key_type', nullable=False)
op.alter_column('api_keys_history', 'key_type', nullable=False)
op.alter_column("api_keys", "key_type", nullable=False)
op.alter_column("api_keys_history", "key_type", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('notifications_key_type_fkey', 'notifications', type_='foreignkey')
op.drop_constraint('notifications_api_key_id_fkey', 'notifications', type_='foreignkey')
op.drop_index(op.f('ix_notifications_key_type'), table_name='notifications')
op.drop_index(op.f('ix_notifications_api_key_id'), table_name='notifications')
op.drop_column('notifications', 'key_type')
op.drop_column('notifications', 'api_key_id')
op.drop_index(op.f('ix_api_keys_history_key_type'), table_name='api_keys_history')
op.drop_column('api_keys_history', 'key_type')
op.drop_constraint('api_keys_key_type_fkey', 'api_keys', type_='foreignkey')
op.drop_index(op.f('ix_api_keys_key_type'), table_name='api_keys')
op.drop_column('api_keys', 'key_type')
op.drop_table('key_types')
op.drop_constraint(
"notifications_key_type_fkey", "notifications", type_="foreignkey"
)
op.drop_constraint(
"notifications_api_key_id_fkey", "notifications", type_="foreignkey"
)
op.drop_index(op.f("ix_notifications_key_type"), table_name="notifications")
op.drop_index(op.f("ix_notifications_api_key_id"), table_name="notifications")
op.drop_column("notifications", "key_type")
op.drop_column("notifications", "api_key_id")
op.drop_index(op.f("ix_api_keys_history_key_type"), table_name="api_keys_history")
op.drop_column("api_keys_history", "key_type")
op.drop_constraint("api_keys_key_type_fkey", "api_keys", type_="foreignkey")
op.drop_index(op.f("ix_api_keys_key_type"), table_name="api_keys")
op.drop_column("api_keys", "key_type")
op.drop_table("key_types")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-06-28 10:37:25.389020
"""
# revision identifiers, used by Alembic.
revision = '0034_pwd_changed_at_not_null'
down_revision = '0033_api_key_type'
revision = "0034_pwd_changed_at_not_null"
down_revision = "0033_api_key_type"
from alembic import op
import sqlalchemy as sa
@@ -17,12 +17,14 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.get_bind()
op.execute('update users set password_changed_at = created_at where password_changed_at is null')
op.alter_column('users', 'password_changed_at', nullable=False)
op.execute(
"update users set password_changed_at = created_at where password_changed_at is null"
)
op.alter_column("users", "password_changed_at", nullable=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('users', 'password_changed_at', nullable=True)
op.alter_column("users", "password_changed_at", nullable=True)
### end Alembic commands ###

View File

@@ -7,21 +7,28 @@ Create Date: 2016-06-29 10:48:55.955317
"""
# revision identifiers, used by Alembic.
revision = '0035_notification_type'
down_revision = '0034_pwd_changed_at_not_null'
revision = "0035_notification_type"
down_revision = "0034_pwd_changed_at_not_null"
from alembic import op
import sqlalchemy as sa
def upgrade():
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)
def upgrade():
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)
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('notifications', 'notification_type')
op.drop_column("notifications", "notification_type")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-07-01 16:01:16.892638
"""
# revision identifiers, used by Alembic.
revision = '0036_notif_key_type_not_null'
down_revision = '0035_notification_type'
revision = "0036_notif_key_type_not_null"
down_revision = "0035_notification_type"
from alembic import op
import sqlalchemy as sa
@@ -17,11 +17,18 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.execute("update notifications set key_type = 'normal' where key_type is null")
op.alter_column('notifications', 'key_type', existing_type=sa.VARCHAR(length=255), nullable=False)
op.alter_column(
"notifications",
"key_type",
existing_type=sa.VARCHAR(length=255),
nullable=False,
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('notifications', 'key_type', existing_type=sa.VARCHAR(length=255), nullable=True)
op.alter_column(
"notifications", "key_type", existing_type=sa.VARCHAR(length=255), nullable=True
)
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-06-30 14:55:33.811696
"""
# revision identifiers, used by Alembic.
revision = '0037_service_sms_sender'
down_revision = '0036_notif_key_type_not_null'
revision = "0037_service_sms_sender"
down_revision = "0036_notif_key_type_not_null"
from alembic import op
import sqlalchemy as sa
@@ -16,13 +16,17 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('sms_sender', sa.String(length=11), nullable=True))
op.add_column('services_history', sa.Column('sms_sender', sa.String(length=11), nullable=True))
op.add_column(
"services", sa.Column("sms_sender", sa.String(length=11), nullable=True)
)
op.add_column(
"services_history", sa.Column("sms_sender", sa.String(length=11), nullable=True)
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('services_history', 'sms_sender')
op.drop_column('services', 'sms_sender')
op.drop_column("services_history", "sms_sender")
op.drop_column("services", "sms_sender")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2016-07-05 10:28:12.947306
"""
# revision identifiers, used by Alembic.
revision = '0038_test_api_key_type'
down_revision = '0037_service_sms_sender'
revision = "0038_test_api_key_type"
down_revision = "0037_service_sms_sender"
from alembic import op

View File

@@ -7,18 +7,24 @@ Create Date: 2016-07-06 13:28:48.381278
"""
# revision identifiers, used by Alembic.
revision = '0039_fix_notifications'
down_revision = '0038_test_api_key_type'
from sqlalchemy import text
revision = "0039_fix_notifications"
down_revision = "0038_test_api_key_type"
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)')
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()
reset_counts = "update notification_statistics set emails_requested = 0, emails_delivered = 0, emails_failed=0," \
"sms_requested = 0, sms_delivered = 0, sms_failed=0 where day > '2016-06-30'"
reset_counts = (
"update notification_statistics set emails_requested = 0, emails_delivered = 0, emails_failed=0,"
"sms_requested = 0, sms_delivered = 0, sms_failed=0 where day > '2016-06-30'"
)
op.execute(reset_counts)
all_notifications = "select * from notifications where date(created_at) > '2016-06-30' order by created_at;"
@@ -26,28 +32,57 @@ def upgrade():
res = results.fetchall()
for x in res:
print(' in loop {} {}'.format(x.notification_type, x.created_at))
created = x.created_at.strftime("%Y-%m-%d")
if x.notification_type == 'email' and x.status == 'delivered':
sql = "update notification_statistics set emails_requested = emails_requested + 1, " \
"emails_delivered = emails_delivered + 1 where day = date('{}') and service_id = '{}'".format(created, x.service_id)
if x.notification_type == 'sms' and x.status == 'delivered':
sql = "update notification_statistics set sms_requested = sms_requested + 1, " \
"sms_delivered = sms_delivered + 1 where day = date('{}') and service_id = '{}'".format(created, x.service_id)
if x.notification_type == 'email' and x.status in ['technical-failure', 'temporary-failure', 'permanent-failure']:
sql = "update notification_statistics set emails_requested = emails_requested + 1, " \
"emails_failed = emails_failed + 1 where day = date('{}') and service_id = '{}'".format(created, x.service_id)
if x.notification_type == 'sms' and x.status in ['technical-failure', 'temporary-failure', 'permanent-failure']:
sql = "update notification_statistics set sms_requested = sms_requested + 1, " \
"sms_failed = sms_failed + 1 where day = date('{}') and service_id = '{}'".format(created, x.service_id)
if x.notification_type == 'email' and x.status in ['created', 'sending', 'pending']:
sql = "update notification_statistics set emails_requested = emails_requested + 1 " \
" where day = date('{}') and service_id = '{}'".format(created, x.service_id)
if x.notification_type == 'sms' and x.status in ['created', 'sending', 'pending']:
sql = "update notification_statistics set sms_requested = sms_requested + 1 " \
" where day = date('{}') and service_id = '{}'".format(created, x.service_id)
input_params = {"created": created, "service_id": x.service_id}
if x.notification_type == "email" and x.status == "delivered":
sql = text(
"update notification_statistics set emails_requested = emails_requested + 1, "
"emails_delivered = emails_delivered + 1 where day = date(:created) and service_id = :service_id"
)
if x.notification_type == "sms" and x.status == "delivered":
sql = text(
"update notification_statistics set sms_requested = sms_requested + 1, "
"sms_delivered = sms_delivered + 1 where day = date(:created) and service_id = :service_id"
)
if x.notification_type == "email" and x.status in [
"technical-failure",
"temporary-failure",
"permanent-failure",
]:
sql = text(
"update notification_statistics set emails_requested = emails_requested + 1, "
"emails_failed = emails_failed + 1 where day = date(:created) and service_id = :service_id"
)
if x.notification_type == "sms" and x.status in [
"technical-failure",
"temporary-failure",
"permanent-failure",
]:
sql = text(
"update notification_statistics set sms_requested = sms_requested + 1, "
"sms_failed = sms_failed + 1 where day = date(:created) and service_id = :service_id"
)
if x.notification_type == "email" and x.status in [
"created",
"sending",
"pending",
]:
sql = text(
"update notification_statistics set emails_requested = emails_requested + 1 "
" where day = date(:created) and service_id = :service_id"
)
if x.notification_type == "sms" and x.status in [
"created",
"sending",
"pending",
]:
sql = text(
"update notification_statistics set sms_requested = sms_requested + 1 "
" where day = date(:created) and service_id = :service_id"
)
print(sql)
conn.execute(sql)
conn.execute(sql, input_params)
def downgrade():
### commands auto generated by Alembic - please adjust! ###

View File

@@ -1,38 +0,0 @@
"""mmg rates now set to 1.65 pence per sms
Revision ID: 0040_adjust_mmg_provider_rate
Revises: 0039_fix_notifications
Create Date: 2016-07-06 15:19:23.124212
"""
# revision identifiers, used by Alembic.
revision = '0040_adjust_mmg_provider_rate'
down_revision = '0039_fix_notifications'
import uuid
from datetime import datetime
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
conn.execute(
sa.sql.text(("INSERT INTO provider_rates (id, valid_from, rate, provider_id) "
"VALUES (:id, :valid_from, :rate, (SELECT id FROM provider_details WHERE identifier = 'mmg'))")),
id=uuid.uuid4(),
valid_from=datetime(2016, 7, 1),
rate=1.65
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
conn.execute(("DELETE FROM provider_rates "
"WHERE provider_id = (SELECT id FROM provider_details WHERE identifier = 'mmg') "
"AND rate = 1.65"))
### end Alembic commands ###

View File

@@ -1,66 +0,0 @@
"""empty message
Revision ID: 0041_email_template
Revises: 0040_adjust_mmg_provider_rate
Create Date: 2016-07-07 16:02:06.241769
"""
# revision identifiers, used by Alembic.
from datetime import datetime
revision = '0041_email_template'
down_revision = '0040_adjust_mmg_provider_rate'
from alembic import op
user_id = '6af522d0-2915-4e52-83a3-3690455a5fe6'
service_id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
def upgrade():
template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at,
content, archived, service_id,
subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
"""
template_insert = """INSERT INTO templates (id, name, template_type, created_at,
content, archived, service_id, subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
"""
content = """You already have a GOV.UK Notify account with this email address.
Sign in here: ((signin_url))
If youve forgotten your password, you can reset it here: ((forgot_password_url))
If you didnt try to register for a GOV.UK Notify account recently, please let us know here: ((feedback_url))"""
op.get_bind()
op.execute(template_history_insert.format('0880fbb1-a0c6-46f0-9a8e-36c986381ceb',
'Your GOV.UK Notify account', 'email',
datetime.utcnow(), content, service_id,
'Your GOV.UK Notify account', user_id))
op.execute(
template_insert.format('0880fbb1-a0c6-46f0-9a8e-36c986381ceb', 'Your GOV.UK Notify account', 'email',
datetime.utcnow(), content, service_id,
'Your GOV.UK Notify account', user_id))
# If you are copying this migration, please remember about an insert to TemplateRedacted,
# which was not originally included here either by mistake or because it was before TemplateRedacted existed
# op.execute(
# """
# INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id)
# VALUES ('0880fbb1-a0c6-46f0-9a8e-36c986381ceb', '{}', '{}', '{}')
# ;
# """.format(False, datetime.utcnow(), user_id)
# )
def downgrade():
op.execute("delete from notifications where template_id = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'")
op.execute("delete from jobs where template_id = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'")
op.execute("delete from template_statistics where template_id = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'")
op.execute("delete from templates_history where id = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'")
op.execute("delete from templates where id = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'")

View File

@@ -1,53 +1,122 @@
"""empty message
Revision ID: 0042_notification_history
Revises: 0041_email_template
Revises: 0039_fix_notifications
Create Date: 2016-07-07 13:15:35.503107
"""
# revision identifiers, used by Alembic.
revision = '0042_notification_history'
down_revision = '0041_email_template'
revision = "0042_notification_history"
down_revision = "0039_fix_notifications"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('notification_history',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('job_row_number', sa.Integer(), nullable=True),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('template_version', sa.Integer(), nullable=False),
sa.Column('api_key_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('key_type', sa.String(), nullable=False),
sa.Column('content_char_count', sa.Integer(), nullable=True),
sa.Column('notification_type', postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('sent_at', sa.DateTime(), nullable=True),
sa.Column('sent_by', sa.String(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('status', postgresql.ENUM('created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure', 'temporary-failure', 'permanent-failure', name='notify_status_type', create_type=False), nullable=False),
sa.Column('reference', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['api_key_id'], ['api_keys.id'], ),
sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ),
sa.ForeignKeyConstraint(['key_type'], ['key_types.name'], ),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"notification_history",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("job_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("job_row_number", sa.Integer(), nullable=True),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("template_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("template_version", sa.Integer(), nullable=False),
sa.Column("api_key_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("key_type", sa.String(), nullable=False),
sa.Column("content_char_count", sa.Integer(), nullable=True),
sa.Column(
"notification_type",
postgresql.ENUM(
"email", "sms", "letter", name="notification_type", create_type=False
),
nullable=False,
),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("sent_at", sa.DateTime(), nullable=True),
sa.Column("sent_by", sa.String(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column(
"status",
postgresql.ENUM(
"created",
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
name="notify_status_type",
create_type=False,
),
nullable=False,
),
sa.Column("reference", sa.String(), nullable=True),
sa.ForeignKeyConstraint(
["api_key_id"],
["api_keys.id"],
),
sa.ForeignKeyConstraint(
["job_id"],
["jobs.id"],
),
sa.ForeignKeyConstraint(
["key_type"],
["key_types.name"],
),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["template_id"],
["templates.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_notification_history_api_key_id"),
"notification_history",
["api_key_id"],
unique=False,
)
op.create_index(
op.f("ix_notification_history_job_id"),
"notification_history",
["job_id"],
unique=False,
)
op.create_index(
op.f("ix_notification_history_key_type"),
"notification_history",
["key_type"],
unique=False,
)
op.create_index(
op.f("ix_notification_history_reference"),
"notification_history",
["reference"],
unique=False,
)
op.create_index(
op.f("ix_notification_history_service_id"),
"notification_history",
["service_id"],
unique=False,
)
op.create_index(
op.f("ix_notification_history_template_id"),
"notification_history",
["template_id"],
unique=False,
)
op.create_index(op.f('ix_notification_history_api_key_id'), 'notification_history', ['api_key_id'], unique=False)
op.create_index(op.f('ix_notification_history_job_id'), 'notification_history', ['job_id'], unique=False)
op.create_index(op.f('ix_notification_history_key_type'), 'notification_history', ['key_type'], unique=False)
op.create_index(op.f('ix_notification_history_reference'), 'notification_history', ['reference'], unique=False)
op.create_index(op.f('ix_notification_history_service_id'), 'notification_history', ['service_id'], unique=False)
op.create_index(op.f('ix_notification_history_template_id'), 'notification_history', ['template_id'], unique=False)
op.execute('''
op.execute(
"""
INSERT INTO notification_history
(
id,
@@ -85,17 +154,30 @@ def upgrade():
status,
reference
FROM notifications
''')
"""
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_notification_history_template_id'), table_name='notification_history')
op.drop_index(op.f('ix_notification_history_service_id'), table_name='notification_history')
op.drop_index(op.f('ix_notification_history_reference'), table_name='notification_history')
op.drop_index(op.f('ix_notification_history_key_type'), table_name='notification_history')
op.drop_index(op.f('ix_notification_history_job_id'), table_name='notification_history')
op.drop_index(op.f('ix_notification_history_api_key_id'), table_name='notification_history')
op.drop_table('notification_history')
op.drop_index(
op.f("ix_notification_history_template_id"), table_name="notification_history"
)
op.drop_index(
op.f("ix_notification_history_service_id"), table_name="notification_history"
)
op.drop_index(
op.f("ix_notification_history_reference"), table_name="notification_history"
)
op.drop_index(
op.f("ix_notification_history_key_type"), table_name="notification_history"
)
op.drop_index(
op.f("ix_notification_history_job_id"), table_name="notification_history"
)
op.drop_index(
op.f("ix_notification_history_api_key_id"), table_name="notification_history"
)
op.drop_table("notification_history")
### end Alembic commands ###

View File

@@ -7,38 +7,65 @@ Create Date: 2016-08-01 10:37:41.198070
"""
# revision identifiers, used by Alembic.
revision = '0043_notification_indexes'
down_revision = '0042_notification_history'
revision = "0043_notification_indexes"
down_revision = "0042_notification_history"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_index(op.f('ix_notifications_created_at'), 'notifications', ['created_at'])
op.create_index(op.f('ix_notification_history_created_at'), 'notification_history', ['created_at'])
op.create_index(
op.f("ix_notifications_created_at"), "notifications", ["created_at"]
)
op.create_index(
op.f("ix_notification_history_created_at"),
"notification_history",
["created_at"],
)
op.create_index(op.f('ix_notifications_status'), 'notifications', ['status'])
op.create_index(op.f('ix_notification_history_status'), 'notification_history', ['status'])
op.create_index(op.f('ix_notifications_notification_type'), 'notifications', ['notification_type'])
op.create_index(op.f('ix_notification_history_notification_type'), 'notification_history', ['notification_type'])
op.create_index(op.f("ix_notifications_status"), "notifications", ["status"])
op.create_index(
op.f("ix_notification_history_status"), "notification_history", ["status"]
)
op.create_index(
'ix_notification_history_week_created',
'notification_history',
[sa.text("date_trunc('week', created_at)")]
op.f("ix_notifications_notification_type"),
"notifications",
["notification_type"],
)
op.create_index(
op.f("ix_notification_history_notification_type"),
"notification_history",
["notification_type"],
)
op.create_index(
"ix_notification_history_week_created",
"notification_history",
[sa.text("date_trunc('week', created_at)")],
)
def downgrade():
op.drop_index(op.f('ix_notifications_created_at'), table_name='notifications')
op.drop_index(op.f('ix_notification_history_created_at'), table_name='notification_history')
op.drop_index(op.f("ix_notifications_created_at"), table_name="notifications")
op.drop_index(
op.f("ix_notification_history_created_at"), table_name="notification_history"
)
op.drop_index(op.f('ix_notifications_status'), table_name='notifications')
op.drop_index(op.f('ix_notification_history_status'), table_name='notification_history')
op.drop_index(op.f("ix_notifications_status"), table_name="notifications")
op.drop_index(
op.f("ix_notification_history_status"), table_name="notification_history"
)
op.drop_index(op.f('ix_notifications_notification_type'), table_name='notifications')
op.drop_index(op.f('ix_notification_history_notification_type'), table_name='notification_history')
op.drop_index(
op.f("ix_notifications_notification_type"), table_name="notifications"
)
op.drop_index(
op.f("ix_notification_history_notification_type"),
table_name="notification_history",
)
op.drop_index(op.f('ix_notification_history_week_created'), table_name='notification_history')
op.drop_index(
op.f("ix_notification_history_week_created"), table_name="notification_history"
)

View File

@@ -7,8 +7,8 @@ Create Date: 2016-07-15 13:28:41.441009
"""
# revision identifiers, used by Alembic.
revision = '0044_jobs_to_notification_hist'
down_revision = '0043_notification_indexes'
revision = "0044_jobs_to_notification_hist"
down_revision = "0043_notification_indexes"
from alembic import op

View File

@@ -7,8 +7,10 @@ Create Date: 2016-08-02 16:36:42.455838
"""
# revision identifiers, used by Alembic.
revision = '0045_billable_units'
down_revision = '0044_jobs_to_notification_hist'
from sqlalchemy import text, bindparam
revision = "0045_billable_units"
down_revision = "0044_jobs_to_notification_hist"
from alembic import op
import sqlalchemy as sa
@@ -16,31 +18,32 @@ from sqlalchemy.orm.session import Session
from app.models import Service
def upgrade():
op.add_column('notifications', sa.Column('billable_units', sa.Integer()))
op.add_column('notification_history', sa.Column('billable_units', sa.Integer()))
op.add_column("notifications", sa.Column("billable_units", sa.Integer()))
op.add_column("notification_history", sa.Column("billable_units", sa.Integer()))
op.execute('update notifications set billable_units = 0')
op.execute('update notification_history set billable_units = 0')
op.alter_column('notifications', 'billable_units', nullable=False)
op.alter_column('notification_history', 'billable_units', nullable=False)
op.execute("update notifications set billable_units = 0")
op.execute("update notification_history set billable_units = 0")
op.alter_column("notifications", "billable_units", nullable=False)
op.alter_column("notification_history", "billable_units", nullable=False)
conn = op.get_bind()
# caveats
# only adjusts notifications for services that have never been in research mode. On live, research mode was
# limited to only services that we have set up ourselves so deemed this acceptable.
billable_services = conn.execute('''
billable_services = conn.execute(
"""
SELECT id FROM services_history WHERE id not in (select id from services_history where research_mode)
''')
"""
)
# set to 'null' if there are no billable services so we don't get a syntax error in the update statement
service_ids = ','.join("'{}'".format(service.id) for service in billable_services) or 'null'
service_ids = ",".join(f"{service.id}" for service in billable_services) or "null"
update_statement = '''
UPDATE {}
update_statement_n = """
UPDATE notifications
SET billable_units = (
CASE
WHEN content_char_count <= 160 THEN 1
@@ -48,29 +51,49 @@ def upgrade():
END
)
WHERE content_char_count is not null
AND service_id in ({})
AND service_id in (:service_ids)
AND notification_type = 'sms'
'''
"""
update_statement_nh = """
UPDATE notification_history
SET billable_units = (
CASE
WHEN content_char_count <= 160 THEN 1
ELSE ceil(content_char_count::float / 153::float)
END
)
WHERE content_char_count is not null
AND service_id in (:service_ids)
AND notification_type = 'sms'
"""
conn = op.get_bind()
conn.execute(update_statement.format('notifications', service_ids))
conn.execute(update_statement.format('notification_history', service_ids))
op.drop_column('notifications', 'content_char_count')
op.drop_column('notification_history', 'content_char_count')
query = text(update_statement_n).bindparams(
bindparam("service_ids", expanding=False)
)
conn.execute(query, service_ids=service_ids)
query = text(update_statement_nh).bindparams(
bindparam("service_ids", expanding=False)
)
conn.execute(query, service_ids=service_ids)
op.drop_column("notifications", "content_char_count")
op.drop_column("notification_history", "content_char_count")
def downgrade():
op.add_column('notifications', sa.Column(
'content_char_count',
sa.INTEGER(),
autoincrement=False,
nullable=True)
op.add_column(
"notifications",
sa.Column(
"content_char_count", sa.INTEGER(), autoincrement=False, nullable=True
),
)
op.add_column('notification_history', sa.Column(
'content_char_count',
sa.INTEGER(),
autoincrement=False,
nullable=True)
op.add_column(
"notification_history",
sa.Column(
"content_char_count", sa.INTEGER(), autoincrement=False, nullable=True
),
)
conn = op.get_bind()
@@ -78,24 +101,40 @@ def downgrade():
# caveats
# only adjusts notifications for services that have never been in research mode. On live, research mode was
# limited to only services that we have set up ourselves
billable_services = conn.execute('''
billable_services = conn.execute(
"""
SELECT id FROM services_history WHERE id not in (select id from services_history where research_mode)
''')
"""
)
# set to 'null' if there are no billable services so we don't get a syntax error in the update statement
service_ids = ','.join("'{}'".format(service.id) for service in billable_services) or 'null'
service_ids = ",".join(f"{service.id}" for service in billable_services) or "null"
# caveats:
# only approximates character counts - billable * 153 to get at least a decent ballpark
# research mode messages assumed to be one message length
update_statement = '''
UPDATE {}
update_statement_n = """
UPDATE notifications
SET content_char_count = GREATEST(billable_units, 1) * 150
WHERE service_id in ({})
WHERE service_id in (:service_ids)
AND notification_type = 'sms'
'''
"""
update_statement_nh = """
UPDATE notification_history
SET content_char_count = GREATEST(billable_units, 1) * 150
WHERE service_id in (:service_ids)
AND notification_type = 'sms'
"""
conn = op.get_bind()
conn.execute(update_statement.format('notifications', service_ids))
conn.execute(update_statement.format('notification_history', service_ids))
op.drop_column('notifications', 'billable_units')
op.drop_column('notification_history', 'billable_units')
query = text(update_statement_n).bindparams(
bindparam("service_ids", expanding=False)
)
conn.execute(query, service_ids=service_ids)
query = text(update_statement_nh).bindparams(
bindparam("service_ids", expanding=False)
)
conn.execute(query, service_ids=service_ids)
op.drop_column("notifications", "billable_units")
op.drop_column("notification_history", "billable_units")

View File

@@ -7,59 +7,85 @@ Create Date: 2016-08-04 12:00:43.682610
"""
# revision identifiers, used by Alembic.
revision = '0046_organisations_and_branding'
down_revision = '0045_billable_units'
revision = "0046_organisations_and_branding"
down_revision = "0045_billable_units"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table('branding_type',
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('name')
op.create_table(
"branding_type",
sa.Column("name", sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint("name"),
)
op.create_table('organisation',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('colour', sa.String(length=7), nullable=True),
sa.Column('logo', sa.String(length=255), nullable=True),
sa.Column('name', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
op.create_table(
"organisation",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("colour", sa.String(length=7), nullable=True),
sa.Column("logo", sa.String(length=255), nullable=True),
sa.Column("name", sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.add_column('services', sa.Column('branding', sa.String(length=255)))
op.add_column('services', sa.Column('organisation_id', postgresql.UUID(as_uuid=True)))
op.add_column('services_history', sa.Column('branding', sa.String(length=255)))
op.add_column('services_history', sa.Column('organisation_id', postgresql.UUID(as_uuid=True)))
op.add_column("services", sa.Column("branding", sa.String(length=255)))
op.add_column(
"services", sa.Column("organisation_id", postgresql.UUID(as_uuid=True))
)
op.add_column("services_history", sa.Column("branding", sa.String(length=255)))
op.add_column(
"services_history", sa.Column("organisation_id", postgresql.UUID(as_uuid=True))
)
op.execute("INSERT INTO branding_type VALUES ('govuk'), ('org'), ('both')")
# insert UKVI data as initial test data. hex and crest pulled from alphagov/whitehall
op.execute("""INSERT INTO organisation VALUES (
op.execute(
"""INSERT INTO organisation VALUES (
'9d25d02d-2915-4e98-874b-974e123e8536',
'#9325b2',
'ho_crest_27px_x2.png',
'UK Visas and Immigration'
)""")
)"""
)
op.execute("UPDATE services SET branding='govuk'")
op.execute("UPDATE services_history SET branding='govuk'")
op.alter_column('services', 'branding', nullable=False)
op.alter_column('services_history', 'branding', nullable=False)
op.alter_column("services", "branding", nullable=False)
op.alter_column("services_history", "branding", nullable=False)
op.create_index(op.f('ix_services_branding'), 'services', ['branding'], unique=False)
op.create_index(op.f('ix_services_organisation_id'), 'services', ['organisation_id'], unique=False)
op.create_index(op.f('ix_services_history_branding'), 'services_history', ['branding'], unique=False)
op.create_index(op.f('ix_services_history_organisation_id'), 'services_history', ['organisation_id'], unique=False)
op.create_index(
op.f("ix_services_branding"), "services", ["branding"], unique=False
)
op.create_index(
op.f("ix_services_organisation_id"),
"services",
["organisation_id"],
unique=False,
)
op.create_index(
op.f("ix_services_history_branding"),
"services_history",
["branding"],
unique=False,
)
op.create_index(
op.f("ix_services_history_organisation_id"),
"services_history",
["organisation_id"],
unique=False,
)
op.create_foreign_key(None, 'services', 'branding_type', ['branding'], ['name'])
op.create_foreign_key(None, 'services', 'organisation', ['organisation_id'], ['id'])
op.create_foreign_key(None, "services", "branding_type", ["branding"], ["name"])
op.create_foreign_key(None, "services", "organisation", ["organisation_id"], ["id"])
def downgrade():
op.drop_column('services_history', 'organisation_id')
op.drop_column('services_history', 'branding')
op.drop_column('services', 'organisation_id')
op.drop_column('services', 'branding')
op.drop_table('organisation')
op.drop_table('branding_type')
op.drop_column("services_history", "organisation_id")
op.drop_column("services_history", "branding")
op.drop_column("services", "organisation_id")
op.drop_column("services", "branding")
op.drop_table("organisation")
op.drop_table("branding_type")

View File

@@ -1,29 +0,0 @@
"""empty message
Revision ID: 0047_ukvi_spelling
Revises: 0046_organisations_and_branding
Create Date: 2016-08-22 16:06:32.981723
"""
# revision identifiers, used by Alembic.
revision = '0047_ukvi_spelling'
down_revision = '0046_organisations_and_branding'
from alembic import op
def upgrade():
op.execute("""
UPDATE organisation
SET name = 'UK Visas & Immigration'
WHERE id = '9d25d02d-2915-4e98-874b-974e123e8536'
""")
def downgrade():
op.execute("""
UPDATE organisation
SET name = 'UK Visas and Immigration'
WHERE id = '9d25d02d-2915-4e98-874b-974e123e8536'
""")

View File

@@ -1,29 +1,32 @@
"""empty message
Revision ID: 0048_job_scheduled_time
Revises: 0047_ukvi_spelling
Revises: 0046_organisations_and_branding
Create Date: 2016-08-24 13:21:51.744526
"""
# revision identifiers, used by Alembic.
revision = '0048_job_scheduled_time'
down_revision = '0047_ukvi_spelling'
revision = "0048_job_scheduled_time"
down_revision = "0046_organisations_and_branding"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('job_status',
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('name')
op.create_table(
"job_status",
sa.Column("name", sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint("name"),
)
op.add_column('jobs', sa.Column('job_status', sa.String(length=255), nullable=True))
op.add_column('jobs', sa.Column('scheduled_for', sa.DateTime(), nullable=True))
op.create_index(op.f('ix_jobs_job_status'), 'jobs', ['job_status'], unique=False)
op.create_index(op.f('ix_jobs_scheduled_for'), 'jobs', ['scheduled_for'], unique=False)
op.create_foreign_key(None, 'jobs', 'job_status', ['job_status'], ['name'])
op.add_column("jobs", sa.Column("job_status", sa.String(length=255), nullable=True))
op.add_column("jobs", sa.Column("scheduled_for", sa.DateTime(), nullable=True))
op.create_index(op.f("ix_jobs_job_status"), "jobs", ["job_status"], unique=False)
op.create_index(
op.f("ix_jobs_scheduled_for"), "jobs", ["scheduled_for"], unique=False
)
op.create_foreign_key(None, "jobs", "job_status", ["job_status"], ["name"])
op.execute("insert into job_status values ('pending')")
op.execute("insert into job_status values ('in progress')")
@@ -33,9 +36,9 @@ def upgrade():
def downgrade():
op.drop_constraint('jobs_job_status_fkey', 'jobs', type_='foreignkey')
op.drop_index(op.f('ix_jobs_scheduled_for'), table_name='jobs')
op.drop_index(op.f('ix_jobs_job_status'), table_name='jobs')
op.drop_column('jobs', 'scheduled_for')
op.drop_column('jobs', 'job_status')
op.drop_table('job_status')
op.drop_constraint("jobs_job_status_fkey", "jobs", type_="foreignkey")
op.drop_index(op.f("ix_jobs_scheduled_for"), table_name="jobs")
op.drop_index(op.f("ix_jobs_job_status"), table_name="jobs")
op.drop_column("jobs", "scheduled_for")
op.drop_column("jobs", "job_status")
op.drop_table("job_status")

View File

@@ -7,8 +7,8 @@ Create Date: 2016-08-24 13:21:51.744526
"""
# revision identifiers, used by Alembic.
revision = '0050_index_for_stats'
down_revision = '0048_job_scheduled_time'
revision = "0050_index_for_stats"
down_revision = "0048_job_scheduled_time"
from alembic import op
import sqlalchemy as sa
@@ -16,16 +16,22 @@ import sqlalchemy as sa
def upgrade():
op.create_index(
'ix_notifications_service_id_created_at',
'notifications',
['service_id', sa.text("date(created_at)")]
"ix_notifications_service_id_created_at",
"notifications",
["service_id", sa.text("date(created_at)")],
)
op.create_index(
'ix_notification_history_service_id_created_at',
'notification_history',
['service_id', sa.text("date(created_at)")]
"ix_notification_history_service_id_created_at",
"notification_history",
["service_id", sa.text("date(created_at)")],
)
def downgrade():
op.drop_index(op.f('ix_notifications_service_id_created_at'), table_name='notifications')
op.drop_index(op.f('ix_notification_history_service_id_created_at'), table_name='notification_history')
op.drop_index(
op.f("ix_notifications_service_id_created_at"), table_name="notifications"
)
op.drop_index(
op.f("ix_notification_history_service_id_created_at"),
table_name="notification_history",
)

View File

@@ -7,8 +7,8 @@ Create Date: 2016-08-24 13:21:51.744526
"""
# revision identifiers, used by Alembic.
revision = '0051_set_job_status'
down_revision = '0050_index_for_stats'
revision = "0051_set_job_status"
down_revision = "0050_index_for_stats"
from alembic import op

View File

@@ -7,8 +7,8 @@ Create Date: 2016-08-25 15:56:31.779399
"""
# revision identifiers, used by Alembic.
revision = '0052_drop_jobs_status'
down_revision = '0051_set_job_status'
revision = "0052_drop_jobs_status"
down_revision = "0051_set_job_status"
from alembic import op
import sqlalchemy as sa
@@ -16,11 +16,19 @@ from sqlalchemy.dialects import postgresql
def upgrade():
op.alter_column('jobs', 'job_status', existing_type=sa.VARCHAR(length=255), nullable=False)
op.alter_column('jobs', 'status', existing_type=sa.VARCHAR(length=255), nullable=True)
op.alter_column(
"jobs", "job_status", existing_type=sa.VARCHAR(length=255), nullable=False
)
op.alter_column(
"jobs", "status", existing_type=sa.VARCHAR(length=255), nullable=True
)
def downgrade():
# this downgrade leaves status empty and with no not null constraint.
op.alter_column('jobs', 'status', existing_type=sa.VARCHAR(length=255), nullable=False)
op.alter_column('jobs', 'job_status', existing_type=sa.VARCHAR(length=255), nullable=True)
op.alter_column(
"jobs", "status", existing_type=sa.VARCHAR(length=255), nullable=False
)
op.alter_column(
"jobs", "job_status", existing_type=sa.VARCHAR(length=255), nullable=True
)

View File

@@ -7,16 +7,18 @@ Create Date: 2016-09-01 14:34:06.839381
"""
# revision identifiers, used by Alembic.
revision = '0053_cancelled_job_status'
down_revision = '0052_drop_jobs_status'
revision = "0053_cancelled_job_status"
down_revision = "0052_drop_jobs_status"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.execute("INSERT INTO job_status VALUES ('cancelled')")
def downgrade():
op.execute("UPDATE jobs SET job_status = 'finished' WHERE job_status = 'cancelled'")
op.execute("DELETE FROM job_status WHERE name = 'cancelled';")

View File

@@ -7,8 +7,8 @@ Create Date: 2016-08-25 15:56:31.779399
"""
# revision identifiers, used by Alembic.
revision = '0054_perform_drop_status_column'
down_revision = '0053_cancelled_job_status'
revision = "0054_perform_drop_status_column"
down_revision = "0053_cancelled_job_status"
from alembic import op
import sqlalchemy as sa
@@ -16,8 +16,22 @@ from sqlalchemy.dialects import postgresql
def upgrade():
op.drop_column('jobs', 'status')
op.drop_column("jobs", "status")
def downgrade():
op.add_column('jobs', sa.Column('status', postgresql.ENUM('pending', 'in progress', 'finished', 'sending limits exceeded', name='job_status_types'), autoincrement=False, nullable=True))
op.add_column(
"jobs",
sa.Column(
"status",
postgresql.ENUM(
"pending",
"in progress",
"finished",
"sending limits exceeded",
name="job_status_types",
),
autoincrement=False,
nullable=True,
),
)

View File

@@ -7,25 +7,39 @@ Create Date: 2016-09-20 12:12:30.838095
"""
# revision identifiers, used by Alembic.
revision = '0055_service_whitelist'
down_revision = '0054_perform_drop_status_column'
revision = "0055_service_whitelist"
down_revision = "0054_perform_drop_status_column"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table('service_whitelist',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('recipient_type', sa.Enum('mobile', 'email', name='recipient_type'), nullable=False),
sa.Column('recipient', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"service_whitelist",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column(
"recipient_type",
sa.Enum("mobile", "email", name="recipient_type"),
nullable=False,
),
sa.Column("recipient", sa.String(length=255), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_service_whitelist_service_id"),
"service_whitelist",
["service_id"],
unique=False,
)
op.create_index(op.f('ix_service_whitelist_service_id'), 'service_whitelist', ['service_id'], unique=False)
def downgrade():
op.drop_table('service_whitelist')
op.drop_table("service_whitelist")

View File

@@ -7,8 +7,8 @@ Create Date: 2016-10-04 09:43:42.321138
"""
# revision identifiers, used by Alembic.
revision = '0056_minor_updates'
down_revision = '0055_service_whitelist'
revision = "0056_minor_updates"
down_revision = "0055_service_whitelist"
from alembic import op
import sqlalchemy as sa
@@ -16,31 +16,53 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('service_whitelist', 'recipient',
existing_type=sa.VARCHAR(length=255),
nullable=False)
op.alter_column('services', 'research_mode',
existing_type=sa.BOOLEAN(),
nullable=False)
op.alter_column('services_history', 'research_mode',
existing_type=sa.BOOLEAN(),
nullable=False)
op.create_foreign_key('templates_history_service_id_fkey', 'templates_history', 'services', ['service_id'], ['id'])
op.create_foreign_key('templates_history_created_by_id_fkey', 'templates_history', 'users', ['created_by_id'], ['id'])
op.alter_column(
"service_whitelist",
"recipient",
existing_type=sa.VARCHAR(length=255),
nullable=False,
)
op.alter_column(
"services", "research_mode", existing_type=sa.BOOLEAN(), nullable=False
)
op.alter_column(
"services_history", "research_mode", existing_type=sa.BOOLEAN(), nullable=False
)
op.create_foreign_key(
"templates_history_service_id_fkey",
"templates_history",
"services",
["service_id"],
["id"],
)
op.create_foreign_key(
"templates_history_created_by_id_fkey",
"templates_history",
"users",
["created_by_id"],
["id"],
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('templates_history_service_id_fkey', 'templates_history', type_='foreignkey')
op.drop_constraint('templates_history_created_by_id_fkey', 'templates_history', type_='foreignkey')
op.alter_column('services_history', 'research_mode',
existing_type=sa.BOOLEAN(),
nullable=True)
op.alter_column('services', 'research_mode',
existing_type=sa.BOOLEAN(),
nullable=True)
op.alter_column('service_whitelist', 'recipient',
existing_type=sa.VARCHAR(length=255),
nullable=True)
op.drop_constraint(
"templates_history_service_id_fkey", "templates_history", type_="foreignkey"
)
op.drop_constraint(
"templates_history_created_by_id_fkey", "templates_history", type_="foreignkey"
)
op.alter_column(
"services_history", "research_mode", existing_type=sa.BOOLEAN(), nullable=True
)
op.alter_column(
"services", "research_mode", existing_type=sa.BOOLEAN(), nullable=True
)
op.alter_column(
"service_whitelist",
"recipient",
existing_type=sa.VARCHAR(length=255),
nullable=True,
)
### end Alembic commands ###

View File

@@ -1,67 +0,0 @@
"""empty message
Revision ID: 0057_change_email_template
Revises: 0056_minor_updates
Create Date: 2016-10-11 09:24:45.669018
"""
# revision identifiers, used by Alembic.
from datetime import datetime
from alembic import op
revision = '0057_change_email_template'
down_revision = '0056_minor_updates'
user_id = '6af522d0-2915-4e52-83a3-3690455a5fe6'
service_id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
template_id = 'eb4d9930-87ab-4aef-9bce-786762687884'
def upgrade():
template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at,
content, archived, service_id,
subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
"""
template_insert = """INSERT INTO templates (id, name, template_type, created_at,
content, archived, service_id, subject, created_by_id, version)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1)
"""
template_content = \
"""Hi ((name)),\n\nClick this link to confirm your new email address:
\n\n((url))
\n\nIf you didnt try to change the email address for your GOV.UK Notify account, let us know here:
\n\n((feedback_url))"""
template_name = 'Confirm new email address'
op.execute(template_history_insert.format(template_id,
template_name,
'email',
datetime.utcnow(), template_content,
service_id,
template_name, user_id))
op.execute(template_insert.format(template_id,
template_name,
'email',
datetime.utcnow(),
template_content,
service_id,
template_name, user_id))
# If you are copying this migration, please remember about an insert to TemplateRedacted,
# which was not originally included here either by mistake or because it was before TemplateRedacted existed
# op.execute(
# """
# INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id)
# VALUES ('{}', '{}', '{}', '{}')
# ;
# """.format(template_id, False, datetime.utcnow(), user_id)
# )
def downgrade():
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id))
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id))
op.execute("delete from templates_history where id = '{}'".format(template_id))
op.execute("delete from templates where id = '{}'".format(template_id))

View File

@@ -1,24 +1,34 @@
"""empty message
Revision ID: 0058_add_letters_flag
Revises: 0057_change_email_template
Revises: 0056_minor_updates
Create Date: 2016-10-25 17:37:27.660723
"""
# revision identifiers, used by Alembic.
revision = '0058_add_letters_flag'
down_revision = '0057_change_email_template'
revision = "0058_add_letters_flag"
down_revision = "0056_minor_updates"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('services', sa.Column('can_send_letters', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('services_history', sa.Column('can_send_letters', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column(
"services",
sa.Column(
"can_send_letters", sa.Boolean(), nullable=False, server_default=sa.false()
),
)
op.add_column(
"services_history",
sa.Column(
"can_send_letters", sa.Boolean(), nullable=False, server_default=sa.false()
),
)
def downgrade():
op.drop_column('services_history', 'can_send_letters')
op.drop_column('services', 'can_send_letters')
op.drop_column("services_history", "can_send_letters")
op.drop_column("services", "can_send_letters")

View File

@@ -9,15 +9,15 @@ Create Date: 2016-10-31 15:17:16.716450
"""
# revision identifiers, used by Alembic.
revision = '0059_set_services_to_active'
down_revision = '0058_add_letters_flag'
revision = "0059_set_services_to_active"
down_revision = "0058_add_letters_flag"
from alembic import op
def upgrade():
op.execute('UPDATE services SET active = TRUE')
op.execute("UPDATE services SET active = TRUE")
def downgrade():
op.execute('UPDATE services SET active = FALSE')
op.execute("UPDATE services SET active = FALSE")

View File

@@ -10,47 +10,52 @@ from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0060_add_letter_template_type'
down_revision = '0059_set_services_to_active'
revision = "0060_add_letter_template_type"
down_revision = "0059_set_services_to_active"
name = 'template_type'
tmp_name = 'tmp_' + name
name = "template_type"
tmp_name = "tmp_" + name
old_options = ('sms', 'email')
new_options = old_options + ('letter',)
old_options = ("sms", "email")
new_options = old_options + ("letter",)
new_type = sa.Enum(*new_options, name=name)
old_type = sa.Enum(*old_options, name=name)
tcr = sa.sql.table(
'templates',
sa.Column('template_type', new_type, nullable=False)
)
tcr = sa.sql.table("templates", sa.Column("template_type", new_type, nullable=False))
def upgrade():
op.execute('ALTER TYPE ' + name + ' RENAME TO ' + tmp_name)
op.execute("ALTER TYPE " + name + " RENAME TO " + tmp_name)
new_type.create(op.get_bind())
op.execute(
'ALTER TABLE templates ALTER COLUMN template_type ' +
'TYPE ' + name + ' USING template_type::text::' + name
"ALTER TABLE templates ALTER COLUMN template_type "
+ "TYPE "
+ name
+ " USING template_type::text::"
+ name
)
op.execute('DROP TYPE ' + tmp_name)
op.execute("DROP TYPE " + tmp_name)
def downgrade():
# Convert 'letter' template into 'email'
op.execute(
tcr.update().where(tcr.c.template_type=='letter').values(template_type='email')
tcr.update()
.where(tcr.c.template_type == "letter")
.values(template_type="email")
)
op.execute('ALTER TYPE ' + name + ' RENAME TO ' + tmp_name)
op.execute("ALTER TYPE " + name + " RENAME TO " + tmp_name)
old_type.create(op.get_bind())
op.execute(
'ALTER TABLE templates ALTER COLUMN template_type ' +
'TYPE ' + name + ' USING template_type::text::' + name
"ALTER TABLE templates ALTER COLUMN template_type "
+ "TYPE "
+ name
+ " USING template_type::text::"
+ name
)
op.execute('DROP TYPE ' + tmp_name)
op.execute("DROP TYPE " + tmp_name)

View File

@@ -7,18 +7,24 @@ Create Date: 2016-11-17 13:19:25.820617
"""
# revision identifiers, used by Alembic.
revision = '0061_add_client_reference'
down_revision = '0060_add_letter_template_type'
revision = "0061_add_client_reference"
down_revision = "0060_add_letter_template_type"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('notifications', sa.Column('client_reference', sa.String(), index=True, nullable=True))
op.add_column('notification_history', sa.Column('client_reference', sa.String(), nullable=True))
op.add_column(
"notifications",
sa.Column("client_reference", sa.String(), index=True, nullable=True),
)
op.add_column(
"notification_history",
sa.Column("client_reference", sa.String(), nullable=True),
)
def downgrade():
op.drop_column('notifications', 'client_reference')
op.drop_column('notification_history', 'client_reference')
op.drop_column("notifications", "client_reference")
op.drop_column("notification_history", "client_reference")

View File

@@ -10,45 +10,55 @@ Create Date: 2016-12-14 13:00:24.226990
"""
# revision identifiers, used by Alembic.
revision = '0062_provider_details_history'
down_revision = '0061_add_client_reference'
revision = "0062_provider_details_history"
down_revision = "0061_add_client_reference"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.get_bind()
op.add_column('provider_details', sa.Column('updated_at', sa.DateTime()))
op.add_column("provider_details", sa.Column("updated_at", sa.DateTime()))
op.execute('UPDATE provider_details SET active = false WHERE active is null')
op.alter_column('provider_details', 'active', nullable=False)
op.execute("UPDATE provider_details SET active = false WHERE active is null")
op.alter_column("provider_details", "active", nullable=False)
op.add_column('provider_details', sa.Column('version', sa.Integer(), nullable=True))
op.execute('UPDATE provider_details SET version = 1')
op.alter_column('provider_details', 'version', nullable=False)
op.add_column("provider_details", sa.Column("version", sa.Integer(), nullable=True))
op.execute("UPDATE provider_details SET version = 1")
op.alter_column("provider_details", "version", nullable=False)
op.create_table('provider_details_history',
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', postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False), nullable=False),
sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('version', sa.Integer(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', 'version')
op.create_table(
"provider_details_history",
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",
postgresql.ENUM(
"email", "sms", "letter", name="notification_type", create_type=False
),
nullable=False,
),
sa.Column("active", sa.Boolean(), nullable=False),
sa.Column("version", sa.Integer(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id", "version"),
)
op.execute(
'INSERT INTO provider_details_history' +
' (id, display_name, identifier, priority, notification_type, active, version)' +
' SELECT id, display_name, identifier, priority, notification_type, active, version FROM provider_details'
"INSERT INTO provider_details_history"
+ " (id, display_name, identifier, priority, notification_type, active, version)"
+ " SELECT id, display_name, identifier, priority, notification_type, active, version FROM provider_details"
)
def downgrade():
op.drop_table('provider_details_history')
op.drop_table("provider_details_history")
op.alter_column('provider_details', 'active', existing_type=sa.BOOLEAN(), nullable=True)
op.drop_column('provider_details', 'version')
op.drop_column('provider_details', 'updated_at')
op.alter_column(
"provider_details", "active", existing_type=sa.BOOLEAN(), nullable=True
)
op.drop_column("provider_details", "version")
op.drop_column("provider_details", "updated_at")

View File

@@ -7,32 +7,61 @@ Create Date: 2017-01-10 15:39:30.909308
"""
# revision identifiers, used by Alembic.
revision = '0063_templates_process_type'
down_revision = '0062_provider_details_history'
revision = "0063_templates_process_type"
down_revision = "0062_provider_details_history"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('template_process_type',
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('name')
op.create_table(
"template_process_type",
sa.Column("name", sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint("name"),
)
op.execute("INSERT INTO template_process_type VALUES ('normal'), ('priority')")
op.add_column('templates', sa.Column('process_type', sa.String(length=255), nullable=True))
op.create_index(op.f('ix_templates_process_type'), 'templates', ['process_type'], unique=False)
op.create_foreign_key('templates_process_type_fkey', 'templates', 'template_process_type', ['process_type'], ['name'])
op.add_column('templates_history', sa.Column('process_type', sa.String(length=255), nullable=True))
op.create_index(op.f('ix_templates_history_process_type'), 'templates_history', ['process_type'], unique=False)
op.create_foreign_key('templates_history_process_type_fkey', 'templates_history', 'template_process_type', ['process_type'], ['name'])
op.add_column(
"templates", sa.Column("process_type", sa.String(length=255), nullable=True)
)
op.create_index(
op.f("ix_templates_process_type"), "templates", ["process_type"], unique=False
)
op.create_foreign_key(
"templates_process_type_fkey",
"templates",
"template_process_type",
["process_type"],
["name"],
)
op.add_column(
"templates_history",
sa.Column("process_type", sa.String(length=255), nullable=True),
)
op.create_index(
op.f("ix_templates_history_process_type"),
"templates_history",
["process_type"],
unique=False,
)
op.create_foreign_key(
"templates_history_process_type_fkey",
"templates_history",
"template_process_type",
["process_type"],
["name"],
)
def downgrade():
op.drop_constraint('templates_history_process_type_fkey', 'templates_history', type_='foreignkey')
op.drop_index(op.f('ix_templates_history_process_type'), table_name='templates_history')
op.drop_column('templates_history', 'process_type')
op.drop_constraint('templates_process_type_fkey', 'templates', type_='foreignkey')
op.drop_index(op.f('ix_templates_process_type'), table_name='templates')
op.drop_column('templates', 'process_type')
op.drop_table('template_process_type')
op.drop_constraint(
"templates_history_process_type_fkey", "templates_history", type_="foreignkey"
)
op.drop_index(
op.f("ix_templates_history_process_type"), table_name="templates_history"
)
op.drop_column("templates_history", "process_type")
op.drop_constraint("templates_process_type_fkey", "templates", type_="foreignkey")
op.drop_index(op.f("ix_templates_process_type"), table_name="templates")
op.drop_column("templates", "process_type")
op.drop_table("template_process_type")

View File

@@ -7,8 +7,8 @@ Create Date: 2017-01-16 11:08:00.520678
"""
# revision identifiers, used by Alembic.
revision = '0064_update_template_process'
down_revision = '0063_templates_process_type'
revision = "0064_update_template_process"
down_revision = "0063_templates_process_type"
from alembic import op
import sqlalchemy as sa
@@ -17,18 +17,27 @@ import sqlalchemy as sa
def upgrade():
op.execute("Update templates set process_type = 'normal'")
op.execute("Update templates_history set process_type = 'normal'")
op.alter_column('templates', 'process_type',
existing_type=sa.VARCHAR(length=255),
nullable=False)
op.alter_column('templates_history', 'process_type',
existing_type=sa.VARCHAR(length=255),
nullable=False)
op.alter_column(
"templates",
"process_type",
existing_type=sa.VARCHAR(length=255),
nullable=False,
)
op.alter_column(
"templates_history",
"process_type",
existing_type=sa.VARCHAR(length=255),
nullable=False,
)
def downgrade():
op.alter_column('templates_history', 'process_type',
existing_type=sa.VARCHAR(length=255),
nullable=True)
op.alter_column('templates', 'process_type',
existing_type=sa.VARCHAR(length=255),
nullable=True)
op.alter_column(
"templates_history",
"process_type",
existing_type=sa.VARCHAR(length=255),
nullable=True,
)
op.alter_column(
"templates", "process_type", existing_type=sa.VARCHAR(length=255), nullable=True
)

View File

@@ -7,16 +7,20 @@ Create Date: 2017-02-17 11:48:40.669235
"""
# revision identifiers, used by Alembic.
revision = '0065_users_current_session_id'
down_revision = '0064_update_template_process'
revision = "0065_users_current_session_id"
down_revision = "0064_update_template_process"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.add_column('users', sa.Column('current_session_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column(
"users",
sa.Column("current_session_id", postgresql.UUID(as_uuid=True), nullable=True),
)
def downgrade():
op.drop_column('users', 'current_session_id')
op.drop_column("users", "current_session_id")

View File

@@ -1,31 +0,0 @@
"""empty message
Revision ID: 0066_add_dvla_provider
Revises: 0065_users_current_session_id
Create Date: 2017-03-02 10:32:28.984947
"""
import uuid
from datetime import datetime
revision = '0066_add_dvla_provider'
down_revision = '0065_users_current_session_id'
from alembic import op
def upgrade():
provider_id = str(uuid.uuid4())
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id)
)
op.execute(
"INSERT INTO provider_details_history (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id)
)
op.execute("INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES ('{}', '{}', 1.0, '{}')".format(uuid.uuid4(), datetime.utcnow(), provider_id))
def downgrade():
op.execute("DELETE FROM provider_rates where provider_id = (SELECT id from provider_details where display_name='DVLA')")
op.execute("DELETE FROM provider_details_history where display_name = 'DVLA'")
op.execute("DELETE FROM provider_details where display_name = 'DVLA'")

View File

@@ -1,14 +1,14 @@
"""empty message
Revision ID: 0067_service_contact_block
Revises: 0066_add_dvla_provider
Revises: 0065_users_current_session_id
Create Date: 2017-02-28 11:23:40.299110
"""
# revision identifiers, used by Alembic.
revision = '0067_service_contact_block'
down_revision = '0066_add_dvla_provider'
revision = "0067_service_contact_block"
down_revision = "0065_users_current_session_id"
from alembic import op
import sqlalchemy as sa
@@ -16,13 +16,17 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('letter_contact_block', sa.Text(), nullable=True))
op.add_column('services_history', sa.Column('letter_contact_block', sa.Text(), nullable=True))
op.add_column(
"services", sa.Column("letter_contact_block", sa.Text(), nullable=True)
)
op.add_column(
"services_history", sa.Column("letter_contact_block", sa.Text(), nullable=True)
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('services_history', 'letter_contact_block')
op.drop_column('services', 'letter_contact_block')
op.drop_column("services_history", "letter_contact_block")
op.drop_column("services", "letter_contact_block")
### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2017-03-06 17:19:28.492005
"""
# revision identifiers, used by Alembic.
revision = '0068_add_created_by_to_provider'
down_revision = '0067_service_contact_block'
revision = "0068_add_created_by_to_provider"
down_revision = "0067_service_contact_block"
from alembic import op
import sqlalchemy as sa
@@ -17,32 +17,60 @@ from sqlalchemy.dialects import postgresql
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('provider_details', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_index(op.f('ix_provider_details_created_by_id'), 'provider_details', ['created_by_id'], unique=False)
op.create_foreign_key('provider_details_created_by_id_fkey', 'provider_details', 'users', ['created_by_id'], ['id'])
op.add_column('provider_details_history', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column(
"provider_details",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.create_index(
op.f('ix_provider_details_history_created_by_id'),
'provider_details_history',
['created_by_id'],
unique=False
op.f("ix_provider_details_created_by_id"),
"provider_details",
["created_by_id"],
unique=False,
)
op.create_foreign_key(
'provider_details_history_created_by_id_fkey',
'provider_details_history',
'users',
['created_by_id'],
['id']
"provider_details_created_by_id_fkey",
"provider_details",
"users",
["created_by_id"],
["id"],
)
op.add_column(
"provider_details_history",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.create_index(
op.f("ix_provider_details_history_created_by_id"),
"provider_details_history",
["created_by_id"],
unique=False,
)
op.create_foreign_key(
"provider_details_history_created_by_id_fkey",
"provider_details_history",
"users",
["created_by_id"],
["id"],
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('provider_details_history_created_by_id_fkey', 'provider_details_history', type_='foreignkey')
op.drop_index(op.f('ix_provider_details_history_created_by_id'), table_name='provider_details_history')
op.drop_column('provider_details_history', 'created_by_id')
op.drop_constraint('provider_details_created_by_id_fkey', 'provider_details', type_='foreignkey')
op.drop_index(op.f('ix_provider_details_created_by_id'), table_name='provider_details')
op.drop_column('provider_details', 'created_by_id')
op.drop_constraint(
"provider_details_history_created_by_id_fkey",
"provider_details_history",
type_="foreignkey",
)
op.drop_index(
op.f("ix_provider_details_history_created_by_id"),
table_name="provider_details_history",
)
op.drop_column("provider_details_history", "created_by_id")
op.drop_constraint(
"provider_details_created_by_id_fkey", "provider_details", type_="foreignkey"
)
op.drop_index(
op.f("ix_provider_details_created_by_id"), table_name="provider_details"
)
op.drop_column("provider_details", "created_by_id")
# ### end Alembic commands ###

View File

@@ -7,8 +7,8 @@ Create Date: 2017-03-10 16:15:22.153948
"""
# revision identifiers, used by Alembic.
revision = '0069_add_dvla_job_status'
down_revision = '0068_add_created_by_to_provider'
revision = "0069_add_dvla_job_status"
down_revision = "0068_add_created_by_to_provider"
from alembic import op
import sqlalchemy as sa
@@ -21,4 +21,4 @@ def upgrade():
def downgrade():
op.execute("DELETE FROM JOB_STATUS WHERE name = 'ready to send'")
op.execute("DELETE FROM JOB_STATUS where name = 'sent to dvla'")
op.execute("DELETE FROM JOB_STATUS where name = 'sent to dvla'")

View File

@@ -7,24 +7,28 @@ Create Date: 2017-03-10 16:15:22.153948
"""
# revision identifiers, used by Alembic.
revision = '0070_fix_notify_user_email'
down_revision = '0069_add_dvla_job_status'
revision = "0070_fix_notify_user_email"
down_revision = "0069_add_dvla_job_status"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.execute("""
op.execute(
"""
UPDATE users
SET email_address = 'testsender@dispostable.com'
WHERE email_address = 'notify-service-user@digital.cabinet-office'
""")
"""
)
def downgrade():
op.execute("""
op.execute(
"""
UPDATE users
SET email_address = 'notify-service-user@digital.cabinet-office'
WHERE email_address = 'testsender@dispostable.com'
""")
"""
)

View File

@@ -7,8 +7,8 @@ Create Date: 2017-03-10 16:15:22.153948
"""
# revision identifiers, used by Alembic.
revision = '0071_add_job_error_state'
down_revision = '0070_fix_notify_user_email'
revision = "0071_add_job_error_state"
down_revision = "0070_fix_notify_user_email"
from alembic import op
import sqlalchemy as sa

View File

@@ -7,8 +7,8 @@ Create Date: 2017-04-19 15:25:45.155886
"""
# revision identifiers, used by Alembic.
revision = '0072_add_dvla_orgs'
down_revision = '0071_add_job_error_state'
revision = "0072_add_dvla_orgs"
down_revision = "0071_add_job_error_state"
from alembic import op
import sqlalchemy as sa
@@ -16,45 +16,61 @@ import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('dvla_organisation',
sa.Column('id', sa.String(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
op.create_table(
"dvla_organisation",
sa.Column("id", sa.String(), nullable=False),
sa.Column("name", sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
# insert initial values - HMG and Land Reg
op.execute("""
op.execute(
"""
INSERT INTO dvla_organisation VALUES
('001', 'HM Government'),
('500', 'Land Registry')
""")
"""
)
op.add_column('services', sa.Column('dvla_organisation_id', sa.String(), nullable=True, server_default='001'))
op.add_column('services_history', sa.Column('dvla_organisation_id', sa.String(), nullable=True, server_default='001'))
op.add_column(
"services",
sa.Column(
"dvla_organisation_id", sa.String(), nullable=True, server_default="001"
),
)
op.add_column(
"services_history",
sa.Column(
"dvla_organisation_id", sa.String(), nullable=True, server_default="001"
),
)
# set everything to be HMG for now
op.execute("UPDATE services SET dvla_organisation_id = '001'")
op.execute("UPDATE services_history SET dvla_organisation_id = '001'")
op.alter_column('services', 'dvla_organisation_id', nullable=False)
op.alter_column('services_history', 'dvla_organisation_id', nullable=False)
op.alter_column("services", "dvla_organisation_id", nullable=False)
op.alter_column("services_history", "dvla_organisation_id", nullable=False)
op.create_index(
op.f('ix_services_dvla_organisation_id'),
'services',
['dvla_organisation_id'],
unique=False
op.f("ix_services_dvla_organisation_id"),
"services",
["dvla_organisation_id"],
unique=False,
)
op.create_index(
op.f('ix_services_history_dvla_organisation_id'),
'services_history',
['dvla_organisation_id'],
unique=False
op.f("ix_services_history_dvla_organisation_id"),
"services_history",
["dvla_organisation_id"],
unique=False,
)
op.create_foreign_key(
None, "services", "dvla_organisation", ["dvla_organisation_id"], ["id"]
)
op.create_foreign_key(None, 'services', 'dvla_organisation', ['dvla_organisation_id'], ['id'])
def downgrade():
op.drop_column('services_history', 'dvla_organisation_id')
op.drop_column('services', 'dvla_organisation_id')
op.drop_table('dvla_organisation')
op.drop_column("services_history", "dvla_organisation_id")
op.drop_column("services", "dvla_organisation_id")
op.drop_table("dvla_organisation")

View File

@@ -7,18 +7,34 @@ Create Date: 2017-10-25 17:37:27.660723
"""
# revision identifiers, used by Alembic.
revision = '0073_add_international_sms_flag'
down_revision = '0072_add_dvla_orgs'
revision = "0073_add_international_sms_flag"
down_revision = "0072_add_dvla_orgs"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('services', sa.Column('can_send_international_sms', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('services_history', sa.Column('can_send_international_sms', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column(
"services",
sa.Column(
"can_send_international_sms",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
op.add_column(
"services_history",
sa.Column(
"can_send_international_sms",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
def downgrade():
op.drop_column('services_history', 'can_send_international_sms')
op.drop_column('services', 'can_send_international_sms')
op.drop_column("services_history", "can_send_international_sms")
op.drop_column("services", "can_send_international_sms")

View File

@@ -1,28 +0,0 @@
"""empty message
Revision ID: 0074_update_sms_rate
Revises: 0073_add_international_sms_flag
Create Date: 2017-04-24 12:10:02.116278
"""
import uuid
revision = '0074_update_sms_rate'
down_revision = '0073_add_international_sms_flag'
from alembic import op
def upgrade():
op.get_bind()
op.execute("INSERT INTO provider_rates (id, valid_from, rate, provider_id) "
"VALUES ('{}', '2017-04-01 00:00:00', 1.58, "
"(SELECT id FROM provider_details WHERE identifier = 'mmg'))".format(uuid.uuid4())
)
def downgrade():
op.get_bind()
op.execute("DELETE FROM provider_rates where valid_from = '2017-04-01 00:00:00' "
"and provider_id = (SELECT id FROM provider_details WHERE identifier = 'mmg')")

View File

@@ -1,7 +1,7 @@
"""empty message
Revision ID: 0075_create_rates_table
Revises: 0074_update_sms_rate
Revises: 0073_add_international_sms_flag
Create Date: 2017-04-24 15:12:18.907629
"""
@@ -9,32 +9,52 @@ Create Date: 2017-04-24 15:12:18.907629
# revision identifiers, used by Alembic.
import uuid
revision = '0075_create_rates_table'
down_revision = '0074_update_sms_rate'
from sqlalchemy import text
revision = "0075_create_rates_table"
down_revision = "0073_add_international_sms_flag"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
notification_types = postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False)
op.create_table('rates',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('valid_from', sa.DateTime(), nullable=False),
sa.Column('rate', sa.Numeric(), nullable=False),
sa.Column('notification_type', notification_types, nullable=False),
sa.PrimaryKeyConstraint('id')
notification_types = postgresql.ENUM(
"email", "sms", "letter", name="notification_type", create_type=False
)
op.create_table(
"rates",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("valid_from", sa.DateTime(), nullable=False),
sa.Column("rate", sa.Numeric(), nullable=False),
sa.Column("notification_type", notification_types, nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_rates_notification_type'), 'rates', ['notification_type'], unique=False)
op.create_index(
op.f("ix_rates_notification_type"), "rates", ["notification_type"], unique=False
)
op.get_bind()
op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
"VALUES('{}', '2016-05-18 00:00:00', 1.65, 'sms')".format(uuid.uuid4()))
op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
"VALUES('{}', '2017-04-01 00:00:00', 1.58, 'sms')".format(uuid.uuid4()))
conn = op.get_bind()
input_params = {"id": uuid.uuid4()}
conn.execute(
text(
"INSERT INTO rates(id, valid_from, rate, notification_type) "
"VALUES(:id, '2016-05-18 00:00:00', 1.65, 'sms')"
),
input_params,
)
input_params = {"id": uuid.uuid4()}
conn.execute(
text(
"INSERT INTO rates(id, valid_from, rate, notification_type) "
"VALUES(:id, '2017-04-01 00:00:00', 1.58, 'sms')"
),
input_params,
)
def downgrade():
op.drop_index(op.f('ix_rates_notification_type'), table_name='rates')
op.drop_table('rates')
op.drop_index(op.f("ix_rates_notification_type"), table_name="rates")
op.drop_table("rates")

View File

@@ -7,21 +7,41 @@ Create Date: 2017-04-25 09:44:13.194164
"""
# revision identifiers, used by Alembic.
revision = '0076_add_intl_flag_to_provider'
down_revision = '0075_create_rates_table'
revision = "0076_add_intl_flag_to_provider"
down_revision = "0075_create_rates_table"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('provider_details', sa.Column('supports_international', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('provider_details_history', sa.Column('supports_international', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column(
"provider_details",
sa.Column(
"supports_international",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
op.add_column(
"provider_details_history",
sa.Column(
"supports_international",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
op.execute("UPDATE provider_details SET supports_international=True WHERE identifier='sns'")
op.execute("UPDATE provider_details_history SET supports_international=True WHERE identifier='sns'")
op.execute(
"UPDATE provider_details SET supports_international=True WHERE identifier='sns'"
)
op.execute(
"UPDATE provider_details_history SET supports_international=True WHERE identifier='sns'"
)
def downgrade():
op.drop_column('provider_details_history', 'supports_international')
op.drop_column('provider_details', 'supports_international')
op.drop_column("provider_details_history", "supports_international")
op.drop_column("provider_details", "supports_international")

View File

@@ -7,26 +7,39 @@ Create Date: 2017-04-25 11:34:43.229494
"""
# revision identifiers, used by Alembic.
revision = '0077_add_intl_notification'
down_revision = '0076_add_intl_flag_to_provider'
revision = "0077_add_intl_notification"
down_revision = "0076_add_intl_flag_to_provider"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('notification_history', sa.Column('international', sa.Boolean(), nullable=True))
op.add_column('notification_history', sa.Column('phone_prefix', sa.String(), nullable=True))
op.add_column('notification_history', sa.Column('rate_multiplier', sa.Numeric(), nullable=True))
op.add_column('notifications', sa.Column('international', sa.Boolean(), nullable=True))
op.add_column('notifications', sa.Column('phone_prefix', sa.String(), nullable=True))
op.add_column('notifications', sa.Column('rate_multiplier', sa.Numeric(), nullable=True))
op.add_column(
"notification_history", sa.Column("international", sa.Boolean(), nullable=True)
)
op.add_column(
"notification_history", sa.Column("phone_prefix", sa.String(), nullable=True)
)
op.add_column(
"notification_history",
sa.Column("rate_multiplier", sa.Numeric(), nullable=True),
)
op.add_column(
"notifications", sa.Column("international", sa.Boolean(), nullable=True)
)
op.add_column(
"notifications", sa.Column("phone_prefix", sa.String(), nullable=True)
)
op.add_column(
"notifications", sa.Column("rate_multiplier", sa.Numeric(), nullable=True)
)
def downgrade():
op.drop_column('notifications', 'rate_multiplier')
op.drop_column('notifications', 'phone_prefix')
op.drop_column('notifications', 'international')
op.drop_column('notification_history', 'rate_multiplier')
op.drop_column('notification_history', 'phone_prefix')
op.drop_column('notification_history', 'international')
op.drop_column("notifications", "rate_multiplier")
op.drop_column("notifications", "phone_prefix")
op.drop_column("notifications", "international")
op.drop_column("notification_history", "rate_multiplier")
op.drop_column("notification_history", "phone_prefix")
op.drop_column("notification_history", "international")

View File

@@ -7,54 +7,60 @@ Create Date: 2017-04-24 16:55:20.731069
"""
# revision identifiers, used by Alembic.
revision = '0078_sent_notification_status'
down_revision = '0077_add_intl_notification'
revision = "0078_sent_notification_status"
down_revision = "0077_add_intl_notification"
from alembic import op
import sqlalchemy as sa
enum_name = 'notify_status_type'
tmp_name = 'tmp_' + enum_name
enum_name = "notify_status_type"
tmp_name = "tmp_" + enum_name
old_options = (
'created',
'sending',
'delivered',
'pending',
'failed',
'technical-failure',
'temporary-failure',
'permanent-failure'
"created",
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
)
new_options = old_options + ('sent',)
new_options = old_options + ("sent",)
old_type = sa.Enum(*old_options, name=enum_name)
new_type = sa.Enum(*new_options, name=enum_name)
alter_str = 'ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type '
alter_str = "ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type "
def upgrade():
op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name))
op.execute("ALTER TYPE notify_status_type RENAME TO tmp_notify_status_type")
new_type.create(op.get_bind())
op.execute(alter_str.format(table='notifications', enum=enum_name))
op.execute(alter_str.format(table='notification_history', enum=enum_name))
op.execute(
"ALTER TABLE notifications ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
op.execute(
"ALTER TABLE notification_history ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
op.execute('DROP TYPE ' + tmp_name)
op.execute("DROP TYPE tmp_notify_status_type")
def downgrade():
op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name))
op.execute("ALTER TYPE notify_status_type RENAME TO tmp_notify_status_type")
# Convert 'sent' template into 'sending'
update_str = "UPDATE {table} SET status='sending' where status='sent'"
op.execute(update_str.format(table='notifications'))
op.execute(update_str.format(table='notification_history'))
op.execute("UPDATE notifications SET status='sending' where status='sent'")
op.execute("UPDATE notification_history SET status='sending' where status='sent'")
old_type.create(op.get_bind())
op.execute(alter_str.format(table='notifications', enum=enum_name))
op.execute(alter_str.format(table='notification_history', enum=enum_name))
op.execute(
"ALTER TABLE notifications ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
op.execute(
"ALTER TABLE notification_history ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
op.execute('DROP TYPE ' + tmp_name)
op.execute("DROP TYPE tmp_notify_status_type")

View File

@@ -1,25 +0,0 @@
"""empty message
Revision ID: 0079_update_rates
Revises: 0078_sent_notification_status
Create Date: 2017-05-03 12:31:20.731069
"""
# revision identifiers, used by Alembic.
revision = '0079_update_rates'
down_revision = '0078_sent_notification_status'
from alembic import op
def upgrade():
op.get_bind()
op.execute("UPDATE RATES SET rate = 0.0158 WHERE valid_from = '2017-04-01 00:00:00'")
op.execute("UPDATE RATES SET rate = 0.0165 WHERE valid_from = '2016-05-18 00:00:00'")
def downgrade():
op.get_bind()
op.execute("UPDATE RATES SET rate = 1.58 WHERE valid_from = '2017-04-01 00:00:00'")
op.execute("UPDATE RATES SET rate = 1.65 WHERE valid_from = '2016-05-18 00:00:00'")

View File

@@ -1,24 +0,0 @@
"""empty message
Revision ID: 0080_fix_rate_start_date
Revises: 0079_update_rates
Create Date: 2017-05-03 16:50:11.334116
"""
# revision identifiers, used by Alembic.
revision = '0080_fix_rate_start_date'
down_revision = '0079_update_rates'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.get_bind()
op.execute("UPDATE RATES SET valid_from = '2017-03-31 23:00:00' WHERE valid_from = '2017-04-01 00:00:00'")
def downgrade():
op.get_bind()
op.execute("UPDATE RATES SET valid_from = '2017-03-31 23:00:00' WHERE valid_from = '2017-04-01 00:00:00'")

View File

@@ -1,63 +1,73 @@
"""empty message
Revision ID: 0081_noti_status_as_enum
Revises: 0080_fix_rate_start_date
Revises: 0078_sent_notification_status
Create Date: 2017-05-02 14:50:04.070874
"""
# revision identifiers, used by Alembic.
revision = '0081_noti_status_as_enum'
down_revision = '0080_fix_rate_start_date'
revision = "0081_noti_status_as_enum"
down_revision = "0078_sent_notification_status"
from alembic import op
import sqlalchemy as sa
def upgrade():
status_table = op.create_table('notification_status_types',
sa.Column('name', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('name')
status_table = op.create_table(
"notification_status_types",
sa.Column("name", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("name"),
)
op.bulk_insert(status_table,
op.bulk_insert(
status_table,
[
{'name': x} for x in {
'created',
'sending',
'delivered',
'pending',
'failed',
'technical-failure',
'temporary-failure',
'permanent-failure',
'sent',
{"name": x}
for x in {
"created",
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
"sent",
}
]
],
)
op.execute('ALTER TABLE notifications ADD COLUMN notification_status text')
op.execute('ALTER TABLE notification_history ADD COLUMN notification_status text')
op.execute("ALTER TABLE notifications ADD COLUMN notification_status text")
op.execute("ALTER TABLE notification_history ADD COLUMN notification_status text")
op.create_index(op.f('ix_notifications_notification_status'), 'notifications', ['notification_status'])
op.create_index(op.f('ix_notification_history_notification_status'), 'notification_history', ['notification_status'])
op.create_foreign_key(
'fk_notifications_notification_status',
'notifications',
'notification_status_types',
['notification_status'],
['name'],
op.create_index(
op.f("ix_notifications_notification_status"),
"notifications",
["notification_status"],
)
op.create_index(
op.f("ix_notification_history_notification_status"),
"notification_history",
["notification_status"],
)
op.create_foreign_key(
'fk_notification_history_notification_status',
'notification_history',
'notification_status_types',
['notification_status'],
['name'],
"fk_notifications_notification_status",
"notifications",
"notification_status_types",
["notification_status"],
["name"],
)
op.create_foreign_key(
"fk_notification_history_notification_status",
"notification_history",
"notification_status_types",
["notification_status"],
["name"],
)
def downgrade():
op.execute('ALTER TABLE notifications DROP COLUMN notification_status')
op.execute('ALTER TABLE notification_history DROP COLUMN notification_status')
op.execute('DROP TABLE notification_status_types')
op.execute("ALTER TABLE notifications DROP COLUMN notification_status")
op.execute("ALTER TABLE notification_history DROP COLUMN notification_status")
op.execute("DROP TABLE notification_status_types")

View File

@@ -13,21 +13,22 @@ from flask import current_app
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text
revision = '0082_add_go_live_template'
down_revision = '0081_noti_status_as_enum'
revision = "0082_add_go_live_template"
down_revision = "0081_noti_status_as_enum"
template_id = '618185c6-3636-49cd-b7d2-6f6f5eb3bdde'
template_id = "618185c6-3636-49cd-b7d2-6f6f5eb3bdde"
def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}')
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1, :process_type)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}')
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1, :process_type)
"""
template_content = """Hi ((name)),
@@ -83,49 +84,33 @@ GOV.UK Notify team
"""
template_name = "Automated \"You''re now live\" message"
template_subject = '((service name)) is now live on GOV.UK Notify'
template_subject = "((service name)) is now live on GOV.UK Notify"
op.execute(
template_history_insert.format(
template_id,
template_name,
'email',
datetime.utcnow(),
template_content,
current_app.config['NOTIFY_SERVICE_ID'],
template_subject,
current_app.config['NOTIFY_USER_ID'],
'normal'
)
)
input_params = {
"template_id": template_id,
"template_name": template_name,
"template_type": "email",
"time_now": datetime.utcnow(),
"content": template_content,
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
"subject": template_subject,
"user_id": current_app.config["NOTIFY_USER_ID"],
"process_type": "normal",
}
conn = op.get_bind()
conn.execute(text(template_history_insert), input_params)
op.execute(
template_insert.format(
template_id,
template_name,
'email',
datetime.utcnow(),
template_content,
current_app.config['NOTIFY_SERVICE_ID'],
template_subject,
current_app.config['NOTIFY_USER_ID'],
'normal'
)
)
# If you are copying this migration, please remember about an insert to TemplateRedacted,
# which was not originally included here either by mistake or because it was before TemplateRedacted existed
# op.execute(
# """
# INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id)
# VALUES ('{}', '{}', '{}', '{}')
# ;
# """.format(template_id, False, datetime.utcnow(), current_app.config['NOTIFY_USER_ID'])
# )
conn.execute(text(template_insert), input_params)
def downgrade():
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id))
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id))
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template_id))
op.execute("DELETE FROM templates WHERE id = '{}'".format(template_id))
input_params = {"template_id": template_id}
conn = op.get_bind()
conn.execute(
text("DELETE FROM notifications WHERE template_id = '{}'"), input_params
)
conn.execute(
text("DELETE FROM notification_history WHERE template_id = '{}'"), input_params
)
conn.execute(text("DELETE FROM templates_history WHERE id = '{}'"), input_params)
conn.execute(text("DELETE FROM templates WHERE id = '{}'"), input_params)

View File

@@ -7,47 +7,69 @@ 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'
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'))
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.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)
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')
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 ###

View File

@@ -7,33 +7,40 @@ Create Date: 2017-05-12 13:16:14.147368
"""
# revision identifiers, used by Alembic.
revision = '0084_add_job_stats'
down_revision = '0083_add_perm_types_and_svc_perm'
revision = "0084_add_job_stats"
down_revision = "0083_add_perm_types_and_svc_perm"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table('job_statistics',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('emails_sent', sa.BigInteger(), nullable=False),
sa.Column('emails_delivered', sa.BigInteger(), nullable=False),
sa.Column('emails_failed', sa.BigInteger(), nullable=False),
sa.Column('sms_sent', sa.BigInteger(), nullable=False),
sa.Column('sms_delivered', sa.BigInteger(), nullable=False),
sa.Column('sms_failed', sa.BigInteger(), nullable=False),
sa.Column('letters_sent', sa.BigInteger(), nullable=False),
sa.Column('letters_failed', sa.BigInteger(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"job_statistics",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("job_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("emails_sent", sa.BigInteger(), nullable=False),
sa.Column("emails_delivered", sa.BigInteger(), nullable=False),
sa.Column("emails_failed", sa.BigInteger(), nullable=False),
sa.Column("sms_sent", sa.BigInteger(), nullable=False),
sa.Column("sms_delivered", sa.BigInteger(), nullable=False),
sa.Column("sms_failed", sa.BigInteger(), nullable=False),
sa.Column("letters_sent", sa.BigInteger(), nullable=False),
sa.Column("letters_failed", sa.BigInteger(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["job_id"],
["jobs.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_job_statistics_job_id"), "job_statistics", ["job_id"], unique=True
)
op.create_index(op.f('ix_job_statistics_job_id'), 'job_statistics', ['job_id'], unique=True)
def downgrade():
op.drop_index(op.f('ix_job_statistics_job_id'), table_name='job_statistics')
op.drop_table('job_statistics')
op.drop_index(op.f("ix_job_statistics_job_id"), table_name="job_statistics")
op.drop_table("job_statistics")

View File

@@ -7,16 +7,21 @@ Create Date: 2017-05-22 10:23:43.939050
"""
# revision identifiers, used by Alembic.
revision = '0085_update_incoming_to_inbound'
down_revision = '0084_add_job_stats'
revision = "0085_update_incoming_to_inbound"
down_revision = "0084_add_job_stats"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.execute("UPDATE service_permission_types SET name='inbound_sms' WHERE name='incoming_sms'")
op.execute(
"UPDATE service_permission_types SET name='inbound_sms' WHERE name='incoming_sms'"
)
def downgrade():
op.execute("UPDATE service_permission_types SET name='incoming_sms' WHERE name='inbound_sms'")
op.execute(
"UPDATE service_permission_types SET name='incoming_sms' WHERE name='inbound_sms'"
)

View File

@@ -9,13 +9,15 @@ Create Date: 2017-05-23 10:37:00.404087
from alembic import op
import sqlalchemy as sa
revision = '0086_add_norm_to_notification'
down_revision = '0085_update_incoming_to_inbound'
revision = "0086_add_norm_to_notification"
down_revision = "0085_update_incoming_to_inbound"
def upgrade():
op.add_column('notifications', sa.Column('normalised_to', sa.String(), nullable=True))
op.add_column(
"notifications", sa.Column("normalised_to", sa.String(), nullable=True)
)
def downgrade():
op.drop_column('notifications', 'normalised_to')
op.drop_column("notifications", "normalised_to")

View File

@@ -9,23 +9,34 @@ from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0087_scheduled_notifications'
down_revision = '0086_add_norm_to_notification'
revision = "0087_scheduled_notifications"
down_revision = "0086_add_norm_to_notification"
def upgrade():
op.create_table('scheduled_notifications',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('scheduled_for', sa.DateTime(), nullable=False),
sa.Column('pending', sa.Boolean, nullable=False, default=True),
sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_scheduled_notifications_notification_id'), 'scheduled_notifications', ['notification_id'],
unique=False)
op.create_table(
"scheduled_notifications",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("notification_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("scheduled_for", sa.DateTime(), nullable=False),
sa.Column("pending", sa.Boolean, nullable=False, default=True),
sa.ForeignKeyConstraint(
["notification_id"],
["notifications.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_scheduled_notifications_notification_id"),
"scheduled_notifications",
["notification_id"],
unique=False,
)
def downgrade():
op.drop_index(op.f('ix_scheduled_notifications_notification_id'), table_name='scheduled_notifications')
op.drop_table('scheduled_notifications')
op.drop_index(
op.f("ix_scheduled_notifications_notification_id"),
table_name="scheduled_notifications",
)
op.drop_table("scheduled_notifications")

View File

@@ -7,8 +7,8 @@ Create Date: 2017-05-26 14:53:18.581320
"""
# revision identifiers, used by Alembic.
revision = '0088_add_schedule_serv_perm'
down_revision = '0087_scheduled_notifications'
revision = "0088_add_schedule_serv_perm"
down_revision = "0087_scheduled_notifications"
from alembic import op
@@ -20,5 +20,9 @@ def upgrade():
def downgrade():
op.get_bind()
op.execute("delete from service_permissions where permission = 'schedule_notifications'")
op.execute("delete from service_permission_types where name = 'schedule_notifications'")
op.execute(
"delete from service_permissions where permission = 'schedule_notifications'"
)
op.execute(
"delete from service_permission_types where name = 'schedule_notifications'"
)

View File

@@ -7,19 +7,21 @@ Create Date: 2017-05-22 13:46:09.584801
"""
# revision identifiers, used by Alembic.
revision = '0089_govuk_sms_sender'
down_revision = '0088_add_schedule_serv_perm'
revision = "0089_govuk_sms_sender"
down_revision = "0088_add_schedule_serv_perm"
from alembic import op
def upgrade():
op.execute("UPDATE services SET sms_sender = 'GOVUK' where sms_sender is null")
op.execute("UPDATE services_history SET sms_sender = 'GOVUK' where sms_sender is null")
op.alter_column('services', 'sms_sender', nullable=False)
op.alter_column('services_history', 'sms_sender', nullable=False)
op.execute(
"UPDATE services_history SET sms_sender = 'GOVUK' where sms_sender is null"
)
op.alter_column("services", "sms_sender", nullable=False)
op.alter_column("services_history", "sms_sender", nullable=False)
def downgrade():
op.alter_column('services_history', 'sms_sender', nullable=True)
op.alter_column('services', 'sms_sender', nullable=True)
op.alter_column("services_history", "sms_sender", nullable=True)
op.alter_column("services", "sms_sender", nullable=True)

View File

@@ -7,31 +7,38 @@ Create Date: 2017-05-22 11:28:53.471004
"""
# revision identifiers, used by Alembic.
revision = '0090_inbound_sms'
down_revision = '0089_govuk_sms_sender'
revision = "0090_inbound_sms"
down_revision = "0089_govuk_sms_sender"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table(
'inbound_sms',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('content', sa.String, nullable=False),
sa.Column('notify_number', sa.String, nullable=False),
sa.Column('user_number', sa.String, nullable=False),
sa.Column('created_at', sa.DateTime, nullable=False),
sa.Column('provider_date', sa.DateTime, nullable=True),
sa.Column('provider_reference', sa.String, nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id')
"inbound_sms",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("content", sa.String, nullable=False),
sa.Column("notify_number", sa.String, nullable=False),
sa.Column("user_number", sa.String, nullable=False),
sa.Column("created_at", sa.DateTime, nullable=False),
sa.Column("provider_date", sa.DateTime, nullable=True),
sa.Column("provider_reference", sa.String, nullable=True),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_inbound_sms_service_id"), "inbound_sms", ["service_id"], unique=False
)
op.create_index(
op.f("ix_inbound_sms_user_number"), "inbound_sms", ["user_number"], unique=False
)
op.create_index(op.f('ix_inbound_sms_service_id'), 'inbound_sms', ['service_id'], unique=False)
op.create_index(op.f('ix_inbound_sms_user_number'), 'inbound_sms', ['user_number'], unique=False)
def downgrade():
op.drop_table('inbound_sms')
op.drop_table("inbound_sms")

View File

@@ -1,50 +0,0 @@
"""empty message
Revision ID: 0091_letter_billing
Revises: 0090_inbound_sms
Create Date: 2017-05-31 11:43:55.744631
"""
import uuid
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0091_letter_billing'
down_revision = '0090_inbound_sms'
def upgrade():
op.create_table('letter_rates',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('valid_from', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('letter_rate_details',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('letter_rate_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('page_total', sa.Integer(), nullable=False),
sa.Column('rate', sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint(['letter_rate_id'], ['letter_rates.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_letter_rate_details_letter_rate_id'), 'letter_rate_details', ['letter_rate_id'],
unique=False)
op.get_bind()
letter_id = uuid.uuid4()
op.execute("insert into letter_rates(id, valid_from) values('{}', '2017-03-31 23:00:00')".format(letter_id))
insert_details = "insert into letter_rate_details(id, letter_rate_id, page_total, rate) values('{}', '{}', {}, {})"
op.execute(
insert_details.format(uuid.uuid4(), letter_id, 1, 29.3))
op.execute(
insert_details.format(uuid.uuid4(), letter_id, 2, 32))
op.execute(
insert_details.format(uuid.uuid4(), letter_id, 3, 35))
def downgrade():
op.get_bind()
op.drop_index('ix_letter_rate_details_letter_rate_id')
op.drop_table('letter_rate_details')
op.drop_table('letter_rates')

View File

@@ -1,22 +1,23 @@
"""empty message
Revision ID: 0092_add_inbound_provider
Revises: 0091_letter_billing
Revises: 0090_inbound_sms
Create Date: 2017-06-02 16:07:35.445423
"""
# revision identifiers, used by Alembic.
revision = '0092_add_inbound_provider'
down_revision = '0091_letter_billing'
revision = "0092_add_inbound_provider"
down_revision = "0090_inbound_sms"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.add_column('inbound_sms', sa.Column('provider', sa.String(), nullable=True))
op.add_column("inbound_sms", sa.Column("provider", sa.String(), nullable=True))
def downgrade():
op.drop_column('inbound_sms', 'provider')
op.drop_column("inbound_sms", "provider")

View File

@@ -1,32 +0,0 @@
"""empty message
Revision ID: 0093_data_gov_uk
Revises: 0092_add_inbound_provider
Create Date: 2017-06-05 16:15:17.744908
"""
# revision identifiers, used by Alembic.
revision = '0093_data_gov_uk'
down_revision = '0092_add_inbound_provider'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
DATA_GOV_UK_ID = '123496d4-44cb-4324-8e0a-4187101f4bdc'
def upgrade():
op.execute("""INSERT INTO organisation VALUES (
'{}',
'',
'data_gov_uk_x2.png',
'data gov.uk'
)""".format(DATA_GOV_UK_ID))
def downgrade():
op.execute("""
DELETE FROM organisation WHERE "id" = '{}'
""".format(DATA_GOV_UK_ID))

View File

@@ -1,7 +1,7 @@
"""empty message
Revision ID: 0094_job_stats_update
Revises: 0093_data_gov_uk
Revises: 0092_add_inbound_provider
Create Date: 2017-06-06 14:37:30.051647
"""
@@ -9,17 +9,19 @@ from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0094_job_stats_update'
down_revision = '0093_data_gov_uk'
revision = "0094_job_stats_update"
down_revision = "0092_add_inbound_provider"
def upgrade():
op.add_column('job_statistics', sa.Column('sent', sa.BigInteger(), nullable=True))
op.add_column('job_statistics', sa.Column('delivered', sa.BigInteger(), nullable=True))
op.add_column('job_statistics', sa.Column('failed', sa.BigInteger(), nullable=True))
op.add_column("job_statistics", sa.Column("sent", sa.BigInteger(), nullable=True))
op.add_column(
"job_statistics", sa.Column("delivered", sa.BigInteger(), nullable=True)
)
op.add_column("job_statistics", sa.Column("failed", sa.BigInteger(), nullable=True))
def downgrade():
op.drop_column('job_statistics', 'sent')
op.drop_column('job_statistics', 'failed')
op.drop_column('job_statistics', 'delivered')
op.drop_column("job_statistics", "sent")
op.drop_column("job_statistics", "failed")
op.drop_column("job_statistics", "delivered")

View File

@@ -7,33 +7,74 @@ Create Date: 2017-05-23 18:13:03.532095
"""
# revision identifiers, used by Alembic.
revision = '0095_migrate_existing_svc_perms'
down_revision = '0094_job_stats_update'
from sqlalchemy import text
revision = "0095_migrate_existing_svc_perms"
down_revision = "0094_job_stats_update"
from alembic import op
import sqlalchemy as sa
migration_date = '2017-05-26 17:30:00.000000'
migration_date = "2017-05-26 17:30:00.000000"
def upgrade():
def get_values(permission):
return "SELECT id, '{0}', '{1}' FROM services WHERE "\
"id NOT IN (SELECT service_id FROM service_permissions "\
"WHERE service_id=id AND permission='{0}')".format(permission, migration_date)
return (
"SELECT id, '{0}', '{1}' FROM services WHERE "
"id NOT IN (SELECT service_id FROM service_permissions "
"WHERE service_id=id AND permission='{0}')".format(
permission, migration_date
)
)
def get_values_if_flag(permission, flag):
return "SELECT id, '{0}', '{1}' FROM services WHERE "\
"{2} AND id NOT IN (SELECT service_id FROM service_permissions "\
"WHERE service_id=id AND permission='{0}')".format(permission, migration_date, flag)
return (
"SELECT id, '{0}', '{1}' FROM services WHERE "
"{2} AND id NOT IN (SELECT service_id FROM service_permissions "
"WHERE service_id=id AND permission='{0}')".format(
permission, migration_date, flag
)
)
op.execute("INSERT INTO service_permissions (service_id, permission, created_at) {}".format(get_values('sms')))
op.execute("INSERT INTO service_permissions (service_id, permission, created_at) {}".format(get_values('email')))
op.execute("INSERT INTO service_permissions (service_id, permission, created_at) {}".format(
get_values_if_flag('letter', 'can_send_letters')))
op.execute("INSERT INTO service_permissions (service_id, permission, created_at) {}".format(
get_values_if_flag('international_sms', 'can_send_international_sms')))
conn = op.get_bind()
conn.execute(
"""
INSERT INTO service_permissions (service_id, permission, created_at)
SELECT id, 'sms', '2017-05-26 17:30:00.000000' FROM services
WHERE id NOT IN (SELECT service_id FROM service_permissions
WHERE service_id=id AND permission='sms')
"""
)
conn.execute(
"""
INSERT INTO service_permissions (service_id, permission, created_at)
SELECT id, 'email', '2017-05-26 17:30:00.000000' FROM services
WHERE id NOT IN (SELECT service_id FROM service_permissions
WHERE service_id=id AND permission='email')
"""
)
conn.execute(
"""
INSERT INTO service_permissions (service_id, permission, created_at)
SELECT id, 'letter', '2017-05-26 17:30:00.000000' FROM services
WHERE can_send_letters AND id NOT IN (SELECT service_id FROM service_permissions
WHERE service_id=id AND permission='letter')
"""
)
conn.execute(
"""
INSERT INTO service_permissions (service_id, permission, created_at)
SELECT id, 'international_sms', '2017-05-26 17:30:00.000000' FROM services
WHERE can_send_international_sms AND id NOT IN (SELECT service_id FROM service_permissions
WHERE service_id=id AND permission='international_sms')
"""
)
def downgrade():
op.execute("DELETE FROM service_permissions WHERE created_at = '{}'::timestamp".format(migration_date))
op.execute(
"DELETE FROM service_permissions WHERE created_at = '2017-05-26 17:30:00.000000'::timestamp"
)

View File

@@ -7,8 +7,8 @@ Create Date: 2017-06-08 15:46:49.637642
"""
# revision identifiers, used by Alembic.
revision = '0096_update_job_stats'
down_revision = '0095_migrate_existing_svc_perms'
revision = "0096_update_job_stats"
down_revision = "0095_migrate_existing_svc_perms"
from alembic import op
import sqlalchemy as sa
@@ -16,20 +16,19 @@ from sqlalchemy.dialects import postgresql
def upgrade():
query = "UPDATE job_statistics " \
"set sent = sms_sent + emails_sent + letters_sent, " \
" delivered = sms_delivered + emails_delivered, " \
" failed = sms_failed + emails_failed + letters_failed "
query = (
"UPDATE job_statistics "
"set sent = sms_sent + emails_sent + letters_sent, "
" delivered = sms_delivered + emails_delivered, "
" failed = sms_failed + emails_failed + letters_failed "
)
conn = op.get_bind()
conn.execute(query)
def downgrade():
query = "UPDATE job_statistics " \
"set sent = 0, " \
" delivered = 0, " \
" failed = 0 "
query = "UPDATE job_statistics " "set sent = 0, " " delivered = 0, " " failed = 0 "
conn = op.get_bind()
conn.execute(query)

View File

@@ -7,20 +7,20 @@ Create Date: 2017-06-02 16:50:11.698423
"""
# revision identifiers, used by Alembic.
revision = '0097_notnull_inbound_provider'
down_revision = '0096_update_job_stats'
revision = "0097_notnull_inbound_provider"
down_revision = "0096_update_job_stats"
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column('inbound_sms', 'provider',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column(
"inbound_sms", "provider", existing_type=sa.VARCHAR(), nullable=False
)
def downgrade():
op.alter_column('inbound_sms', 'provider',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column(
"inbound_sms", "provider", existing_type=sa.VARCHAR(), nullable=True
)

View File

@@ -9,48 +9,83 @@ from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0098_service_inbound_api'
down_revision = '0097_notnull_inbound_provider'
revision = "0098_service_inbound_api"
down_revision = "0097_notnull_inbound_provider"
def upgrade():
op.create_table('service_inbound_api_history',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('url', sa.String(), nullable=False),
sa.Column('bearer_token', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('updated_by_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', 'version')
op.create_table(
"service_inbound_api_history",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("url", sa.String(), nullable=False),
sa.Column("bearer_token", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("updated_by_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("version", sa.Integer(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint("id", "version"),
)
op.create_index(op.f('ix_service_inbound_api_history_service_id'), 'service_inbound_api_history', ['service_id'],
unique=False)
op.create_index(op.f('ix_service_inbound_api_history_updated_by_id'), 'service_inbound_api_history',
['updated_by_id'], unique=False)
op.create_table('service_inbound_api',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('url', sa.String(), nullable=False),
sa.Column('bearer_token', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('updated_by_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('version', sa.Integer(), nullable=False),\
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['updated_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_index(
op.f("ix_service_inbound_api_history_service_id"),
"service_inbound_api_history",
["service_id"],
unique=False,
)
op.create_index(
op.f("ix_service_inbound_api_history_updated_by_id"),
"service_inbound_api_history",
["updated_by_id"],
unique=False,
)
op.create_table(
"service_inbound_api",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("url", sa.String(), nullable=False),
sa.Column("bearer_token", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("updated_by_id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("version", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["services.id"],
),
sa.ForeignKeyConstraint(
["updated_by_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_service_inbound_api_service_id"),
"service_inbound_api",
["service_id"],
unique=True,
)
op.create_index(
op.f("ix_service_inbound_api_updated_by_id"),
"service_inbound_api",
["updated_by_id"],
unique=False,
)
op.create_index(op.f('ix_service_inbound_api_service_id'), 'service_inbound_api', ['service_id'], unique=True)
op.create_index(op.f('ix_service_inbound_api_updated_by_id'), 'service_inbound_api', ['updated_by_id'],
unique=False)
def downgrade():
op.drop_index(op.f('ix_service_inbound_api_updated_by_id'), table_name='service_inbound_api')
op.drop_index(op.f('ix_service_inbound_api_service_id'), table_name='service_inbound_api')
op.drop_table('service_inbound_api')
op.drop_index(op.f('ix_service_inbound_api_history_updated_by_id'), table_name='service_inbound_api_history')
op.drop_index(op.f('ix_service_inbound_api_history_service_id'), table_name='service_inbound_api_history')
op.drop_table('service_inbound_api_history')
op.drop_index(
op.f("ix_service_inbound_api_updated_by_id"), table_name="service_inbound_api"
)
op.drop_index(
op.f("ix_service_inbound_api_service_id"), table_name="service_inbound_api"
)
op.drop_table("service_inbound_api")
op.drop_index(
op.f("ix_service_inbound_api_history_updated_by_id"),
table_name="service_inbound_api_history",
)
op.drop_index(
op.f("ix_service_inbound_api_history_service_id"),
table_name="service_inbound_api_history",
)
op.drop_table("service_inbound_api_history")

View File

@@ -7,26 +7,42 @@ Create Date: 2017-06-05 16:15:17.744908
"""
# revision identifiers, used by Alembic.
revision = '0099_tfl_dar'
down_revision = '0098_service_inbound_api'
from sqlalchemy import text
revision = "0099_tfl_dar"
down_revision = "0098_service_inbound_api"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
TFL_DAR_ID = '1d70f564-919b-4c68-8bdf-b8520d92516e'
TFL_DAR_ID = "1d70f564-919b-4c68-8bdf-b8520d92516e"
def upgrade():
op.execute("""INSERT INTO organisation VALUES (
'{}',
conn = op.get_bind()
input_params = {"tfl_dar_id": TFL_DAR_ID}
conn.execute(
text(
"""INSERT INTO organisation VALUES (
:tfl_dar_id,
'',
'tfl_dar_x2.png',
'tfl'
)""".format(TFL_DAR_ID))
)"""
),
input_params,
)
def downgrade():
op.execute("""
DELETE FROM organisation WHERE "id" = '{}'
""".format(TFL_DAR_ID))
conn = op.get_bind()
input_params = {"tfl_dar_id": TFL_DAR_ID}
conn.execute(
text(
"""
DELETE FROM organisation WHERE "id" = :tfl_dar_id
"""
),
input_params,
)

View File

@@ -7,21 +7,30 @@ Create Date: 2017-06-13 10:53:25.032202
"""
# revision identifiers, used by Alembic.
revision = '0100_notification_created_by'
down_revision = '0099_tfl_dar'
revision = "0100_notification_created_by"
down_revision = "0099_tfl_dar"
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.add_column('notifications', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_foreign_key(None, 'notifications', 'users', ['created_by_id'], ['id'])
op.add_column('notification_history', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_foreign_key(None, 'notification_history', 'users', ['created_by_id'], ['id'])
def upgrade():
op.add_column(
"notifications",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.create_foreign_key(None, "notifications", "users", ["created_by_id"], ["id"])
op.add_column(
"notification_history",
sa.Column("created_by_id", postgresql.UUID(as_uuid=True), nullable=True),
)
op.create_foreign_key(
None, "notification_history", "users", ["created_by_id"], ["id"]
)
def downgrade():
op.drop_column('notifications', 'created_by_id')
op.drop_column('notification_history', 'created_by_id')
op.drop_column("notifications", "created_by_id")
op.drop_column("notification_history", "created_by_id")

View File

@@ -7,24 +7,39 @@ Create Date: 2017-06-26 11:43:30.374723
"""
from alembic import op
from sqlalchemy import text
revision = '0101_een_logo'
down_revision = '0100_notification_created_by'
revision = "0101_een_logo"
down_revision = "0100_notification_created_by"
ENTERPRISE_EUROPE_NETWORK_ID = '89ce468b-fb29-4d5d-bd3f-d468fb6f7c36'
ENTERPRISE_EUROPE_NETWORK_ID = "89ce468b-fb29-4d5d-bd3f-d468fb6f7c36"
def upgrade():
op.execute("""INSERT INTO organisation VALUES (
'{}',
input_params = {"network_id": ENTERPRISE_EUROPE_NETWORK_ID}
conn = op.get_bind()
conn.execute(
text(
"""INSERT INTO organisation VALUES (
:network_id,
'',
'een_x2.png',
'een'
)""".format(ENTERPRISE_EUROPE_NETWORK_ID))
)"""
),
input_params,
)
def downgrade():
op.execute("""
DELETE FROM organisation WHERE "id" = '{}'
""".format(ENTERPRISE_EUROPE_NETWORK_ID))
input_params = {"network_id": ENTERPRISE_EUROPE_NETWORK_ID}
conn = op.get_bind()
conn.execute(
text(
"""
DELETE FROM organisation WHERE "id" = :network_id
"""
),
input_params,
)

Some files were not shown because too many files have changed in this diff Show More