<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class ModifyGenderInUserProfileTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Primero eliminamos la restricción existente
        DB::statement('ALTER TABLE user_profile DROP CONSTRAINT IF EXISTS user_profile_gender_check');
        
        // Convertimos la columna a VARCHAR
        DB::statement('ALTER TABLE user_profile ALTER COLUMN gender TYPE VARCHAR(1)');
        
        // Agregamos la nueva restricción
        DB::statement("ALTER TABLE user_profile ADD CONSTRAINT user_profile_gender_check CHECK (gender IN ('f', 'm', 'o', 'F', 'M', 'O'))");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Eliminamos la restricción check
        DB::statement('ALTER TABLE user_profile DROP CONSTRAINT IF EXISTS user_profile_gender_check');
        
        // Volvemos a crear el enum original
        DB::statement("ALTER TABLE user_profile ALTER COLUMN gender TYPE VARCHAR(1)");
        DB::statement("ALTER TABLE user_profile ADD CONSTRAINT user_profile_gender_check CHECK (gender IN ('f', 'm', 'o'))");
    }
} 