"""Add vehicle demand fields and service configuration.""" from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql revision = "0024_vehicle_demand" down_revision = "0023_detail_concierge_advisor" branch_labels = None depends_on = None def upgrade() -> None: op.add_column("Lead", sa.Column("leadType", sa.String(), nullable=False, server_default="general")) op.add_column("Lead", sa.Column("contactName", sa.String(), nullable=True)) op.add_column("Lead", sa.Column("customerId", sa.String(), nullable=True)) op.add_column("Lead", sa.Column("vehicleDemand", postgresql.JSONB(astext_type=sa.Text()), nullable=True)) op.create_index("ix_Lead_leadType", "Lead", ["leadType"]) op.create_index("ix_Lead_customerId", "Lead", ["customerId"]) op.create_foreign_key("fk_Lead_customerId_Customer", "Lead", "Customer", ["customerId"], ["id"], ondelete="SET NULL") op.alter_column("Lead", "leadType", server_default=None) op.create_table( "VehicleServiceConfig", sa.Column("id", sa.String(), nullable=False), sa.Column("introTitle", sa.String(), nullable=False), sa.Column("intro", sa.Text(), nullable=False), sa.Column("serviceSections", postgresql.JSONB(astext_type=sa.Text()), nullable=False, server_default=sa.text("'[]'::jsonb")), sa.Column("advantages", postgresql.JSONB(astext_type=sa.Text()), nullable=False, server_default=sa.text("'[]'::jsonb")), sa.Column("processSteps", postgresql.JSONB(astext_type=sa.Text()), nullable=False, server_default=sa.text("'[]'::jsonb")), sa.Column("isActive", sa.Boolean(), nullable=False, server_default=sa.text("true")), sa.Column("createdAt", sa.DateTime(), nullable=False), sa.Column("updatedAt", sa.DateTime(), nullable=False), sa.PrimaryKeyConstraint("id"), ) op.create_index("ix_VehicleServiceConfig_isActive", "VehicleServiceConfig", ["isActive"]) op.alter_column("VehicleServiceConfig", "serviceSections", server_default=None) op.alter_column("VehicleServiceConfig", "advantages", server_default=None) op.alter_column("VehicleServiceConfig", "processSteps", server_default=None) op.alter_column("VehicleServiceConfig", "isActive", server_default=None) def downgrade() -> None: op.drop_index("ix_VehicleServiceConfig_isActive", table_name="VehicleServiceConfig") op.drop_table("VehicleServiceConfig") op.drop_constraint("fk_Lead_customerId_Customer", "Lead", type_="foreignkey") op.drop_index("ix_Lead_customerId", table_name="Lead") op.drop_index("ix_Lead_leadType", table_name="Lead") op.drop_column("Lead", "vehicleDemand") op.drop_column("Lead", "customerId") op.drop_column("Lead", "contactName") op.drop_column("Lead", "leadType")