From b71f6777e9151bcc0badb6b0e0d546fb30d13457 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 10 Jul 2018 11:35:20 +0100 Subject: [PATCH] Create a table SERVICE_DATA_RETENTION to store the number of days the notification is to be kept for. --- app/models.py | 12 +++++++ .../versions/0202_service_data_retention.py | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 migrations/versions/0202_service_data_retention.py diff --git a/app/models.py b/app/models.py index 27851740b..2f07597dc 100644 --- a/app/models.py +++ b/app/models.py @@ -1843,3 +1843,15 @@ class Complaint(db.Model): 'complaint_date': self.complaint_date.strftime(DATETIME_FORMAT) if self.complaint_date else None, 'created_at': self.created_at.strftime(DATETIME_FORMAT), } + + +class ServiceDataRetention(db.Model): + __tablename__ = 'service_data_retention' + + 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'), unique=False, index=True, nullable=False) + service = db.relationship(Service, backref=db.backref('service_data_retention')) + notification_type = db.Column(notification_types, nullable=False) + days_of_retention = db.Column(db.Integer, nullable=False) + created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) + updated_at = db.Column(db.DateTime, nullable=True, default=datetime.datetime.utcnow) diff --git a/migrations/versions/0202_service_data_retention.py b/migrations/versions/0202_service_data_retention.py new file mode 100644 index 000000000..a85ead60f --- /dev/null +++ b/migrations/versions/0202_service_data_retention.py @@ -0,0 +1,35 @@ +""" + +Revision ID: 0202_service_data_retention +Revises: 0201_another_letter_org +Create Date: 2018-07-10 11:22:01.761829 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = '0202_service_data_retention' +down_revision = '0201_another_letter_org' + + +def upgrade(): + op.create_table('service_data_retention', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('notification_type', + postgresql.ENUM(name='notification_type', create_type=False), + nullable=False), + sa.Column('days_of_retention', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_service_data_retention_service_id'), 'service_data_retention', ['service_id'], + unique=False) + + +def downgrade(): + op.drop_index(op.f('ix_service_data_retention_service_id'), table_name='service_data_retention') + op.drop_table('service_data_retention')