Remove the archived table template_statistics. The last time the table we updated was August 30 2016, it's safe to say we are done with it.

I updated the InboundSms and TemplateRedacted model to include an index in the db.
Dropped service_permissions.updated_at column since we are not auditting the table
This commit is contained in:
Rebecca Law
2017-07-10 14:43:46 +01:00
parent 2aba819cb6
commit 8a01a76e33
6 changed files with 43 additions and 43 deletions

View File

@@ -13,7 +13,6 @@ from app.dao.dao_utils import (
from app.dao.notifications_dao import get_financial_year
from app.models import (
NotificationStatistics,
TemplateStatistics,
ProviderStatistics,
VerifyCode,
ApiKey,
@@ -33,9 +32,7 @@ from app.models import (
TEMPLATE_TYPES,
JobStatistics,
SMS_TYPE,
EMAIL_TYPE,
INTERNATIONAL_SMS_TYPE,
LETTER_TYPE
EMAIL_TYPE
)
from app.service.statistics import format_monthly_template_notification_stats
from app.statsd_decorators import statsd
@@ -207,7 +204,6 @@ def delete_service_and_all_associated_db_objects(service):
_delete_commit(TemplateRedacted.query.filter(TemplateRedacted.template_id.in_(subq)))
_delete_commit(NotificationStatistics.query.filter_by(service=service))
_delete_commit(TemplateStatistics.query.filter_by(service=service))
_delete_commit(ProviderStatistics.query.filter_by(service=service))
_delete_commit(InvitedUser.query.filter_by(service=service))
_delete_commit(Permission.query.filter_by(service=service))

View File

@@ -467,7 +467,7 @@ class TemplateRedacted(db.Model):
template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), primary_key=True, nullable=False)
redact_personalisation = db.Column(db.Boolean, nullable=False, default=False)
updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
updated_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=False)
updated_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=False, index=True)
updated_by = db.relationship('User')
# uselist=False as this is a one-to-one relationship
@@ -1126,22 +1126,6 @@ class Permission(db.Model):
)
class TemplateStatistics(db.Model):
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, nullable=False)
service = db.relationship('Service', backref=db.backref('template_statistics', lazy='dynamic'))
template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, nullable=False, unique=False)
template = db.relationship('Template')
usage_count = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=1)
day = db.Column(db.Date, index=True, nullable=False, unique=False, default=datetime.date.today)
updated_at = db.Column(
db.DateTime,
index=False,
unique=False,
nullable=False,
default=datetime.datetime.utcnow)
class Event(db.Model):
__tablename__ = 'events'
@@ -1228,7 +1212,7 @@ class InboundSms(db.Model):
service = db.relationship('Service', backref='inbound_sms')
notify_number = db.Column(db.String, nullable=False) # the service's number, that the msg was sent to
user_number = db.Column(db.String, nullable=False) # the end user's number, that the msg was sent from
user_number = db.Column(db.String, nullable=False, index=True) # the end user's number, that the msg was sent from
provider_date = db.Column(db.DateTime)
provider_reference = db.Column(db.String)
provider = db.Column(db.String, nullable=False)

View File

