fix: music table fixed
This commit is contained in:
+23
-3
@@ -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
|
||||
// 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)');
|
||||
|
||||
// Then make it nullable if needed
|
||||
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
|
||||
// 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)');
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user