feat: enhance CreditsPlus and NavbarManager extensions with improved role checks, route handling, and migration logic for better functionality and compatibility across databases
This commit is contained in:
@@ -1,19 +1,52 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// For MySQL, we need to alter the enum column to include new values
|
||||
DB::statement("ALTER TABLE navbar_links MODIFY COLUMN link_type ENUM('route', 'path', 'url', 'product', 'category') DEFAULT 'route'");
|
||||
$driver = Schema::getConnection()->getDriverName();
|
||||
|
||||
if ($driver === 'mysql') {
|
||||
// For MySQL, use ALTER TABLE to modify enum
|
||||
DB::statement("ALTER TABLE navbar_links MODIFY COLUMN link_type ENUM('route', 'path', 'url', 'product', 'category') DEFAULT 'route'");
|
||||
} else {
|
||||
// For other databases (PostgreSQL, SQLite), drop and recreate column
|
||||
Schema::table('navbar_links', function (Blueprint $table) {
|
||||
$table->string('link_type_temp')->default('route');
|
||||
});
|
||||
|
||||
DB::table('navbar_links')->update(['link_type_temp' => DB::raw('link_type')]);
|
||||
|
||||
Schema::table('navbar_links', function (Blueprint $table) {
|
||||
$table->dropColumn('link_type');
|
||||
});
|
||||
|
||||
Schema::table('navbar_links', function (Blueprint $table) {
|
||||
$table->string('link_type')->default('route')->after('type');
|
||||
});
|
||||
|
||||
DB::table('navbar_links')->update(['link_type' => DB::raw('link_type_temp')]);
|
||||
|
||||
Schema::table('navbar_links', function (Blueprint $table) {
|
||||
$table->dropColumn('link_type_temp');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// Revert back to original enum values
|
||||
DB::statement("ALTER TABLE navbar_links MODIFY COLUMN link_type ENUM('route', 'path', 'url') DEFAULT 'route'");
|
||||
$driver = Schema::getConnection()->getDriverName();
|
||||
|
||||
if ($driver === 'mysql') {
|
||||
DB::statement("ALTER TABLE navbar_links MODIFY COLUMN link_type ENUM('route', 'path', 'url') DEFAULT 'route'");
|
||||
} else {
|
||||
// For rollback on other databases, just keep as string
|
||||
// Data with 'product' or 'category' will remain but may cause issues
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user