fix: music table fixed

This commit is contained in:
2026-05-30 09:19:50 +03:30
parent bac1e46848
commit 8923810df3
@@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration return new class extends Migration
{ {
@@ -11,13 +12,22 @@
*/ */
public function up(): void public function up(): void
{ {
// For PostgreSQL, we need to use a raw statement with USING clause // Get the database driver
$driver = DB::connection()->getDriverName();
if ($driver === 'pgsql') {
// PostgreSQL: Use raw statement with USING clause
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE integer USING (duration::integer)'); DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE integer USING (duration::integer)');
// Then make it nullable if needed
Schema::table('music', function (Blueprint $table) { Schema::table('music', function (Blueprint $table) {
$table->integer('duration')->nullable()->change(); $table->integer('duration')->nullable()->change();
}); });
} elseif ($driver === 'mysql') {
// MySQL: Can directly change column type
Schema::table('music', function (Blueprint $table) {
$table->integer('duration')->nullable()->change();
});
}
} }
/** /**
@@ -25,11 +35,21 @@ public function up(): void
*/ */
public function down(): void public function down(): void
{ {
// Convert back to string/text // Get the database driver
$driver = DB::connection()->getDriverName();
if ($driver === 'pgsql') {
// PostgreSQL: Convert back to text
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE text USING (duration::text)'); DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE text USING (duration::text)');
Schema::table('music', function (Blueprint $table) { Schema::table('music', function (Blueprint $table) {
$table->string('duration')->nullable()->change(); $table->string('duration')->nullable()->change();
}); });
} elseif ($driver === 'mysql') {
// MySQL: Change back to string
Schema::table('music', function (Blueprint $table) {
$table->string('duration')->nullable()->change();
});
}
} }
}; };