TestDatabase.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests;
  4. use App\Services\DB;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Database\Capsule\Manager as Capsule;
  7. class TestDatabase
  8. {
  9. public static function init(): void
  10. {
  11. DB::init();
  12. self::createTables();
  13. }
  14. private static function createTables(): void
  15. {
  16. $capsule = DB::getCapsule();
  17. $schema = $capsule->schema();
  18. if (!$schema->hasTable('user')) {
  19. $schema->create('user', function (Blueprint $table) {
  20. $table->increments('id');
  21. $table->string('email')->unique();
  22. $table->string('user_name')->default('');
  23. $table->string('passwd');
  24. $table->integer('t')->default(0);
  25. $table->bigInteger('u')->default(0);
  26. $table->bigInteger('d')->default(0);
  27. $table->bigInteger('transfer_today')->default(0);
  28. $table->bigInteger('transfer_total')->default(0);
  29. $table->bigInteger('transfer_enable')->default(0);
  30. $table->integer('port')->default(0);
  31. $table->integer('switch')->default(1);
  32. $table->integer('enable')->default(1);
  33. $table->integer('type')->default(1);
  34. $table->dateTime('last_detect_ban_time')->nullable();
  35. $table->string('last_check_in_time')->nullable();
  36. $table->string('reg_ip')->default('');
  37. $table->integer('invite_num')->default(0);
  38. $table->decimal('money', 10, 2)->default(0);
  39. $table->string('ref_by_user_name')->default('');
  40. $table->string('method')->default('aes-256-gcm');
  41. $table->integer('custom_rss')->default(0);
  42. $table->string('protocol')->default('origin');
  43. $table->string('protocol_param')->default('');
  44. $table->string('obfs')->default('plain');
  45. $table->string('obfs_param')->default('');
  46. $table->integer('node_connector')->default(0);
  47. $table->tinyInteger('is_email_verify')->default(0);
  48. $table->dateTime('reg_date');
  49. $table->decimal('in_use', 10, 2)->default(0);
  50. $table->dateTime('current_login_time')->nullable();
  51. $table->string('current_login_ip')->default('');
  52. $table->tinyInteger('auto_reset_bandwidth')->default(0);
  53. $table->dateTime('auto_reset_bandwidth_date')->nullable();
  54. $table->integer('c_rebate')->default(10);
  55. $table->integer('commission')->default(0);
  56. $table->integer('agent_level')->default(0);
  57. $table->integer('class')->default(0);
  58. $table->dateTime('class_expire')->nullable();
  59. $table->integer('theme')->default(1);
  60. $table->string('ga_token')->default('');
  61. $table->tinyInteger('ga_enable')->default(0);
  62. $table->string('telegram_id')->nullable();
  63. $table->string('discord_id')->nullable();
  64. $table->string('slack_id')->nullable();
  65. $table->string('im_type')->default('');
  66. $table->string('im_value')->default('');
  67. $table->timestamps();
  68. });
  69. }
  70. if (!$schema->hasTable('node')) {
  71. $schema->create('node', function (Blueprint $table) {
  72. $table->increments('id');
  73. $table->string('name');
  74. $table->integer('type')->default(1);
  75. $table->string('server');
  76. $table->text('custom_config')->nullable();
  77. $table->text('info')->nullable();
  78. $table->text('traffic_rate')->nullable();
  79. $table->integer('status')->default(1);
  80. $table->integer('sort')->default(0);
  81. $table->integer('node_class')->default(0);
  82. $table->bigInteger('node_speedlimit')->default(0);
  83. $table->bigInteger('node_bandwidth')->default(0);
  84. $table->bigInteger('node_bandwidth_limit')->default(0);
  85. $table->bigInteger('bandwidth_resetday')->default(0);
  86. $table->tinyInteger('node_heartbeat')->default(0);
  87. $table->string('node_ip')->nullable();
  88. $table->tinyInteger('node_group')->default(0);
  89. $table->tinyInteger('custom_method')->default(0);
  90. $table->string('password');
  91. $table->dateTime('created_at')->nullable();
  92. $table->dateTime('updated_at')->nullable();
  93. });
  94. }
  95. if (!$schema->hasTable('node_online_log')) {
  96. $schema->create('node_online_log', function (Blueprint $table) {
  97. $table->increments('id');
  98. $table->integer('node_id');
  99. $table->integer('online_user');
  100. $table->integer('log_time');
  101. $table->index('node_id');
  102. $table->index('log_time');
  103. });
  104. }
  105. if (!$schema->hasTable('user_traffic_log')) {
  106. $schema->create('user_traffic_log', function (Blueprint $table) {
  107. $table->increments('id');
  108. $table->integer('user_id');
  109. $table->bigInteger('u');
  110. $table->bigInteger('d');
  111. $table->integer('node_id');
  112. $table->double('rate');
  113. $table->string('traffic');
  114. $table->integer('log_time');
  115. $table->index('user_id');
  116. $table->index('node_id');
  117. $table->index('log_time');
  118. });
  119. }
  120. }
  121. public static function dropTables(): void
  122. {
  123. $capsule = DB::getCapsule();
  124. $schema = $capsule->schema();
  125. $tables = ['user_traffic_log', 'node_online_log', 'node', 'user'];
  126. foreach ($tables as $table) {
  127. if ($schema->hasTable($table)) {
  128. $schema->drop($table);
  129. }
  130. }
  131. }
  132. }