2021_01_15_065207_create_notifications_table.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreateNotificationsTable extends Migration
  6. {
  7. private $configs = [
  8. 'account_expire_notification',
  9. 'data_anomaly_notification',
  10. 'data_exhaust_notification',
  11. 'node_blocked_notification',
  12. 'node_daily_notification',
  13. 'node_offline_notification',
  14. 'password_reset_notification',
  15. 'payment_received_notification',
  16. 'ticket_closed_notification',
  17. 'ticket_created_notification',
  18. 'ticket_replied_notification',
  19. ];
  20. private $dropConfigs = [
  21. 'is_reset_password',
  22. 'expire_warning',
  23. 'traffic_warning',
  24. 'is_node_offline',
  25. 'node_daily_report',
  26. 'nodes_detection',
  27. 'is_notification',
  28. ];
  29. public function up()
  30. {
  31. Schema::create('notifications', function (Blueprint $table) {
  32. $table->uuid('id')->primary();
  33. $table->string('type');
  34. $table->morphs('notifiable');
  35. $table->text('data');
  36. $table->timestamp('read_at')->nullable();
  37. $table->timestamps();
  38. });
  39. Schema::table('order', function (Blueprint $table) {
  40. $table->renameColumn('order_sn', 'sn');
  41. });
  42. foreach ($this->configs as $config) {
  43. \App\Models\Config::insert(['name' => $config]);
  44. }
  45. \App\Models\Config::whereIn('name', $this->dropConfigs)->delete();
  46. }
  47. /**
  48. * Reverse the migrations.
  49. *
  50. * @return void
  51. */
  52. public function down()
  53. {
  54. Schema::dropIfExists('notifications');
  55. Schema::table('order', function (Blueprint $table) {
  56. $table->renameColumn('sn', 'order_sn');
  57. });
  58. foreach ($this->dropConfigs as $config) {
  59. \App\Models\Config::insert(['name' => $config]);
  60. }
  61. \App\Models\Config::whereIn('name', $this->configs)->delete();
  62. }
  63. }