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\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
@@ -11,13 +12,22 @@
*/
public function up(): void
{
// For PostgreSQL, we need to use a raw statement with USING clause
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE integer USING (duration::integer)');
// Get the database driver
$driver = DB::connection()->getDriverName();
// Then make it nullable if needed
Schema::table('music', function (Blueprint $table) {
$table->integer('duration')->nullable()->change();
});
if ($driver === 'pgsql') {
// PostgreSQL: Use raw statement with USING clause
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE integer USING (duration::integer)');
Schema::table('music', function (Blueprint $table) {
$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
{
// Convert back to string/text
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE text USING (duration::text)');
// Get the database driver
$driver = DB::connection()->getDriverName();
Schema::table('music', function (Blueprint $table) {
$table->string('duration')->nullable()->change();
});
if ($driver === 'pgsql') {
// PostgreSQL: Convert back to text
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE text USING (duration::text)');
Schema::table('music', function (Blueprint $table) {
$table->string('duration')->nullable()->change();
});
} elseif ($driver === 'mysql') {
// MySQL: Change back to string
Schema::table('music', function (Blueprint $table) {
$table->string('duration')->nullable()->change();
});
}
}
};