"""external cp extra sans

Revision ID: 04398db10434
Revises: 24a548bfce3e
Create Date: 2025-11-20 09:45:26.563717

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '04398db10434'
down_revision: Union[str, Sequence[str], None] = '24a548bfce3e'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('k8s_ext_control_planes', sa.Column('extra_sans', sa.String(length=2530), nullable=True))

    op.execute("""
        UPDATE k8s_ext_control_planes
        SET extra_sans = name || '.' || zone
    """)

    op.alter_column('k8s_ext_control_planes', 'extra_sans', nullable=False)

    op.drop_column('k8s_ext_control_planes', 'name')
    op.drop_column('k8s_ext_control_planes', 'zone')
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('k8s_ext_control_planes', sa.Column('zone', sa.VARCHAR(length=253), autoincrement=False, nullable=False))
    op.add_column('k8s_ext_control_planes', sa.Column('name', sa.VARCHAR(length=253), autoincrement=False, nullable=False))
    op.drop_column('k8s_ext_control_planes', 'extra_sans')
    # ### end Alembic commands ###
