Remove 'total' & 'traffic' in dataflow database table

This commit is contained in:
BrettonYe
2023-07-22 16:42:37 +08:00
committed by BrettonYe
parent b5c04f34ae
commit 226e1dfdec
22 changed files with 229 additions and 160 deletions

View File

@@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('failed_jobs', static function (Blueprint $table) {
@@ -22,9 +19,6 @@ return new class extends Migration
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('failed_jobs', function (Blueprint $table) {

View File

@@ -9,9 +9,6 @@ return new class extends Migration
private static array $newConfigs = ['paypal_client_id', 'paypal_client_secret'];
/**
* Run the migrations.
*/
public function up(): void
{
if (Config::exists()) {
@@ -24,9 +21,6 @@ return new class extends Migration
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
foreach (self::$newConfigs as $config) {

View File

@@ -0,0 +1,74 @@
<?php
use App\Models\NodeDailyDataFlow;
use App\Models\NodeHourlyDataFlow;
use App\Models\UserDailyDataFlow;
use App\Models\UserHourlyDataFlow;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
DB::table('country')->where('code', '=', 'uk')->update(['code' => 'gb']);
Schema::table('node_daily_data_flow', function (Blueprint $table) {
$table->dropColumn(['total', 'traffic']);
});
Schema::table('node_hourly_data_flow', function (Blueprint $table) {
$table->dropColumn(['total', 'traffic']);
});
Schema::table('user_daily_data_flow', function (Blueprint $table) {
$table->dropColumn(['total', 'traffic']);
});
Schema::table('user_hourly_data_flow', function (Blueprint $table) {
$table->dropColumn(['total', 'traffic']);
});
}
public function down(): void
{
Schema::table('node_daily_data_flow', static function (Blueprint $table) {
$table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
$table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
});
foreach (NodeDailyDataFlow::cursor() as $log) {
$log->total = $log->u + $log->d;
$log->traffic = formatBytes($log->total);
$log->save();
}
Schema::table('node_hourly_data_flow', static function (Blueprint $table) {
$table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
$table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
});
foreach (NodeHourlyDataFlow::cursor() as $log) {
$log->total = $log->u + $log->d;
$log->traffic = formatBytes($log->total);
$log->save();
}
Schema::table('user_daily_data_flow', static function (Blueprint $table) {
$table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
$table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
});
foreach (UserDailyDataFlow::cursor() as $log) {
$log->total = $log->u + $log->d;
$log->traffic = formatBytes($log->total);
$log->save();
}
Schema::table('user_hourly_data_flow', static function (Blueprint $table) {
$table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
$table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
});
foreach (UserHourlyDataFlow::cursor() as $log) {
$log->total = $log->u + $log->d;
$log->traffic = formatBytes($log->total);
$log->save();
}
}
};