fix: music table fixed
This commit is contained in:
+31
-11
@@ -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
|
||||||
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE integer USING (duration::integer)');
|
$driver = DB::connection()->getDriverName();
|
||||||
|
|
||||||
// Then make it nullable if needed
|
if ($driver === 'pgsql') {
|
||||||
Schema::table('music', function (Blueprint $table) {
|
// PostgreSQL: Use raw statement with USING clause
|
||||||
$table->integer('duration')->nullable()->change();
|
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
|
public function down(): void
|
||||||
{
|
{
|
||||||
// Convert back to string/text
|
// Get the database driver
|
||||||
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE text USING (duration::text)');
|
$driver = DB::connection()->getDriverName();
|
||||||
|
|
||||||
Schema::table('music', function (Blueprint $table) {
|
if ($driver === 'pgsql') {
|
||||||
$table->string('duration')->nullable()->change();
|
// 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