"""update elevations_processing enum

Revision ID: ef18bfbcc613
Revises: c59425f77851
Create Date: 2025-11-12 12:15:42.977410

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ef18bfbcc613'
down_revision = 'c59425f77851'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("ALTER TYPE elevations_processing RENAME TO elevations_processing_old")
    op.execute("CREATE TYPE elevations_processing AS ENUM('NONE', 'OPEN_ELEVATION', 'OPEN_ELEVATION_SMOOTH', 'VALHALLA')")
    op.execute(
        """
        ALTER TABLE users 
            ALTER COLUMN missing_elevations_processing DROP DEFAULT,
            ALTER COLUMN missing_elevations_processing TYPE elevations_processing USING missing_elevations_processing::text::elevations_processing,
            ALTER COLUMN missing_elevations_processing SET DEFAULT 'NONE';
        ALTER TABLE workouts 
            ALTER COLUMN missing_elevations_processing DROP DEFAULT,
            ALTER COLUMN missing_elevations_processing TYPE elevations_processing USING missing_elevations_processing::text::elevations_processing,
            ALTER COLUMN missing_elevations_processing SET DEFAULT 'NONE';
    """
    )
    op.execute("DROP TYPE elevations_processing_old")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    op.execute("UPDATE users SET missing_elevations_processing = 'NONE' WHERE missing_elevations_processing = 'VALHALLA';")
    op.execute("UPDATE workouts SET missing_elevations_processing = 'NONE' WHERE missing_elevations_processing = 'VALHALLA';")
    op.execute(
        "ALTER TYPE elevations_processing RENAME TO elevations_processing_old")
    op.execute(
        "CREATE TYPE elevations_processing AS ENUM('NONE', 'OPEN_ELEVATION', 'OPEN_ELEVATION_SMOOTH')")
    op.execute(
        """
        ALTER TABLE users 
            ALTER COLUMN missing_elevations_processing DROP DEFAULT,
            ALTER COLUMN missing_elevations_processing TYPE elevations_processing USING missing_elevations_processing::text::elevations_processing,
            ALTER COLUMN missing_elevations_processing SET DEFAULT 'NONE';
        ALTER TABLE workouts 
            ALTER COLUMN missing_elevations_processing DROP DEFAULT,
            ALTER COLUMN missing_elevations_processing TYPE elevations_processing USING missing_elevations_processing::text::elevations_processing,
            ALTER COLUMN missing_elevations_processing SET DEFAULT 'NONE';
    """
    )
    op.execute("DROP TYPE elevations_processing_old")

