mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
add notification_history table
table will be used for storing archival versions of notifications. It's an exact duplicate of notifications table, but with the following modifications: * removed _personalisation * removed to * removed content_char_count All foreign keys to other tables still exist. additionally, removed defaults (for id and created_at) since they'll be set when we create, and we should ensure that we don't forget about them when inserting/udpating this table.
This commit is contained in:
@@ -332,7 +332,7 @@ class VerifyCode(db.Model):
|
|||||||
|
|
||||||
NOTIFICATION_STATUS_TYPES = ['created', 'sending', 'delivered', 'pending', 'failed',
|
NOTIFICATION_STATUS_TYPES = ['created', 'sending', 'delivered', 'pending', 'failed',
|
||||||
'technical-failure', 'temporary-failure', 'permanent-failure']
|
'technical-failure', 'temporary-failure', 'permanent-failure']
|
||||||
|
NOTIFICATION_STATUS_TYPES_ENUM = db.Enum(*NOTIFICATION_STATUS_TYPES, name='notify_status_type')
|
||||||
|
|
||||||
class Notification(db.Model):
|
class Notification(db.Model):
|
||||||
|
|
||||||
@@ -370,8 +370,7 @@ class Notification(db.Model):
|
|||||||
unique=False,
|
unique=False,
|
||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.utcnow)
|
onupdate=datetime.datetime.utcnow)
|
||||||
status = db.Column(
|
status = db.Column(NOTIFICATION_STATUS_TYPES_ENUM, nullable=False, default='created')
|
||||||
db.Enum(*NOTIFICATION_STATUS_TYPES, name='notify_status_type'), nullable=False, default='created')
|
|
||||||
reference = db.Column(db.String, nullable=True, index=True)
|
reference = db.Column(db.String, nullable=True, index=True)
|
||||||
_personalisation = db.Column(db.String, nullable=True)
|
_personalisation = db.Column(db.String, nullable=True)
|
||||||
|
|
||||||
@@ -387,6 +386,30 @@ class Notification(db.Model):
|
|||||||
self._personalisation = encryption.encrypt(personalisation)
|
self._personalisation = encryption.encrypt(personalisation)
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationHistory(db.Model):
|
||||||
|
__tablename__ = 'notification_history'
|
||||||
|
|
||||||
|
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
||||||
|
job_id = db.Column(UUID(as_uuid=True), db.ForeignKey('jobs.id'), index=True, unique=False)
|
||||||
|
job = db.relationship('Job')
|
||||||
|
job_row_number = db.Column(db.Integer, nullable=True)
|
||||||
|
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False)
|
||||||
|
service = db.relationship('Service')
|
||||||
|
template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, unique=False)
|
||||||
|
template = db.relationship('Template')
|
||||||
|
template_version = db.Column(db.Integer, nullable=False)
|
||||||
|
api_key_id = db.Column(UUID(as_uuid=True), db.ForeignKey('api_keys.id'), index=True, unique=False)
|
||||||
|
api_key = db.relationship('ApiKey')
|
||||||
|
key_type = db.Column(db.String, db.ForeignKey('key_types.name'), index=True, unique=False, nullable=False)
|
||||||
|
notification_type = db.Column(notification_types, nullable=False)
|
||||||
|
created_at = db.Column(db.DateTime, index=False, unique=False, nullable=False)
|
||||||
|
sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
|
||||||
|
sent_by = db.Column(db.String, nullable=True)
|
||||||
|
updated_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
|
||||||
|
status = db.Column(NOTIFICATION_STATUS_TYPES_ENUM, nullable=False, default='created')
|
||||||
|
reference = db.Column(db.String, nullable=True, index=True)
|
||||||
|
|
||||||
|
|
||||||
INVITED_USER_STATUS_TYPES = ['pending', 'accepted', 'cancelled']
|
INVITED_USER_STATUS_TYPES = ['pending', 'accepted', 'cancelled']
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
60
migrations/versions/0041_notification_history.py
Normal file
60
migrations/versions/0041_notification_history.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 807f0b497157
|
||||||
|
Revises: 0039_fix_notifications
|
||||||
|
Create Date: 2016-07-07 13:15:35.503107
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '807f0b497157'
|
||||||
|
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('notification_type', sa.Enum('email', 'sms', 'letter', name='notification_type'), 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', sa.Enum('created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure', 'temporary-failure', 'permanent-failure', name='notify_status_type'), 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)
|
||||||
|
### 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')
|
||||||
|
### end Alembic commands ###
|
||||||
Reference in New Issue
Block a user