mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
Remove ServiceContactList from db
This commit is contained in:
@@ -18,14 +18,7 @@ from notifications_utils.template import (
|
|||||||
SMSMessageTemplate,
|
SMSMessageTemplate,
|
||||||
)
|
)
|
||||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||||
from sqlalchemy import (
|
from sqlalchemy import CheckConstraint, Index, UniqueConstraint
|
||||||
CheckConstraint,
|
|
||||||
Index,
|
|
||||||
String,
|
|
||||||
UniqueConstraint,
|
|
||||||
and_,
|
|
||||||
func,
|
|
||||||
)
|
|
||||||
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
|
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
|
||||||
from sqlalchemy.ext.associationproxy import association_proxy
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
@@ -561,7 +554,7 @@ class InboundNumber(db.Model):
|
|||||||
__tablename__ = "inbound_numbers"
|
__tablename__ = "inbound_numbers"
|
||||||
|
|
||||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
number = db.Column(db.String(11), unique=True, nullable=False)
|
number = db.Column(db.String(255), unique=True, nullable=False)
|
||||||
provider = db.Column(db.String(), nullable=False)
|
provider = db.Column(db.String(), nullable=False)
|
||||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), unique=True, index=True, nullable=True)
|
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), unique=True, index=True, nullable=True)
|
||||||
service = db.relationship(Service, backref=db.backref("inbound_number", uselist=False))
|
service = db.relationship(Service, backref=db.backref("inbound_number", uselist=False))
|
||||||
@@ -1148,7 +1141,6 @@ class Job(db.Model):
|
|||||||
db.String(255), db.ForeignKey('job_status.name'), index=True, nullable=False, default='pending'
|
db.String(255), db.ForeignKey('job_status.name'), index=True, nullable=False, default='pending'
|
||||||
)
|
)
|
||||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
archived = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
contact_list_id = db.Column(UUID(as_uuid=True), db.ForeignKey('service_contact_list.id'), nullable=True)
|
|
||||||
|
|
||||||
|
|
||||||
VERIFY_CODE_TYPES = [EMAIL_TYPE, SMS_TYPE]
|
VERIFY_CODE_TYPES = [EMAIL_TYPE, SMS_TYPE]
|
||||||
@@ -1956,57 +1948,6 @@ class ServiceDataRetention(db.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ServiceContactList(db.Model):
|
|
||||||
__tablename__ = 'service_contact_list'
|
|
||||||
|
|
||||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
||||||
original_file_name = db.Column(db.String, nullable=False)
|
|
||||||
row_count = db.Column(db.Integer, nullable=False)
|
|
||||||
template_type = db.Column(template_types, nullable=False)
|
|
||||||
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('contact_list'))
|
|
||||||
created_by = db.relationship('User')
|
|
||||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=True)
|
|
||||||
created_at = db.Column(db.DateTime, nullable=False)
|
|
||||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
|
||||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def job_count(self):
|
|
||||||
today = datetime.datetime.utcnow().date()
|
|
||||||
return Job.query.filter(
|
|
||||||
Job.contact_list_id == self.id,
|
|
||||||
func.coalesce(
|
|
||||||
Job.processing_started, Job.created_at
|
|
||||||
) >= today - func.coalesce(ServiceDataRetention.days_of_retention, 7)
|
|
||||||
).outerjoin(
|
|
||||||
ServiceDataRetention, and_(
|
|
||||||
self.service_id == ServiceDataRetention.service_id,
|
|
||||||
func.cast(self.template_type, String) == func.cast(ServiceDataRetention.notification_type, String)
|
|
||||||
)
|
|
||||||
).count()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def has_jobs(self):
|
|
||||||
return bool(Job.query.filter(
|
|
||||||
Job.contact_list_id == self.id,
|
|
||||||
).first())
|
|
||||||
|
|
||||||
def serialize(self):
|
|
||||||
contact_list = {
|
|
||||||
"id": str(self.id),
|
|
||||||
"original_file_name": self.original_file_name,
|
|
||||||
"row_count": self.row_count,
|
|
||||||
"recent_job_count": self.job_count,
|
|
||||||
"has_jobs": self.has_jobs,
|
|
||||||
"template_type": self.template_type,
|
|
||||||
"service_id": str(self.service_id),
|
|
||||||
"created_by": self.created_by.name,
|
|
||||||
"created_at": self.created_at.strftime(DATETIME_FORMAT),
|
|
||||||
}
|
|
||||||
return contact_list
|
|
||||||
|
|
||||||
|
|
||||||
class WebauthnCredential(db.Model):
|
class WebauthnCredential(db.Model):
|
||||||
"""
|
"""
|
||||||
A table that stores data for registered webauthn credentials.
|
A table that stores data for registered webauthn credentials.
|
||||||
|
|||||||
46
migrations/versions/0394_remove_contact_list_.py
Normal file
46
migrations/versions/0394_remove_contact_list_.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0394_remove_contact_list
|
||||||
|
Revises: 0393_remove_crown
|
||||||
|
Create Date: 2023-04-12 13:12:12.683257
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
revision = '0394_remove_contact_list'
|
||||||
|
down_revision = '0393_remove_crown'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_constraint('jobs_contact_list_id_fkey', 'jobs', type_='foreignkey')
|
||||||
|
op.drop_index('ix_service_contact_list_created_by_id', table_name='service_contact_list')
|
||||||
|
op.drop_index('ix_service_contact_list_service_id', table_name='service_contact_list')
|
||||||
|
op.drop_table('service_contact_list')
|
||||||
|
op.drop_column('jobs', 'contact_list_id')
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('jobs', sa.Column('contact_list_id', postgresql.UUID(), autoincrement=False, nullable=True))
|
||||||
|
op.create_table('service_contact_list',
|
||||||
|
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
|
||||||
|
sa.Column('original_file_name', sa.VARCHAR(), autoincrement=False, nullable=False),
|
||||||
|
sa.Column('row_count', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||||
|
sa.Column('template_type', postgresql.ENUM('sms', 'email', 'letter', 'broadcast', name='template_type'), autoincrement=False, nullable=False),
|
||||||
|
sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
|
||||||
|
sa.Column('created_by_id', postgresql.UUID(), autoincrement=False, nullable=True),
|
||||||
|
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
|
||||||
|
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
|
||||||
|
sa.Column('archived', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], name='service_contact_list_created_by_id_fkey'),
|
||||||
|
sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='service_contact_list_service_id_fkey'),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='service_contact_list_pkey')
|
||||||
|
)
|
||||||
|
op.create_index('ix_service_contact_list_service_id', 'service_contact_list', ['service_id'], unique=False)
|
||||||
|
op.create_index('ix_service_contact_list_created_by_id', 'service_contact_list', ['created_by_id'], unique=False)
|
||||||
|
op.create_foreign_key('jobs_contact_list_id_fkey', 'jobs', 'service_contact_list', ['contact_list_id'], ['id'])
|
||||||
|
# ### end Alembic commands ###
|
||||||
Reference in New Issue
Block a user