<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * Fix "data too long for column" for long stream URLs.
     */
    public function up(): void
    {
        $driver = DB::getDriverName();
        if ($driver === 'mysql') {
            DB::statement('ALTER TABLE live_tvs MODIFY stream_from TEXT NULL, MODIFY stream_label TEXT NULL, MODIFY stream_url TEXT NULL');
        } elseif ($driver === 'pgsql') {
            DB::statement('ALTER TABLE live_tvs ALTER COLUMN stream_from TYPE TEXT, ALTER COLUMN stream_label TYPE TEXT, ALTER COLUMN stream_url TYPE TEXT');
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $driver = DB::getDriverName();
        if ($driver === 'mysql') {
            DB::statement('ALTER TABLE live_tvs MODIFY stream_from VARCHAR(191) NULL, MODIFY stream_label VARCHAR(191) NULL, MODIFY stream_url VARCHAR(191) NULL');
        } elseif ($driver === 'pgsql') {
            DB::statement('ALTER TABLE live_tvs ALTER COLUMN stream_from TYPE VARCHAR(191), ALTER COLUMN stream_label TYPE VARCHAR(191), ALTER COLUMN stream_url TYPE VARCHAR(191)');
        }
    }
};
