改进 迁移

This commit is contained in:
iVampireSP.com 2023-01-14 18:05:18 +08:00
parent 0cdbe75340
commit 44b907818f
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 3 additions and 40 deletions

View File

@ -14,7 +14,7 @@ public function up(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //
$table->decimal('balances', 10)->default(0)->after('password'); $table->decimal('balance', 10)->default(0)->after('password');
// drop column if exists // drop column if exists
if (Schema::hasColumn('users', 'drops')) { if (Schema::hasColumn('users', 'drops')) {
@ -32,7 +32,7 @@ public function down(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //
$table->dropColumn('balances'); $table->dropColumn('balance');
}); });
} }
}; };

View File

@ -14,7 +14,7 @@ public function up(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //
$table->dateTime('banned_at')->nullable()->comment('封禁时间')->after('balances'); $table->dateTime('banned_at')->nullable()->comment('封禁时间')->after('balance');
// reason // reason
$table->string('banned_reason')->nullable()->after('banned_at'); $table->string('banned_reason')->nullable()->after('banned_at');
}); });

View File

@ -1,37 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
// if it has balances
if (Schema::hasColumn('users', 'balances')) {
$table->renameColumn('balances', 'balance');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
if (Schema::hasColumn('users', 'balance')) {
$table->renameColumn('balance', 'balances');
}
});
}
};