2023_07_08_162803_clean_up_unnecessary_info.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. use App\Models\NodeDailyDataFlow;
  3. use App\Models\NodeHourlyDataFlow;
  4. use App\Models\UserDailyDataFlow;
  5. use App\Models\UserHourlyDataFlow;
  6. use Illuminate\Database\Migrations\Migration;
  7. use Illuminate\Database\Schema\Blueprint;
  8. use Illuminate\Support\Facades\Schema;
  9. return new class extends Migration
  10. {
  11. public function up(): void
  12. {
  13. DB::table('country')->where('code', '=', 'uk')->update(['code' => 'gb']);
  14. Schema::table('node_daily_data_flow', function (Blueprint $table) {
  15. $table->dropColumn(['total', 'traffic']);
  16. });
  17. Schema::table('node_hourly_data_flow', function (Blueprint $table) {
  18. $table->dropColumn(['total', 'traffic']);
  19. });
  20. Schema::table('user_daily_data_flow', function (Blueprint $table) {
  21. $table->dropColumn(['total', 'traffic']);
  22. });
  23. Schema::table('user_hourly_data_flow', function (Blueprint $table) {
  24. $table->dropColumn(['total', 'traffic']);
  25. });
  26. }
  27. public function down(): void
  28. {
  29. Schema::table('node_daily_data_flow', static function (Blueprint $table) {
  30. $table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
  31. $table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
  32. });
  33. foreach (NodeDailyDataFlow::cursor() as $log) {
  34. $log->total = $log->u + $log->d;
  35. $log->traffic = formatBytes($log->total);
  36. $log->save();
  37. }
  38. Schema::table('node_hourly_data_flow', static function (Blueprint $table) {
  39. $table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
  40. $table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
  41. });
  42. foreach (NodeHourlyDataFlow::cursor() as $log) {
  43. $log->total = $log->u + $log->d;
  44. $log->traffic = formatBytes($log->total);
  45. $log->save();
  46. }
  47. Schema::table('user_daily_data_flow', static function (Blueprint $table) {
  48. $table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
  49. $table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
  50. });
  51. foreach (UserDailyDataFlow::cursor() as $log) {
  52. $log->total = $log->u + $log->d;
  53. $log->traffic = formatBytes($log->total);
  54. $log->save();
  55. }
  56. Schema::table('user_hourly_data_flow', static function (Blueprint $table) {
  57. $table->unsignedBigInteger('total')->default(0)->comment('总流量')->after('d');
  58. $table->string('traffic')->nullable()->comment('总流量(带单位)')->after('total');
  59. });
  60. foreach (UserHourlyDataFlow::cursor() as $log) {
  61. $log->total = $log->u + $log->d;
  62. $log->traffic = formatBytes($log->total);
  63. $log->save();
  64. }
  65. }
  66. };