mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Add a new data model LETTER_BRANDING to store the letters. Add a new data model SERVICE_LETTER_BRANDING to map the service to the letter brand.
This will replace services.dvla_organisation_id and dvla_organisation.
This commit is contained in:
@@ -249,6 +249,23 @@ class DVLAOrganisation(db.Model):
|
|||||||
filename = db.Column(db.String(255), nullable=False)
|
filename = db.Column(db.String(255), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class LetterBranding(db.Model):
|
||||||
|
__tablename__ = 'letter_branding'
|
||||||
|
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
||||||
|
name = db.Column(db.String(255), unique=True, nullable=False)
|
||||||
|
filename = db.Column(db.String(255), unique=True, nullable=False)
|
||||||
|
domain = db.Column(db.Text, unique=True, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
|
service_letter_branding = db.Table(
|
||||||
|
'service_letter_branding',
|
||||||
|
db.Model.metadata,
|
||||||
|
# service_id is a primary key as you can only have one letter branding per service
|
||||||
|
db.Column('service_id', UUID(as_uuid=True), db.ForeignKey('services.id'), primary_key=True, nullable=False),
|
||||||
|
db.Column('letter_branding_id', UUID(as_uuid=True), db.ForeignKey('letter_branding.id'), nullable=False),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
INTERNATIONAL_SMS_TYPE = 'international_sms'
|
INTERNATIONAL_SMS_TYPE = 'international_sms'
|
||||||
INBOUND_SMS_TYPE = 'inbound_sms'
|
INBOUND_SMS_TYPE = 'inbound_sms'
|
||||||
SCHEDULE_NOTIFICATIONS = 'schedule_notifications'
|
SCHEDULE_NOTIFICATIONS = 'schedule_notifications'
|
||||||
|
|||||||
52
migrations/versions/0251_letter_branding_table.py
Normal file
52
migrations/versions/0251_letter_branding_table.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0251_letter_branding_table
|
||||||
|
Revises: 0250_drop_stats_template_table
|
||||||
|
Create Date: 2019-01-17 15:45:33.242955
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
revision = '0251_letter_branding_table'
|
||||||
|
down_revision = '0250_drop_stats_template_table'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table('letter_branding',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=255), nullable=False),
|
||||||
|
sa.Column('filename', sa.String(length=255), nullable=False),
|
||||||
|
sa.Column('domain', sa.Text(), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('domain'),
|
||||||
|
sa.UniqueConstraint('filename'),
|
||||||
|
sa.UniqueConstraint('name')
|
||||||
|
)
|
||||||
|
op.create_table('service_letter_branding',
|
||||||
|
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('letter_branding_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['letter_branding_id'], ['letter_branding.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('service_id')
|
||||||
|
)
|
||||||
|
|
||||||
|
op.get_bind()
|
||||||
|
|
||||||
|
op.execute("""INSERT INTO letter_branding (id, name, filename, domain)
|
||||||
|
SELECT uuid_in(md5(random()::text)::cstring), name, filename, null
|
||||||
|
from dvla_organisation""")
|
||||||
|
|
||||||
|
op.execute("""INSERT INTO service_letter_branding (service_id, letter_branding_id)
|
||||||
|
SELECT S.id, LB.id
|
||||||
|
FROM services s
|
||||||
|
JOIN dvla_organisation d on (s.dvla_organisation_id = d.id)
|
||||||
|
JOIN letter_branding lb on (lb.filename = d.filename)
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table('service_letter_branding')
|
||||||
|
op.drop_table('letter_branding')
|
||||||
Reference in New Issue
Block a user