mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-16 10:12:32 -05:00
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
"""
|
|
|
|
Revision ID: 0161_email_branding
|
|
Revises: 0159_add_historical_redact
|
|
Create Date: 2018-01-30 15:35:12.016574
|
|
|
|
"""
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision = "0161_email_branding"
|
|
down_revision = "0159_add_historical_redact"
|
|
|
|
|
|
def upgrade():
|
|
op.create_table(
|
|
"email_branding",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
|
sa.Column("colour", sa.String(length=7), nullable=True),
|
|
sa.Column("logo", sa.String(length=255), nullable=True),
|
|
sa.Column("name", sa.String(length=255), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_table(
|
|
"service_email_branding",
|
|
sa.Column("service_id", postgresql.UUID(as_uuid=True), nullable=True),
|
|
sa.Column("email_branding_id", postgresql.UUID(as_uuid=True), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["email_branding_id"],
|
|
["email_branding.id"],
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["service_id"],
|
|
["services.id"],
|
|
),
|
|
sa.UniqueConstraint(
|
|
"service_id", name="uix_service_email_branding_one_per_service"
|
|
),
|
|
sa.PrimaryKeyConstraint("service_id"),
|
|
)
|
|
op.execute(
|
|
"""
|
|
INSERT INTO email_branding (id, colour, logo, name)
|
|
SELECT id, colour, logo, name
|
|
FROM organisation
|
|
"""
|
|
)
|
|
op.execute(
|
|
"""
|
|
INSERT INTO service_email_branding (service_id, email_branding_id)
|
|
SELECT id, organisation_id
|
|
FROM services where organisation_id is not null
|
|
"""
|
|
)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_table("service_email_branding")
|
|
op.drop_table("email_branding")
|