@@ -25,7 +25,7 @@ from notifications_utils.recipients import (
from app import ma
from app import models
from app.models import ServicePermission, INTERNATIONAL_SMS_TYPE, LETTER_TYPE
from app.models import ServicePermission
from app.dao.permissions_dao import permission_dao
from app.utils import get_template_instance
@@ -571,15 +571,6 @@ class NotificationsFilterSchema(ma.Schema):
_validate_positive_number(value)
class TemplateStatisticsSchema(BaseSchema):
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type"], dump_only=True)
class Meta:
model = models.TemplateStatistics
strict = True
class ServiceHistorySchema(ma.Schema):
id = fields.UUID()
name = fields.String()
@@ -663,7 +654,6 @@ permission_schema = PermissionSchema()
email_data_request_schema = EmailDataSchema()
notifications_statistics_schema = NotificationsStatisticsSchema()
notifications_filter_schema = NotificationsFilterSchema()
template_statistics_schema = TemplateStatisticsSchema()
service_history_schema = ServiceHistorySchema()
api_key_history_schema = ApiKeyHistorySchema()
template_history_schema = TemplateHistorySchema()

View File

@@ -0,0 +1,38 @@
"""empty message
Revision ID: 0106_drop_template_stats
Revises: 0105_opg_letter_org
Create Date: 2017-07-10 14:25:58.494636
"""
# revision identifiers, used by Alembic.
revision = '0106_drop_template_stats'
down_revision = '0105_opg_letter_org'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.drop_table('template_statistics')
op.drop_column('service_permissions', 'updated_at')
def downgrade():
op.add_column('service_permissions',
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True))
op.create_table('template_statistics',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('template_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('usage_count', sa.BIGINT(), autoincrement=False, nullable=False),
sa.Column('day', sa.DATE(), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'],
name='template_statistics_service_id_fkey'),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'],
name='template_statistics_template_id_fkey'),
sa.PrimaryKeyConstraint('id', name='template_statistics_pkey')
)

View File

@@ -11,7 +11,6 @@ from app.models import (
NotificationHistory,
Job,
NotificationStatistics,
TemplateStatistics,
ScheduledNotification,
NOTIFICATION_STATUS_TYPES,
NOTIFICATION_STATUS_TYPES_FAILED,
@@ -590,7 +589,6 @@ def test_create_notification_creates_notification_with_personalisation(notify_db
sample_job, mmg_provider):
assert Notification.query.count() == 0
assert NotificationStatistics.query.count() == 0
assert TemplateStatistics.query.count() == 0
data = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
template=sample_template_with_placeholders,
@@ -614,7 +612,6 @@ def test_create_notification_creates_notification_with_personalisation(notify_db
def test_save_notification_creates_sms(sample_template, sample_job, mmg_provider):
assert Notification.query.count() == 0
assert NotificationStatistics.query.count() == 0
assert TemplateStatistics.query.count() == 0
data = _notification_json(sample_template, job_id=sample_job.id)
@@ -633,10 +630,9 @@ def test_save_notification_creates_sms(sample_template, sample_job, mmg_provider
assert notification_from_db.status == 'created'
def test_save_notification_and_create_email(sample_email_template, sample_job, ses_provider):
def test_save_notification_and_create_email(sample_email_template, sample_job):
assert Notification.query.count() == 0
assert NotificationStatistics.query.count() == 0
assert TemplateStatistics.query.count() == 0
data = _notification_json(sample_email_template, job_id=sample_job.id)
@@ -761,7 +757,6 @@ def test_not_save_notification_and_not_create_stats_on_commit_error(sample_templ
assert Notification.query.count() == 0
assert Job.query.get(sample_job.id).notifications_sent == 0
assert NotificationStatistics.query.count() == 0
assert TemplateStatistics.query.count() == 0
def test_save_notification_and_increment_job(sample_template, sample_job, mmg_provider):

View File

@@ -32,7 +32,6 @@ from app.dao.service_permissions_dao import dao_add_service_permission, dao_remo
from app.dao.users_dao import save_model_user
from app.models import (
NotificationStatistics,
TemplateStatistics,
ProviderStatistics,
VerifyCode,
ApiKey,
@@ -55,7 +54,6 @@ from app.models import (
EMAIL_TYPE,
SMS_TYPE,
LETTER_TYPE,
INTERNATIONAL_SMS_TYPE,
SERVICE_PERMISSION_TYPES
)
@@ -433,7 +431,6 @@ def test_delete_service_and_associated_objects(notify_db,
delete_service_and_all_associated_db_objects(sample_service)
assert NotificationStatistics.query.count() == 0
assert TemplateStatistics.query.count() == 0
assert ProviderStatistics.query.count() == 0
assert VerifyCode.query.count() == 0
assert ApiKey.query.count() == 0