Files

92 lines
2.8 KiB
Python
Raw Permalink Normal View History

2016-08-04 12:35:47 +01:00
"""empty message
Revision ID: 0046_organisations_and_branding
Revises: 0045_billable_units
Create Date: 2016-08-04 12:00:43.682610
"""
# revision identifiers, used by Alembic.
2023-08-29 14:54:30 -07:00
revision = "0046_organisations_and_branding"
down_revision = "0045_billable_units"
2016-08-04 12:35:47 +01:00
import sqlalchemy as sa
2023-12-08 21:43:52 -05:00
from alembic import op
2016-08-04 12:35:47 +01:00
from sqlalchemy.dialects import postgresql
2023-08-29 14:54:30 -07:00
2016-08-04 12:35:47 +01:00
def upgrade():
2023-08-29 14:54:30 -07:00
op.create_table(
"branding_type",
sa.Column("name", sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint("name"),
2016-08-04 12:35:47 +01:00
)
2023-08-29 14:54:30 -07:00
op.create_table(
"organisation",
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"),
2016-08-04 12:35:47 +01:00
)
2023-08-29 14:54:30 -07:00
op.add_column("services", sa.Column("branding", sa.String(length=255)))
op.add_column(
"services", sa.Column("organisation_id", postgresql.UUID(as_uuid=True))
)
op.add_column("services_history", sa.Column("branding", sa.String(length=255)))
op.add_column(
"services_history", sa.Column("organisation_id", postgresql.UUID(as_uuid=True))
)
2016-08-04 12:35:47 +01:00
op.execute("INSERT INTO branding_type VALUES ('govuk'), ('org'), ('both')")
2016-08-04 12:35:47 +01:00
2016-08-05 16:32:55 +01:00
# insert UKVI data as initial test data. hex and crest pulled from alphagov/whitehall
2023-08-29 14:54:30 -07:00
op.execute(
"""INSERT INTO organisation VALUES (
2016-08-05 16:32:55 +01:00
'9d25d02d-2915-4e98-874b-974e123e8536',
'#9325b2',
'ho_crest_27px_x2.png',
'UK Visas and Immigration'
2023-08-29 14:54:30 -07:00
)"""
)
2016-08-04 12:35:47 +01:00
op.execute("UPDATE services SET branding='govuk'")
op.execute("UPDATE services_history SET branding='govuk'")
2023-08-29 14:54:30 -07:00
op.alter_column("services", "branding", nullable=False)
op.alter_column("services_history", "branding", nullable=False)
2016-08-04 12:35:47 +01:00
2023-08-29 14:54:30 -07:00
op.create_index(
op.f("ix_services_branding"), "services", ["branding"], unique=False
)
op.create_index(
op.f("ix_services_organisation_id"),
"services",
["organisation_id"],
unique=False,
)
op.create_index(
op.f("ix_services_history_branding"),
"services_history",
["branding"],
unique=False,
)
op.create_index(
op.f("ix_services_history_organisation_id"),
"services_history",
["organisation_id"],
unique=False,
)
2016-08-04 12:35:47 +01:00
2023-08-29 14:54:30 -07:00
op.create_foreign_key(None, "services", "branding_type", ["branding"], ["name"])
op.create_foreign_key(None, "services", "organisation", ["organisation_id"], ["id"])
2016-08-04 12:35:47 +01:00
def downgrade():
2023-08-29 14:54:30 -07:00
op.drop_column("services_history", "organisation_id")
op.drop_column("services_history", "branding")
op.drop_column("services", "organisation_id")
op.drop_column("services", "branding")
op.drop_table("organisation")
op.drop_table("branding_type")