From b0de3ba4d9d65d4a80060d34fd48001e99147394 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Thu, 15 Feb 2018 14:27:38 +0000 Subject: [PATCH] Create DailySortedLetter table The response files we receive from the DVLA when we send letters contain a row for each letter and a field with a value of 'Unsorted' or 'Sorted'. This table will be used to store the total number of 'Unsorted' and 'Sorted' letter notifications per day. --- app/models.py | 10 +++++++ .../0173_create_daily_sorted_letter.py | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 migrations/versions/0173_create_daily_sorted_letter.py diff --git a/app/models.py b/app/models.py index 6678d91e6..47256a63d 100644 --- a/app/models.py +++ b/app/models.py @@ -1752,3 +1752,13 @@ class StatsTemplateUsageByMonth(db.Model): 'year': self.year, 'count': self.count } + + +class DailySortedLetter(db.Model): + __tablename__ = "daily_sorted_letter" + + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + billing_day = db.Column(db.Date, nullable=False, index=True, unique=True) + unsorted_count = db.Column(db.Integer, nullable=False, default=0) + sorted_count = db.Column(db.Integer, nullable=False, default=0) + updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow) diff --git a/migrations/versions/0173_create_daily_sorted_letter.py b/migrations/versions/0173_create_daily_sorted_letter.py new file mode 100644 index 000000000..3215134b9 --- /dev/null +++ b/migrations/versions/0173_create_daily_sorted_letter.py @@ -0,0 +1,30 @@ +""" + +Revision ID: 0173_create_daily_sorted_letter +Revises: 0172_deprioritise_examples +Create Date: 2018-03-01 11:53:32.964256 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = '0173_create_daily_sorted_letter' +down_revision = '0172_deprioritise_examples' + + +def upgrade(): + op.create_table('daily_sorted_letter', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('billing_day', sa.Date(), nullable=False), + sa.Column('unsorted_count', sa.Integer(), nullable=False), + sa.Column('sorted_count', sa.Integer(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_daily_sorted_letter_billing_day'), 'daily_sorted_letter', ['billing_day'], unique=True) + + +def downgrade(): + op.drop_index(op.f('ix_daily_sorted_letter_billing_day'), table_name='daily_sorted_letter') + op.drop_table('daily_sorted_letter')