改进 迁移

This commit is contained in:
iVampireSP.com 2023-01-14 18:02:27 +08:00
parent db6f14ab79
commit 0cdbe75340
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
50 changed files with 91 additions and 508 deletions

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->id(); $table->id();
@ -32,7 +32,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('users'); Schema::dropIfExists('users');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('password_resets', function (Blueprint $table) { Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index(); $table->string('email')->index();
@ -24,7 +24,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('password_resets'); Schema::dropIfExists('password_resets');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('failed_jobs', function (Blueprint $table) { Schema::create('failed_jobs', function (Blueprint $table) {
$table->id(); $table->id();
@ -28,7 +28,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('failed_jobs'); Schema::dropIfExists('failed_jobs');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('personal_access_tokens', function (Blueprint $table) { Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id(); $table->id();
@ -29,7 +29,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('personal_access_tokens'); Schema::dropIfExists('personal_access_tokens');
} }

View File

@ -1,49 +0,0 @@
<?php
use App\Models\User;
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()
{
Schema::create('drops', function (Blueprint $table) {
$table->id();
// payment
$table->string('payment')->index();
// amount
$table->double('amount', 60, 8)->default(0);
// 汇率
$table->integer('rate')->default(1);
// 实际收入
$table->double('total', 60, 8)->default(0);
$table->boolean('status')->default(0)->index();
$table->foreignIdFor(User::class)->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('drops');
}
};

View File

@ -1,45 +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()
{
Schema::create('transcations', function (Blueprint $table) {
$table->id();
// remote transaction id
$table->string('remote_id')->index();
// drops id
$table->unsignedBigInteger('drops_id')->index();
$table->foreign('drops_id')->references('id')->on('drops');
// payment
$table->string('payment')->index();
// amount
$table->double('amount', 60, 8)->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('transcations');
}
};

View File

@ -1,33 +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()
{
Schema::table('drops', function (Blueprint $table) {
//
$table->string('type')->index()->after('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('drops', function (Blueprint $table) {
// drop column
$table->dropColumn('type');
});
}
};

View File

@ -11,7 +11,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('modules', function (Blueprint $table) { Schema::create('modules', function (Blueprint $table) {
$table->string('id')->index()->primary()->unique(); $table->string('id')->index()->primary()->unique();
@ -23,14 +23,14 @@ public function up()
}); });
// if env is local // if env is local
if (env('APP_ENV') == 'local') { if (config('app.env') == 'local') {
$module = [ $module = [
'id' => 'test', 'id' => 'test',
'name' => 'Example Module', 'name' => 'Example Module',
'api_token' => '123456' 'api_token' => '123456'
]; ];
Module::create($module); (new App\Models\Module)->create($module);
} }
} }
@ -39,7 +39,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('modules'); Schema::dropIfExists('modules');
} }

View File

@ -1,6 +1,5 @@
<?php <?php
use App\Models\Module\ProviderModule;
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;
@ -11,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('hosts', function (Blueprint $table) { Schema::create('hosts', function (Blueprint $table) {
$table->id(); $table->id();
@ -49,7 +48,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('hosts'); Schema::dropIfExists('hosts');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('work_orders', function (Blueprint $table) { Schema::create('work_orders', function (Blueprint $table) {
$table->id(); $table->id();
@ -46,8 +46,8 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('workorders'); Schema::dropIfExists('work_orders');
} }
}; };

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('work_order_replies', function (Blueprint $table) { Schema::create('work_order_replies', function (Blueprint $table) {
$table->id(); $table->id();
@ -18,7 +18,7 @@ public function up()
// content // content
$table->text('content'); $table->text('content');
// workorder id (on delete cascade) // work_order id (on delete cascade)
$table->unsignedBigInteger('work_order_id')->index(); $table->unsignedBigInteger('work_order_id')->index();
$table->foreign('work_order_id')->references('id')->on('work_orders')->onDelete('cascade'); $table->foreign('work_order_id')->references('id')->on('work_orders')->onDelete('cascade');
@ -39,8 +39,8 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('workorder_replies'); Schema::dropIfExists('work_order_replies');
} }
}; };

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('notifications', function (Blueprint $table) { Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary(); $table->uuid('id')->primary();
@ -27,7 +27,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('notifications'); Schema::dropIfExists('notifications');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //
@ -23,7 +23,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// drop // drop

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('work_order_replies', function (Blueprint $table) { Schema::table('work_order_replies', function (Blueprint $table) {
// //
@ -24,7 +24,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('work_order_replies', function (Blueprint $table) { Schema::table('work_order_replies', function (Blueprint $table) {
// //

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('modules', function (Blueprint $table) { Schema::table('modules', function (Blueprint $table) {
// //
@ -23,10 +23,11 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('modules', function (Blueprint $table) { Schema::table('modules', function (Blueprint $table) {
// //
$table->dropColumn('url');
}); });
} }
}; };

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::dropIfExists('tasks'); Schema::dropIfExists('tasks');
@ -46,7 +46,7 @@ function (Blueprint $table) {
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
// //
Schema::dropIfExists('tasks'); Schema::dropIfExists('tasks');

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //
@ -23,7 +23,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //
@ -28,7 +28,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('balances', function (Blueprint $table) { Schema::create('balances', function (Blueprint $table) {
$table->id(); $table->id();
@ -43,7 +43,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('balances'); Schema::dropIfExists('balances');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
$table->foreign('module_id')->references('id')->on('modules')->cascadeOnUpdate(); $table->foreign('module_id')->references('id')->on('modules')->cascadeOnUpdate();
@ -22,10 +22,11 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// // rollback
$table->dropForeign(['module_id']);
}); });
} }
}; };

View File

@ -1,35 +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()
{
Schema::table('users', function (Blueprint $table) {
//
// drop column if exists
if (Schema::hasColumn('users', 'drops')) {
$table->dropColumn('drops');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
};

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //
@ -25,7 +25,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// //

View File

@ -1,27 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::dropIfExists('transcations');
}
// /**
// * Reverse the migrations.
// *
// * @return void
// */
// public function down()
// {
// //
// }
};

View File

@ -10,12 +10,12 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
// if transaction collection exists // if transaction collection exists
if (Schema::connection('mongodb')->hasTable('transactions')) { if (Schema::connection('mongodb')->hasTable('transactions')) {
return true; return;
} }
Schema::connection('mongodb')->create('transactions', function (Blueprint $collection) { Schema::connection('mongodb')->create('transactions', function (Blueprint $collection) {
@ -40,7 +40,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::connection('mongodb')->dropIfExists('transactions'); Schema::connection('mongodb')->dropIfExists('transactions');
} }

View File

@ -1,52 +0,0 @@
<?php
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Cache;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
$decimal = config('drops.decimal');
User::chunk(100, function ($users) use ($decimal) {
foreach ($users as $user) {
$cache_key = 'user_drops_' . $user->id;
$drops = Cache::get($cache_key);
if (!is_array($drops)) {
$drops = [
'drops' => $drops,
];
}
$drops = $drops['drops'] / $decimal;
$drops = [
'drops' => $drops,
];
Cache::forever($cache_key, $drops);
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('modules', function (Blueprint $table) { Schema::table('modules', function (Blueprint $table) {
// //
@ -23,7 +23,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('modules', function (Blueprint $table) { Schema::table('modules', function (Blueprint $table) {
// //

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('admins', function (Blueprint $table) { Schema::create('admins', function (Blueprint $table) {
$table->id(); $table->id();
@ -32,7 +32,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('admins'); Schema::dropIfExists('admins');
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('balances', function (Blueprint $table) { Schema::table('balances', function (Blueprint $table) {
// //
@ -23,7 +23,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('balances', function (Blueprint $table) { Schema::table('balances', function (Blueprint $table) {
// //

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
// Drop table
Schema::dropIfExists('drops');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
// 不可逆
}
};

View File

@ -1,38 +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()
{
Schema::dropIfExists('personal_access_tokens');
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Schema::dropIfExists('personal_access_tokens');
}
};

View File

@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::dropIfExists('access_tokens');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};

View File

@ -11,7 +11,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //
@ -20,7 +20,7 @@ public function up()
}); });
echo PHP_EOL . '将开始刷新主机的小时数...'; echo PHP_EOL . '将开始刷新主机的小时数...';
Host::chunk(100, function ($hosts) { (new App\Models\Host)->chunk(100, function ($hosts) {
foreach ($hosts as $host) { foreach ($hosts as $host) {
$host->hour_at = $host->created_at->hour; $host->hour_at = $host->created_at->hour;
$host->save(); $host->save();
@ -34,7 +34,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //

View File

@ -1,70 +0,0 @@
<?php
use App\Models\User;
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()
{
$transaction = new \App\Models\Transaction;
// 寻找 updates_at 在 3 天内的用户
User::chunk(100, function ($users) use ($transaction) {
foreach ($users as $user) {
// 重新计算余额
$drops = Cache::get('user_drops_' . $user->id, 0);
$drops = $drops['drops'] ?? 0;
$rate = config('billing.drops_rate', 1000);
if ($drops > 0) {
$amount = $drops / $rate;
$desc = "转换 {$drops} Drops 为 {$amount} 元。";
$transaction->addAmount($user->id, 'console', $amount, $desc, true);
echo "恢复 Drops User {$user->id} 的余额。";
Cache::forget('user_drops_' . $user->id);
}
}
});
User::where('updated_at', '>', now()->subDays(3))->chunk(100, function ($users) use ($transaction) {
foreach ($users as $user) {
if ($user->balance == -1) {
echo "补正余额: User {$user->id} balance {$user->balance}";
$transaction->addAmount($user->id, 'console', 2, '补偿余额。', true);
}
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('balance', function (Blueprint $table) {
//
});
}
};

View File

@ -4,14 +4,13 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('tasks', function (Blueprint $table) { Schema::table('tasks', function (Blueprint $table) {
// //
@ -26,7 +25,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('tasks', function (Blueprint $table) { Schema::table('tasks', function (Blueprint $table) {
// //

View File

@ -9,7 +9,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
// Drop foreign key // Drop foreign key
Schema::table('tasks', function (Blueprint $table) { Schema::table('tasks', function (Blueprint $table) {
@ -27,7 +27,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
// //

View File

@ -5,14 +5,13 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //
@ -21,7 +20,7 @@ public function up()
}); });
echo PHP_EOL . '将开始刷新主机的分钟数...'; echo PHP_EOL . '将开始刷新主机的分钟数...';
Host::chunk(100, function ($hosts) { (new App\Models\Host)->chunk(100, function ($hosts) {
foreach ($hosts as $host) { foreach ($hosts as $host) {
echo '刷新: ' . $host->id . PHP_EOL; echo '刷新: ' . $host->id . PHP_EOL;
$host->minute_at = $host->created_at->minute; $host->minute_at = $host->created_at->minute;
@ -36,7 +35,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('hosts', function (Blueprint $table) { Schema::table('hosts', function (Blueprint $table) {
// //

View File

@ -4,14 +4,13 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('modules', function (Blueprint $table) { Schema::table('modules', function (Blueprint $table) {
// //
@ -24,7 +23,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('modules', function (Blueprint $table) { Schema::table('modules', function (Blueprint $table) {
// //

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('user_groups', function (Blueprint $table) { Schema::create('user_groups', function (Blueprint $table) {
$table->id(); $table->id();
@ -46,7 +46,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
// Schema::table('users', function (Blueprint $table) { // Schema::table('users', function (Blueprint $table) {
// // drop column if exists // // drop column if exists

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('applications', function (Blueprint $table) { Schema::create('applications', function (Blueprint $table) {
$table->id(); $table->id();
@ -30,7 +30,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('applications'); Schema::dropIfExists('applications');
} }

View File

@ -4,14 +4,13 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::create('module_allows', function (Blueprint $table) { Schema::create('module_allows', function (Blueprint $table) {
$table->id(); $table->id();
@ -33,7 +32,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('module_allows'); Schema::dropIfExists('module_allows');
} }

View File

@ -4,14 +4,13 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('work_orders', function (Blueprint $table) { Schema::table('work_orders', function (Blueprint $table) {
// //
@ -29,9 +28,9 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('workorders', function (Blueprint $table) { Schema::table('work_orders', function (Blueprint $table) {
// //
}); });
} }

View File

@ -10,7 +10,7 @@
* *
* @return void * @return void
*/ */
public function up() public function up(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
$table->date('birthday_at')->nullable()->index()->after('email_verified_at'); $table->date('birthday_at')->nullable()->index()->after('email_verified_at');
@ -25,7 +25,7 @@ public function up()
* *
* @return void * @return void
*/ */
public function down() public function down(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
$table->dropColumn('birthday_at'); $table->dropColumn('birthday_at');

View File

@ -15,7 +15,7 @@ public function up(): void
{ {
Schema::table('work_orders', function (Blueprint $table) { Schema::table('work_orders', function (Blueprint $table) {
// uuid // uuid
$table->uuid('uuid')->nullable()->after('id')->index()->unique(); $table->uuid()->nullable()->after('id')->index()->unique();
}); });
// 为每个工单生成一个 uuid 安静更改 // 为每个工单生成一个 uuid 安静更改
@ -34,6 +34,5 @@ public function up(): void
*/ */
public function down(): void public function down(): void
{ {
return;
} }
}; };

View File

@ -23,7 +23,7 @@ public function up(): void
}); });
// 为每个工单回复生成一个 module_id 安静更改 // 为每个工单回复生成一个 module_id 安静更改
Reply::whereNull('module_id')->with('workOrder')->chunk(100, function ($replies) { (new App\Models\WorkOrder\Reply)->whereNull('module_id')->with('workOrder')->chunk(100, function ($replies) {
foreach ($replies as $reply) { foreach ($replies as $reply) {
$reply->module_id = $reply->workOrder->module_id; $reply->module_id = $reply->workOrder->module_id;
$reply->saveQuietly(); $reply->saveQuietly();

View File

@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *

View File

@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *

View File

@ -17,10 +17,10 @@ public function up(): void
$table->string('email_md5')->after('email')->nullable()->comment('邮箱 MD5'); $table->string('email_md5')->after('email')->nullable()->comment('邮箱 MD5');
}); });
$count = User::count(); $count = (new App\Models\User)->count();
$i = 0; $i = 0;
User::chunk(100, function ($users) use (&$i, $count) { (new App\Models\User)->chunk(100, function ($users) use (&$i, $count) {
foreach ($users as $user) { foreach ($users as $user) {
echo sprintf('Updating %d/%d', ++$i, $count) . PHP_EOL; echo sprintf('Updating %d/%d', ++$i, $count) . PHP_EOL;

View File

@ -17,10 +17,10 @@ public function up(): void
$table->uuid()->unique()->after('id')->nullable(); $table->uuid()->unique()->after('id')->nullable();
}); });
$count = User::count(); $count = (new App\Models\User)->count();
$i = 0; $i = 0;
User::chunk(100, function ($users) use (&$i, $count) { (new App\Models\User)->chunk(100, function ($users) use (&$i, $count) {
foreach ($users as $user) { foreach ($users as $user) {
echo sprintf('Updating %d/%d', ++$i, $count) . PHP_EOL; echo sprintf('Updating %d/%d', ++$i, $count) . PHP_EOL;

View File

@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *

View File

@ -5,8 +5,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
* *