61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
"""Add long-form detail content to homepage team buildings.
|
|
|
|
Revision ID: 0020_home_team_building_details
|
|
Revises: 0019_home_wild_archive_images
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy import inspect
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
revision = "0020_home_team_building_details"
|
|
down_revision = "0019_home_wild_archive_images"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
inspector = inspect(bind)
|
|
if "HomeTeamBuilding" not in set(inspector.get_table_names()):
|
|
return
|
|
column_names = {column["name"] for column in inspector.get_columns("HomeTeamBuilding")}
|
|
if "detailSubtitle" not in column_names:
|
|
op.add_column(
|
|
"HomeTeamBuilding",
|
|
sa.Column("detailSubtitle", sa.String(), nullable=False, server_default=""),
|
|
)
|
|
if "detailParagraphs" not in column_names:
|
|
op.add_column(
|
|
"HomeTeamBuilding",
|
|
sa.Column(
|
|
"detailParagraphs",
|
|
postgresql.JSONB(astext_type=sa.Text()),
|
|
nullable=False,
|
|
server_default=sa.text("'[]'::jsonb"),
|
|
),
|
|
)
|
|
op.execute(
|
|
sa.text(
|
|
'UPDATE "HomeTeamBuilding" '
|
|
'SET "detailSubtitle" = CASE '
|
|
'WHEN "detailSubtitle" IS NULL OR "detailSubtitle" = \'\' THEN "description" '
|
|
'ELSE "detailSubtitle" END, '
|
|
'"detailParagraphs" = CASE '
|
|
'WHEN "detailParagraphs" IS NULL OR jsonb_array_length("detailParagraphs") = 0 '
|
|
'THEN jsonb_build_array("description") '
|
|
'ELSE "detailParagraphs" END '
|
|
'WHERE "detailSubtitle" IS NULL OR "detailSubtitle" = \'\' '
|
|
'OR "detailParagraphs" IS NULL OR jsonb_array_length("detailParagraphs") = 0'
|
|
)
|
|
)
|
|
op.alter_column("HomeTeamBuilding", "detailSubtitle", server_default=None)
|
|
op.alter_column("HomeTeamBuilding", "detailParagraphs", server_default=None)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("HomeTeamBuilding", "detailParagraphs")
|
|
op.drop_column("HomeTeamBuilding", "detailSubtitle")
|