From 4b5ba18b296b3e8f34e14ac516ff095af7d3cb43 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Thu, 2 Feb 2023 20:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=20=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2014_10_12_000000_create_users_table.php | 17 +++-- ...2_000001_create_password_resets_table.php} | 0 ..._08_19_000000_create_failed_jobs_table.php | 36 --------- ...01_create_personal_access_tokens_table.php | 4 - ...04635_add_managed_price_to_hosts_table.php | 34 --------- ...user_id_nullable_to_work_order_replies.php | 33 --------- ..._08_19_082540_add_url_to_modules_table.php | 34 --------- .../2022_08_25_142429_create_tasks_table.php | 54 -------------- ...094841_add_suspended_at_to_hosts_table.php | 33 --------- ...8_30_081930_add_balance_to_users_table.php | 39 ---------- ...22_09_03_070656_add_module_id_to_hosts.php | 33 --------- ...22_09_13_191255_add_banned_at_to_users.php | 35 --------- ...09_14_215159_create_transactions_table.php | 47 ------------ ...10_31_161617_add_wecom_hook_to_modules.php | 38 ---------- ...05842_add_remaining_amount_to_balances.php | 33 --------- ...2022_11_19_220435_add_hour_at_to_hosts.php | 45 ------------ ...22_11_20_222505_add_module_id_to_tasks.php | 35 --------- ...53_change_tasks_engine_to_memory_table.php | 43 ----------- ...22_11_23_103355_add_minute_at_to_hosts.php | 46 ------------ ..._23_104838_add_status_to_modules_table.php | 35 --------- ..._11_26_202440_create_user_groups_table.php | 73 ------------------- ...add_cascade_update_to_workorders_table.php | 37 ---------- ..._212017_add_birthday_at_to_users_table.php | 36 --------- ...1_171554_add_uuid_to_work_orders_table.php | 39 ---------- ...5_add_name_to_work_order_replies_table.php | 48 ------------ ...9_add_role_to_work_order_replies_table.php | 32 -------- ...201811_add_notify_to_work_orders_table.php | 32 -------- ...02_220622_add_email_md5_to_users_table.php | 44 ----------- ...3_01_03_143451_add_uuid_to_users_table.php | 46 ------------ ..._01_04_192849_add_index_to_users_table.php | 34 --------- ..._01_05_222438_add_name_to_admins_table.php | 39 ---------- ...1_14_180605_change_type_to_hosts_table.php | 36 --------- ..._14_195428_add_ip_to_work_orders_table.php | 32 -------- ...435_add_ip_to_work_order_replies_table.php | 32 -------- ...14_202329_add_balance_to_modules_table.php | 32 -------- ...654_add_real_name_verified_at_to_users.php | 34 --------- ...1_15_191519_encrypt_id_card_from_users.php | 40 ---------- ...d_real_name_verified_at_index_to_users.php | 32 -------- ...cimal_total_to_users_and_modules_table.php | 40 ---------- ...9_set_progress_nullable_to_tasks_table.php | 41 ----------- ...odule_id_nullable_to_work_orders_table.php | 32 -------- ...151627_add_timestamps_to_modules_table.php | 39 ---------- ..._add_unavailable_status_to_hosts_table.php | 37 ---------- ...2023_02_02_000000_create_admins_table.php} | 7 +- ...2_02_000000_create_applications_table.php} | 9 +-- ...23_02_02_000000_create_balances_table.php} | 17 +---- ..._02_000000_create_notifications_table.php} | 5 +- ...023_02_02_000001_create_modules_table.php} | 23 ++---- ..._02_000002_create_module_allows_table.php} | 10 +-- ... 2023_02_02_000003_create_hosts_table.php} | 30 +++----- ...02_02_031145_add_soft_deletes_to_users.php | 38 ---------- ...2_02_193726_add_index_to_modules_table.php | 32 -------- .../2023_02_02_195733_create_tasks_table.php | 40 ++++++++++ ..._02_02_195733_create_user_groups_table.php | 42 +++++++++++ ...02_02_195733_create_work_orders_table.php} | 26 +++---- ...95734_create_work_order_replies_table.php} | 22 +++--- ...> 2023_02_02_200339_create_tag_tables.php} | 12 ++- 57 files changed, 152 insertions(+), 1722 deletions(-) rename database/migrations/{2014_10_12_100000_create_password_resets_table.php => 2014_10_12_000001_create_password_resets_table.php} (100%) delete mode 100644 database/migrations/2019_08_19_000000_create_failed_jobs_table.php delete mode 100644 database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php delete mode 100644 database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php delete mode 100644 database/migrations/2022_08_19_082540_add_url_to_modules_table.php delete mode 100644 database/migrations/2022_08_25_142429_create_tasks_table.php delete mode 100644 database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php delete mode 100644 database/migrations/2022_08_30_081930_add_balance_to_users_table.php delete mode 100644 database/migrations/2022_09_03_070656_add_module_id_to_hosts.php delete mode 100644 database/migrations/2022_09_13_191255_add_banned_at_to_users.php delete mode 100644 database/migrations/2022_09_14_215159_create_transactions_table.php delete mode 100644 database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php delete mode 100644 database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php delete mode 100644 database/migrations/2022_11_19_220435_add_hour_at_to_hosts.php delete mode 100644 database/migrations/2022_11_20_222505_add_module_id_to_tasks.php delete mode 100644 database/migrations/2022_11_22_180553_change_tasks_engine_to_memory_table.php delete mode 100644 database/migrations/2022_11_23_103355_add_minute_at_to_hosts.php delete mode 100644 database/migrations/2022_11_23_104838_add_status_to_modules_table.php delete mode 100644 database/migrations/2022_11_26_202440_create_user_groups_table.php delete mode 100644 database/migrations/2022_12_03_133136_add_cascade_update_to_workorders_table.php delete mode 100644 database/migrations/2022_12_28_212017_add_birthday_at_to_users_table.php delete mode 100644 database/migrations/2023_01_01_171554_add_uuid_to_work_orders_table.php delete mode 100644 database/migrations/2023_01_01_180855_add_name_to_work_order_replies_table.php delete mode 100644 database/migrations/2023_01_01_211259_add_role_to_work_order_replies_table.php delete mode 100644 database/migrations/2023_01_02_201811_add_notify_to_work_orders_table.php delete mode 100644 database/migrations/2023_01_02_220622_add_email_md5_to_users_table.php delete mode 100644 database/migrations/2023_01_03_143451_add_uuid_to_users_table.php delete mode 100644 database/migrations/2023_01_04_192849_add_index_to_users_table.php delete mode 100644 database/migrations/2023_01_05_222438_add_name_to_admins_table.php delete mode 100644 database/migrations/2023_01_14_180605_change_type_to_hosts_table.php delete mode 100644 database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php delete mode 100644 database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php delete mode 100644 database/migrations/2023_01_14_202329_add_balance_to_modules_table.php delete mode 100644 database/migrations/2023_01_15_011654_add_real_name_verified_at_to_users.php delete mode 100644 database/migrations/2023_01_15_191519_encrypt_id_card_from_users.php delete mode 100644 database/migrations/2023_01_15_194111_add_real_name_verified_at_index_to_users.php delete mode 100644 database/migrations/2023_01_17_235003_change_decimal_total_to_users_and_modules_table.php delete mode 100644 database/migrations/2023_01_19_021809_set_progress_nullable_to_tasks_table.php delete mode 100644 database/migrations/2023_01_19_162625_set_module_id_nullable_to_work_orders_table.php delete mode 100644 database/migrations/2023_01_20_151627_add_timestamps_to_modules_table.php delete mode 100644 database/migrations/2023_01_20_153636_add_unavailable_status_to_hosts_table.php rename database/migrations/{2022_11_02_103610_create_admins_table.php => 2023_02_02_000000_create_admins_table.php} (93%) rename database/migrations/{2022_11_27_100733_create_applications_table.php => 2023_02_02_000000_create_applications_table.php} (86%) rename database/migrations/{2022_09_01_033240_create_balances_table.php => 2023_02_02_000000_create_balances_table.php} (78%) rename database/migrations/{2022_08_13_083908_create_notifications_table.php => 2023_02_02_000000_create_notifications_table.php} (81%) rename database/migrations/{2022_08_12_123308_create_modules_table.php => 2023_02_02_000001_create_modules_table.php} (55%) rename database/migrations/{2022_12_03_130419_create_module_allows_table.php => 2023_02_02_000002_create_module_allows_table.php} (70%) rename database/migrations/{2022_08_13_051148_create_hosts_table.php => 2023_02_02_000003_create_hosts_table.php} (52%) delete mode 100644 database/migrations/2023_02_02_031145_add_soft_deletes_to_users.php delete mode 100644 database/migrations/2023_02_02_193726_add_index_to_modules_table.php create mode 100644 database/migrations/2023_02_02_195733_create_tasks_table.php create mode 100644 database/migrations/2023_02_02_195733_create_user_groups_table.php rename database/migrations/{2022_08_13_051705_create_workorders_table.php => 2023_02_02_195733_create_work_orders_table.php} (57%) rename database/migrations/{2022_08_13_051817_create_workorder_replies_table.php => 2023_02_02_195734_create_work_order_replies_table.php} (50%) rename database/migrations/{2023_01_17_010152_create_tag_tables.php => 2023_02_02_200339_create_tag_tables.php} (78%) diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index ed8a5f1..cb45e42 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -15,16 +15,23 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('name'); + $table->uuid()->nullable()->unique(); + $table->string('name')->index(); + $table->string('real_name')->nullable(); $table->string('email')->unique(); + $table->string('email_md5')->nullable()->comment('邮箱 MD5'); + $table->string('id_card')->nullable()->comment('身份证号'); $table->timestamp('email_verified_at')->nullable(); + $table->timestamp('real_name_verified_at')->nullable()->index()->comment('实名认证时间'); + $table->date('birthday_at')->nullable()->index(); $table->string('password')->nullable(); - - // 积分(8位小数点) - $table->double('drops', 60, 8)->default(0); - + $table->decimal('balance', 20, 4)->default(0); + $table->dateTime('banned_at')->nullable()->index()->comment('封禁时间'); + $table->string('banned_reason')->nullable(); + $table->unsignedBigInteger('user_group_id')->nullable()->index()->comment('用户组'); $table->rememberToken(); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_000001_create_password_resets_table.php similarity index 100% rename from database/migrations/2014_10_12_100000_create_password_resets_table.php rename to database/migrations/2014_10_12_000001_create_password_resets_table.php diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php deleted file mode 100644 index db96e7d..0000000 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ /dev/null @@ -1,36 +0,0 @@ -id(); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::dropIfExists('failed_jobs'); - } -}; diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index f5730b1..e828ad8 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -8,8 +8,6 @@ { /** * Run the migrations. - * - * @return void */ public function up(): void { @@ -27,8 +25,6 @@ public function up(): void /** * Reverse the migrations. - * - * @return void */ public function down(): void { diff --git a/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php b/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php deleted file mode 100644 index db63341..0000000 --- a/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php +++ /dev/null @@ -1,34 +0,0 @@ -double('managed_price', 60, 8)->index()->nullable()->after('price'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('hosts', function (Blueprint $table) { - // drop - $table->dropColumn('managed_price'); - }); - } -}; diff --git a/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php b/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php deleted file mode 100644 index 73c9579..0000000 --- a/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php +++ /dev/null @@ -1,33 +0,0 @@ -unsignedBigInteger('user_id')->nullable()->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_order_replies', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2022_08_19_082540_add_url_to_modules_table.php b/database/migrations/2022_08_19_082540_add_url_to_modules_table.php deleted file mode 100644 index d32afa7..0000000 --- a/database/migrations/2022_08_19_082540_add_url_to_modules_table.php +++ /dev/null @@ -1,34 +0,0 @@ -string('url')->nullable()->after('api_token')->index(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('modules', function (Blueprint $table) { - // - $table->dropColumn('url'); - }); - } -}; diff --git a/database/migrations/2022_08_25_142429_create_tasks_table.php b/database/migrations/2022_08_25_142429_create_tasks_table.php deleted file mode 100644 index 41faeaf..0000000 --- a/database/migrations/2022_08_25_142429_create_tasks_table.php +++ /dev/null @@ -1,54 +0,0 @@ -uuid('id')->primary()->unique(); - - $table->string('title'); - - // progress (max 100) - $table->integer('progress')->default(0); - - // status - $table->enum('status', ['pending', 'done', 'success', 'failed', 'error', 'cancelled', 'processing', 'need_operation'])->index(); - - // user id - $table->unsignedBigInteger('user_id')->index(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - // host id - $table->unsignedBigInteger('host_id')->index(); - $table->foreign('host_id')->references('id')->on('hosts')->onDelete('cascade'); - - $table->timestamps(); - } - ); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - // - Schema::dropIfExists('tasks'); - } -}; diff --git a/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php b/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php deleted file mode 100644 index d640e9e..0000000 --- a/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php +++ /dev/null @@ -1,33 +0,0 @@ -timestamp('suspended_at')->nullable()->index()->after('status'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('hosts', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2022_08_30_081930_add_balance_to_users_table.php b/database/migrations/2022_08_30_081930_add_balance_to_users_table.php deleted file mode 100644 index 85ecd58..0000000 --- a/database/migrations/2022_08_30_081930_add_balance_to_users_table.php +++ /dev/null @@ -1,39 +0,0 @@ -decimal('balance')->default(0)->after('password'); - - // drop column if exists - if (Schema::hasColumn('users', 'drops')) { - $table->dropColumn('drops'); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - // - $table->dropColumn('balance'); - }); - } -}; diff --git a/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php b/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php deleted file mode 100644 index e6233f6..0000000 --- a/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php +++ /dev/null @@ -1,33 +0,0 @@ -foreign('module_id')->references('id')->on('modules')->cascadeOnUpdate(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('hosts', function (Blueprint $table) { - // rollback - $table->dropForeign(['module_id']); - }); - } -}; diff --git a/database/migrations/2022_09_13_191255_add_banned_at_to_users.php b/database/migrations/2022_09_13_191255_add_banned_at_to_users.php deleted file mode 100644 index 1dfd739..0000000 --- a/database/migrations/2022_09_13_191255_add_banned_at_to_users.php +++ /dev/null @@ -1,35 +0,0 @@ -dateTime('banned_at')->nullable()->comment('封禁时间')->after('balance'); - // reason - $table->string('banned_reason')->nullable()->after('banned_at'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2022_09_14_215159_create_transactions_table.php b/database/migrations/2022_09_14_215159_create_transactions_table.php deleted file mode 100644 index 2febfe9..0000000 --- a/database/migrations/2022_09_14_215159_create_transactions_table.php +++ /dev/null @@ -1,47 +0,0 @@ -hasTable('transactions')) { - return; - } - - Schema::connection('mongodb')->create('transactions', function (Blueprint $collection) { - $collection->unsignedBigInteger('user_id')->index(); - $collection->unsignedBigInteger( - 'type' - )->index(); - $collection->unsignedBigInteger('payment')->index(); - $collection->unsignedBigInteger( - 'module_id' - )->index()->nullable(); - $collection->unsignedBigInteger('host_id')->index()->nullable(); - - // a year - $year = 365 * 24 * 60 * 60; - $collection->expire('created_at', $year); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::connection('mongodb')->dropIfExists('transactions'); - } -}; diff --git a/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php b/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php deleted file mode 100644 index 0d94c49..0000000 --- a/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php +++ /dev/null @@ -1,38 +0,0 @@ -string('wecom_key')->nullable()->comment('企业微信机器人 key'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('modules', function (Blueprint $table) { - // - - // drop if exists - if (Schema::hasColumn('modules', 'wecom_key')) { - $table->dropColumn('wecom_key'); - } - }); - } -}; diff --git a/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php b/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php deleted file mode 100644 index 9b6cc4d..0000000 --- a/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php +++ /dev/null @@ -1,33 +0,0 @@ -decimal('remaining_amount', 10)->default(0)->after('amount'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('balances', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2022_11_19_220435_add_hour_at_to_hosts.php b/database/migrations/2022_11_19_220435_add_hour_at_to_hosts.php deleted file mode 100644 index 3fe0c9f..0000000 --- a/database/migrations/2022_11_19_220435_add_hour_at_to_hosts.php +++ /dev/null @@ -1,45 +0,0 @@ -tinyInteger('hour_at')->index()->nullable()->after('status'); - }); - - echo PHP_EOL.'将开始刷新主机的小时数...'; - (new App\Models\Host)->chunk(100, function ($hosts) { - foreach ($hosts as $host) { - $host->hour_at = $host->created_at->hour; - $host->save(); - } - }); - echo ' 完成!'.PHP_EOL; - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('hosts', function (Blueprint $table) { - // - - $table->dropColumn('hour_at'); - }); - } -}; diff --git a/database/migrations/2022_11_20_222505_add_module_id_to_tasks.php b/database/migrations/2022_11_20_222505_add_module_id_to_tasks.php deleted file mode 100644 index 243e6d8..0000000 --- a/database/migrations/2022_11_20_222505_add_module_id_to_tasks.php +++ /dev/null @@ -1,35 +0,0 @@ -string('module_id')->nullable()->after('host_id')->index(); - $table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('tasks', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2022_11_22_180553_change_tasks_engine_to_memory_table.php b/database/migrations/2022_11_22_180553_change_tasks_engine_to_memory_table.php deleted file mode 100644 index 6407a97..0000000 --- a/database/migrations/2022_11_22_180553_change_tasks_engine_to_memory_table.php +++ /dev/null @@ -1,43 +0,0 @@ -dropForeign('tasks_host_id_foreign'); - $table->dropForeign('tasks_user_id_foreign'); - $table->dropForeign('tasks_module_id_foreign'); - }); - - // run RAW SQL - DB::statement('ALTER TABLE tasks ENGINE=MEMORY;'); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - // - - DB::statement('ALTER TABLE tasks ENGINE=InnoDB;'); - - Schema::table('tasks', function (Blueprint $table) { - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('host_id')->references('id')->on('hosts')->onDelete('cascade'); - $table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade'); - }); - } -}; diff --git a/database/migrations/2022_11_23_103355_add_minute_at_to_hosts.php b/database/migrations/2022_11_23_103355_add_minute_at_to_hosts.php deleted file mode 100644 index b7a63bd..0000000 --- a/database/migrations/2022_11_23_103355_add_minute_at_to_hosts.php +++ /dev/null @@ -1,46 +0,0 @@ -tinyInteger('minute_at')->index()->nullable()->after('hour_at'); - }); - - echo PHP_EOL.'将开始刷新主机的分钟数...'; - (new App\Models\Host)->chunk(100, function ($hosts) { - foreach ($hosts as $host) { - echo '刷新: '.$host->id.PHP_EOL; - $host->minute_at = $host->created_at->minute; - $host->save(); - } - }); - echo ' 完成!'.PHP_EOL; - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('hosts', function (Blueprint $table) { - // - - $table->dropColumn('minute_at'); - }); - } -}; diff --git a/database/migrations/2022_11_23_104838_add_status_to_modules_table.php b/database/migrations/2022_11_23_104838_add_status_to_modules_table.php deleted file mode 100644 index fd39976..0000000 --- a/database/migrations/2022_11_23_104838_add_status_to_modules_table.php +++ /dev/null @@ -1,35 +0,0 @@ -enum('status', ['up', 'down', 'maintenance'])->index()->default('down')->after('url'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('modules', function (Blueprint $table) { - // - - $table->dropColumn('status'); - }); - } -}; diff --git a/database/migrations/2022_11_26_202440_create_user_groups_table.php b/database/migrations/2022_11_26_202440_create_user_groups_table.php deleted file mode 100644 index a8f5469..0000000 --- a/database/migrations/2022_11_26_202440_create_user_groups_table.php +++ /dev/null @@ -1,73 +0,0 @@ -id(); - - // 名称 - $table->string('name')->comment('名称')->index(); - - // 颜色 - $table->string('color')->comment('颜色')->nullable(); - - // 优惠百分比 - $table->integer('discount')->comment('优惠百分比')->default(100); - - // 暂停/终止豁免权 - $table->boolean('exempt')->comment('暂停/终止豁免权')->default(false); - - $table->timestamps(); - }); - - // Schema::table('users', function (Blueprint $table) { - // $table->unsignedBigInteger('user_group_id')->nullable()->comment('用户组')->index()->after('banned_reason'); - // $table->foreign('user_group_id')->references('id')->on('user_groups')->onDelete('set null'); - // }); - - Schema::table('users', function (Blueprint $table) { - $table->unsignedBigInteger('user_group_id')->nullable()->comment('用户组')->index()->after('banned_reason'); - $table->foreign('user_group_id')->references('id')->on('user_groups')->onDelete('set null'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - // Schema::table('users', function (Blueprint $table) { - // // drop column if exists - // if (Schema::hasColumn('users', 'user_group_id')) { - // $table->dropForeign('users_user_group_id_foreign'); - // - // $table->dropColumn('user_group_id'); - // } - // }); - // - - Schema::table('users', function (Blueprint $table) { - // drop column if exists - if (Schema::hasColumn('users', 'user_group_id')) { - $table->dropForeign('users_user_group_id_foreign'); - - $table->dropColumn('user_group_id'); - } - }); - - Schema::dropIfExists('user_groups'); - } -}; diff --git a/database/migrations/2022_12_03_133136_add_cascade_update_to_workorders_table.php b/database/migrations/2022_12_03_133136_add_cascade_update_to_workorders_table.php deleted file mode 100644 index 5cab09d..0000000 --- a/database/migrations/2022_12_03_133136_add_cascade_update_to_workorders_table.php +++ /dev/null @@ -1,37 +0,0 @@ -dropForeign('work_orders_module_id_foreign'); - - $table->foreign('module_id')->references('id')->on('modules')->cascadeOnDelete()->cascadeOnUpdate(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_orders', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2022_12_28_212017_add_birthday_at_to_users_table.php b/database/migrations/2022_12_28_212017_add_birthday_at_to_users_table.php deleted file mode 100644 index 54626b6..0000000 --- a/database/migrations/2022_12_28_212017_add_birthday_at_to_users_table.php +++ /dev/null @@ -1,36 +0,0 @@ -date('birthday_at')->nullable()->index()->after('email_verified_at'); - - // 真实姓名 - $table->string('real_name')->nullable()->after('name'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropColumn('birthday_at'); - $table->dropColumn('real_name'); - }); - } -}; diff --git a/database/migrations/2023_01_01_171554_add_uuid_to_work_orders_table.php b/database/migrations/2023_01_01_171554_add_uuid_to_work_orders_table.php deleted file mode 100644 index d3b6cf6..0000000 --- a/database/migrations/2023_01_01_171554_add_uuid_to_work_orders_table.php +++ /dev/null @@ -1,39 +0,0 @@ -uuid()->nullable()->after('id')->index()->unique(); - }); - - // 为每个工单生成一个 uuid 安静更改 - WorkOrder::query()->chunk(100, function ($workOrders) { - foreach ($workOrders as $workOrder) { - $workOrder->uuid = Str::uuid(); - $workOrder->saveQuietly(); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - } -}; diff --git a/database/migrations/2023_01_01_180855_add_name_to_work_order_replies_table.php b/database/migrations/2023_01_01_180855_add_name_to_work_order_replies_table.php deleted file mode 100644 index a4b0922..0000000 --- a/database/migrations/2023_01_01_180855_add_name_to_work_order_replies_table.php +++ /dev/null @@ -1,48 +0,0 @@ -string('name')->nullable()->after('user_id'); - - // module_id - $table->string('module_id')->nullable()->after('name')->index(); - $table->foreign('module_id')->references('id')->on('modules')->cascadeOnDelete(); - }); - - // 为每个工单回复生成一个 module_id 安静更改 - (new App\Models\WorkOrder\Reply)->whereNull('module_id')->with('workOrder')->chunk(100, function ($replies) { - foreach ($replies as $reply) { - $reply->module_id = $reply->workOrder->module_id; - $reply->saveQuietly(); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_order_replies', function (Blueprint $table) { - Schema::hasColumn('work_order_replies', 'name') && $table->dropColumn('name'); - - $table->dropForeign(['module_id']); - $table->dropColumn('module_id'); - }); - } -}; diff --git a/database/migrations/2023_01_01_211259_add_role_to_work_order_replies_table.php b/database/migrations/2023_01_01_211259_add_role_to_work_order_replies_table.php deleted file mode 100644 index 35bfef7..0000000 --- a/database/migrations/2023_01_01_211259_add_role_to_work_order_replies_table.php +++ /dev/null @@ -1,32 +0,0 @@ -string('role')->default('user')->comment('回复角色')->after('module_id'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_order_replies', function (Blueprint $table) { - $table->dropColumn('role'); - }); - } -}; diff --git a/database/migrations/2023_01_02_201811_add_notify_to_work_orders_table.php b/database/migrations/2023_01_02_201811_add_notify_to_work_orders_table.php deleted file mode 100644 index a88bc5c..0000000 --- a/database/migrations/2023_01_02_201811_add_notify_to_work_orders_table.php +++ /dev/null @@ -1,32 +0,0 @@ -boolean('notify')->default(true)->comment('是否通知')->after('status'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_orders', function (Blueprint $table) { - $table->dropColumn('notify'); - }); - } -}; diff --git a/database/migrations/2023_01_02_220622_add_email_md5_to_users_table.php b/database/migrations/2023_01_02_220622_add_email_md5_to_users_table.php deleted file mode 100644 index a05c426..0000000 --- a/database/migrations/2023_01_02_220622_add_email_md5_to_users_table.php +++ /dev/null @@ -1,44 +0,0 @@ -string('email_md5')->after('email')->nullable()->comment('邮箱 MD5'); - }); - - $count = (new App\Models\User)->count(); - $i = 0; - - (new App\Models\User)->chunk(100, function ($users) use (&$i, $count) { - foreach ($users as $user) { - echo sprintf('Updating %d/%d', ++$i, $count).PHP_EOL; - - $user->email_md5 = md5($user->email); - $user->saveQuietly(); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropColumn('email_md5'); - }); - } -}; diff --git a/database/migrations/2023_01_03_143451_add_uuid_to_users_table.php b/database/migrations/2023_01_03_143451_add_uuid_to_users_table.php deleted file mode 100644 index 99d5f53..0000000 --- a/database/migrations/2023_01_03_143451_add_uuid_to_users_table.php +++ /dev/null @@ -1,46 +0,0 @@ -uuid()->unique()->after('id')->nullable(); - }); - - $count = (new App\Models\User)->count(); - $i = 0; - - (new App\Models\User)->chunk(100, function ($users) use (&$i, $count) { - foreach ($users as $user) { - echo sprintf('Updating %d/%d', ++$i, $count).PHP_EOL; - - $user->email_md5 = md5($user->email); - $user->uuid = Str::uuid(); - $user->saveQuietly(); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropColumn('uuid'); - }); - } -}; diff --git a/database/migrations/2023_01_04_192849_add_index_to_users_table.php b/database/migrations/2023_01_04_192849_add_index_to_users_table.php deleted file mode 100644 index 02e6b7c..0000000 --- a/database/migrations/2023_01_04_192849_add_index_to_users_table.php +++ /dev/null @@ -1,34 +0,0 @@ -string('name')->index()->change(); - $table->dateTime('banned_at')->index()->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropIndex('users_name_index'); - $table->dropIndex('users_banned_at_index'); - }); - } -}; diff --git a/database/migrations/2023_01_05_222438_add_name_to_admins_table.php b/database/migrations/2023_01_05_222438_add_name_to_admins_table.php deleted file mode 100644 index 19d53e0..0000000 --- a/database/migrations/2023_01_05_222438_add_name_to_admins_table.php +++ /dev/null @@ -1,39 +0,0 @@ -string('name')->after('id')->nullable(); - }); - - $admins = Admin::all(); - foreach ($admins as $admin) { - $admin->name = $admin->id; - $admin->save(); - } - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('admins', function (Blueprint $table) { - $table->dropColumn('name'); - }); - } -}; diff --git a/database/migrations/2023_01_14_180605_change_type_to_hosts_table.php b/database/migrations/2023_01_14_180605_change_type_to_hosts_table.php deleted file mode 100644 index 59d1e9d..0000000 --- a/database/migrations/2023_01_14_180605_change_type_to_hosts_table.php +++ /dev/null @@ -1,36 +0,0 @@ -decimal('price', 10)->change(); - $table->decimal('managed_price', 10)->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('hosts', function (Blueprint $table) { - // 回滚 - $table->unsignedDouble('price', 10)->change(); - $table->unsignedDouble('managed_price', 10)->change(); - }); - } -}; diff --git a/database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php b/database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php deleted file mode 100644 index 87ebbad..0000000 --- a/database/migrations/2023_01_14_195428_add_ip_to_work_orders_table.php +++ /dev/null @@ -1,32 +0,0 @@ -string('ip')->nullable()->after('status'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_orders', function (Blueprint $table) { - $table->dropColumn('ip'); - }); - } -}; diff --git a/database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php b/database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php deleted file mode 100644 index d8b3ed8..0000000 --- a/database/migrations/2023_01_14_195435_add_ip_to_work_order_replies_table.php +++ /dev/null @@ -1,32 +0,0 @@ -string('ip')->nullable()->after('content'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_order_replies', function (Blueprint $table) { - $table->dropColumn('ip'); - }); - } -}; diff --git a/database/migrations/2023_01_14_202329_add_balance_to_modules_table.php b/database/migrations/2023_01_14_202329_add_balance_to_modules_table.php deleted file mode 100644 index 07c6249..0000000 --- a/database/migrations/2023_01_14_202329_add_balance_to_modules_table.php +++ /dev/null @@ -1,32 +0,0 @@ -decimal('balance', 20, 2)->default(0)->after('name'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('modules', function (Blueprint $table) { - $table->dropColumn('balance'); - }); - } -}; diff --git a/database/migrations/2023_01_15_011654_add_real_name_verified_at_to_users.php b/database/migrations/2023_01_15_011654_add_real_name_verified_at_to_users.php deleted file mode 100644 index 81afde5..0000000 --- a/database/migrations/2023_01_15_011654_add_real_name_verified_at_to_users.php +++ /dev/null @@ -1,34 +0,0 @@ -timestamp('real_name_verified_at')->nullable()->comment('实名认证时间')->after('email_verified_at'); - $table->string('id_card')->nullable()->comment('身份证号')->after('email_md5'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropColumn('real_name_verified_at'); - $table->dropColumn('id_card'); - }); - } -}; diff --git a/database/migrations/2023_01_15_191519_encrypt_id_card_from_users.php b/database/migrations/2023_01_15_191519_encrypt_id_card_from_users.php deleted file mode 100644 index 3c84161..0000000 --- a/database/migrations/2023_01_15_191519_encrypt_id_card_from_users.php +++ /dev/null @@ -1,40 +0,0 @@ -id_card) { - continue; - } - - echo "Encrypting user {$user->id}...".PHP_EOL; - // 设置值(不走模型的 mutator) - $user->setAttribute('id_card', Crypt::encryptString($user->id_card)); - - $user->save(); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - echo PHP_EOL.'无法解密用户数据,因为此操作是不可逆的。'.PHP_EOL; - } -}; diff --git a/database/migrations/2023_01_15_194111_add_real_name_verified_at_index_to_users.php b/database/migrations/2023_01_15_194111_add_real_name_verified_at_index_to_users.php deleted file mode 100644 index 6c9ecb9..0000000 --- a/database/migrations/2023_01_15_194111_add_real_name_verified_at_index_to_users.php +++ /dev/null @@ -1,32 +0,0 @@ -index('real_name_verified_at'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropIndex('users_real_name_verified_at_index'); - }); - } -}; diff --git a/database/migrations/2023_01_17_235003_change_decimal_total_to_users_and_modules_table.php b/database/migrations/2023_01_17_235003_change_decimal_total_to_users_and_modules_table.php deleted file mode 100644 index 0e2dbda..0000000 --- a/database/migrations/2023_01_17_235003_change_decimal_total_to_users_and_modules_table.php +++ /dev/null @@ -1,40 +0,0 @@ -decimal('balance', 20, 4)->change(); - }); - - Schema::table('modules', function (Blueprint $table) { - $table->decimal('balance', 20, 4)->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->decimal('balance', 10)->change(); - }); - - Schema::table('modules', function (Blueprint $table) { - $table->decimal('balance', 10)->change(); - }); - } -}; diff --git a/database/migrations/2023_01_19_021809_set_progress_nullable_to_tasks_table.php b/database/migrations/2023_01_19_021809_set_progress_nullable_to_tasks_table.php deleted file mode 100644 index c45f959..0000000 --- a/database/migrations/2023_01_19_021809_set_progress_nullable_to_tasks_table.php +++ /dev/null @@ -1,41 +0,0 @@ -dropColumn('progress'); - }); - - Schema::table('tasks', function (Blueprint $table) { - $table->unsignedTinyInteger('progress')->nullable()->after('title'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('tasks', function (Blueprint $table) { - $table->dropColumn('progress'); - }); - - Schema::table('tasks', function (Blueprint $table) { - $table->integer('progress')->after('title'); - }); - } -}; diff --git a/database/migrations/2023_01_19_162625_set_module_id_nullable_to_work_orders_table.php b/database/migrations/2023_01_19_162625_set_module_id_nullable_to_work_orders_table.php deleted file mode 100644 index 56f2186..0000000 --- a/database/migrations/2023_01_19_162625_set_module_id_nullable_to_work_orders_table.php +++ /dev/null @@ -1,32 +0,0 @@ -string('module_id')->nullable()->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('work_orders', function (Blueprint $table) { - $table->string('module_id')->nullable(false)->change(); - }); - } -}; diff --git a/database/migrations/2023_01_20_151627_add_timestamps_to_modules_table.php b/database/migrations/2023_01_20_151627_add_timestamps_to_modules_table.php deleted file mode 100644 index 85a3609..0000000 --- a/database/migrations/2023_01_20_151627_add_timestamps_to_modules_table.php +++ /dev/null @@ -1,39 +0,0 @@ -timestamps(); - }); - - // 刷新时间戳 - DB::table('modules')->update([ - 'created_at' => DB::raw('NOW()'), - 'updated_at' => DB::raw('NOW()'), - ]); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('modules', function (Blueprint $table) { - $table->dropColumn('created_at'); - $table->dropColumn('updated_at'); - }); - } -}; diff --git a/database/migrations/2023_01_20_153636_add_unavailable_status_to_hosts_table.php b/database/migrations/2023_01_20_153636_add_unavailable_status_to_hosts_table.php deleted file mode 100644 index c473b79..0000000 --- a/database/migrations/2023_01_20_153636_add_unavailable_status_to_hosts_table.php +++ /dev/null @@ -1,37 +0,0 @@ -timestamp('unavailable_at')->nullable()->comment('不可用时间')->after('suspended_at'); - $table->timestamp('locked_at')->nullable()->comment('锁定时间')->after('unavailable_at'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - \Illuminate\Support\Facades\DB::statement("ALTER TABLE `hosts` CHANGE `status` `status` ENUM('running','stopped','error','suspended','pending') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending';"); - - \Illuminate\Support\Facades\Schema::table('hosts', function (Blueprint $table) { - $table->dropColumn('unavailable_at'); - $table->dropColumn('locked_at'); - }); - } -}; diff --git a/database/migrations/2022_11_02_103610_create_admins_table.php b/database/migrations/2023_02_02_000000_create_admins_table.php similarity index 93% rename from database/migrations/2022_11_02_103610_create_admins_table.php rename to database/migrations/2023_02_02_000000_create_admins_table.php index 65d584e..d590e9f 100644 --- a/database/migrations/2022_11_02_103610_create_admins_table.php +++ b/database/migrations/2023_02_02_000000_create_admins_table.php @@ -15,15 +15,10 @@ public function up(): void { Schema::create('admins', function (Blueprint $table) { $table->id(); - - // email + $table->string('name')->nullable(); $table->string('email')->unique(); - - // password $table->string('password'); - $table->rememberToken(); - $table->timestamps(); }); } diff --git a/database/migrations/2022_11_27_100733_create_applications_table.php b/database/migrations/2023_02_02_000000_create_applications_table.php similarity index 86% rename from database/migrations/2022_11_27_100733_create_applications_table.php rename to database/migrations/2023_02_02_000000_create_applications_table.php index fee15bb..55a4c39 100644 --- a/database/migrations/2022_11_27_100733_create_applications_table.php +++ b/database/migrations/2023_02_02_000000_create_applications_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -15,13 +14,9 @@ public function up(): void { Schema::create('applications', function (Blueprint $table) { $table->id(); - $table->string('name')->index(); - $table->string('description')->nullable(); - - $table->string('api_token')->index()->unique(); - + $table->string('api_token')->unique(); $table->timestamps(); }); } diff --git a/database/migrations/2022_09_01_033240_create_balances_table.php b/database/migrations/2023_02_02_000000_create_balances_table.php similarity index 78% rename from database/migrations/2022_09_01_033240_create_balances_table.php rename to database/migrations/2023_02_02_000000_create_balances_table.php index 7fceee7..827ac6c 100644 --- a/database/migrations/2022_09_01_033240_create_balances_table.php +++ b/database/migrations/2023_02_02_000000_create_balances_table.php @@ -15,27 +15,14 @@ public function up(): void { Schema::create('balances', function (Blueprint $table) { $table->id(); - - // order id $table->string('order_id')->nullable()->index(); - - // trade id $table->string('trade_id')->nullable()->index(); - - // payment $table->string('payment')->nullable()->index(); - - // amount $table->decimal('amount', 10)->default(0); - - // paid_at + $table->decimal('remaining_amount', 10)->default(0); $table->timestamp('paid_at')->nullable(); - - // user id $table->unsignedBigInteger('user_id')->nullable()->index(); - $table->foreign('user_id')->references('id')->on('users'); - - $table->timestamps(); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('NO ACTION')->onDelete('NO ACTION'); }); } diff --git a/database/migrations/2022_08_13_083908_create_notifications_table.php b/database/migrations/2023_02_02_000000_create_notifications_table.php similarity index 81% rename from database/migrations/2022_08_13_083908_create_notifications_table.php rename to database/migrations/2023_02_02_000000_create_notifications_table.php index 6d7e703..14ad82f 100644 --- a/database/migrations/2022_08_13_083908_create_notifications_table.php +++ b/database/migrations/2023_02_02_000000_create_notifications_table.php @@ -14,9 +14,10 @@ public function up(): void { Schema::create('notifications', function (Blueprint $table) { - $table->uuid('id')->primary(); + $table->uuid()->primary(); $table->string('type'); - $table->morphs('notifiable'); + $table->string('notifiable_type')->index(); + $table->unsignedBigInteger('notifiable_id')->index(); $table->text('data'); $table->timestamp('read_at')->nullable(); $table->timestamps(); diff --git a/database/migrations/2022_08_12_123308_create_modules_table.php b/database/migrations/2023_02_02_000001_create_modules_table.php similarity index 55% rename from database/migrations/2022_08_12_123308_create_modules_table.php rename to database/migrations/2023_02_02_000001_create_modules_table.php index 25c47e4..a4af1b0 100644 --- a/database/migrations/2022_08_12_123308_create_modules_table.php +++ b/database/migrations/2023_02_02_000001_create_modules_table.php @@ -14,24 +14,15 @@ public function up(): void { Schema::create('modules', function (Blueprint $table) { - $table->string('id')->index()->primary()->unique(); - + $table->string('id')->primary(); $table->string('name')->index(); - - // api token - $table->string('api_token')->nullable()->unique()->index(); + $table->decimal('balance', 20, 4)->default(0)->index(); + $table->string('api_token')->nullable()->unique(); + $table->string('url')->nullable()->index(); + $table->enum('status', ['up', 'down', 'maintenance'])->default('down')->index(); + $table->timestamps(); + $table->string('wecom_key')->nullable()->comment('企业微信机器人 key'); }); - - // if env is local - if (config('app.env') == 'local') { - $module = [ - 'id' => 'test', - 'name' => 'Example Module', - 'api_token' => '123456', - ]; - - (new App\Models\Module)->create($module); - } } /** diff --git a/database/migrations/2022_12_03_130419_create_module_allows_table.php b/database/migrations/2023_02_02_000002_create_module_allows_table.php similarity index 70% rename from database/migrations/2022_12_03_130419_create_module_allows_table.php rename to database/migrations/2023_02_02_000002_create_module_allows_table.php index cbefa97..151276c 100644 --- a/database/migrations/2022_12_03_130419_create_module_allows_table.php +++ b/database/migrations/2023_02_02_000002_create_module_allows_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -17,12 +16,11 @@ public function up(): void $table->id(); $table->string('module_id')->index(); - $table->foreign('module_id')->references('id')->on('modules')->cascadeOnDelete()->cascadeOnUpdate(); - $table->string('allowed_module_id')->index(); - $table->foreign('allowed_module_id')->references('id')->on('modules')->cascadeOnDelete()->cascadeOnUpdate(); - $table->timestamps(); + + $table->foreign(['allowed_module_id'])->references(['id'])->on('modules')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign(['module_id'])->references(['id'])->on('modules')->onUpdate('CASCADE')->onDelete('CASCADE'); }); } diff --git a/database/migrations/2022_08_13_051148_create_hosts_table.php b/database/migrations/2023_02_02_000003_create_hosts_table.php similarity index 52% rename from database/migrations/2022_08_13_051148_create_hosts_table.php rename to database/migrations/2023_02_02_000003_create_hosts_table.php index 3a41431..5ac0af9 100644 --- a/database/migrations/2022_08_13_051148_create_hosts_table.php +++ b/database/migrations/2023_02_02_000003_create_hosts_table.php @@ -15,31 +15,23 @@ public function up(): void { Schema::create('hosts', function (Blueprint $table) { $table->id(); - - // name $table->string('name')->index(); - - // provider id $table->string('module_id')->index(); - // $table->foreign('module_id')->references('id')->on('modules')->onDelete('set null'); - - // user_id $table->unsignedBigInteger('user_id')->index(); - $table->foreign('user_id')->references('id')->on('users'); - - // price - $table->double('price', 60, 8)->index(); - - // config + $table->decimal('price', 10)->index(); + $table->decimal('managed_price', 10)->nullable()->index(); $table->json('configuration')->nullable(); - - // status - $table->enum('status', ['running', 'stopped', 'error', 'suspended', 'pending'])->default('pending')->index(); - - // soft delete + $table->enum('status', ['running', 'stopped', 'error', 'suspended', 'pending', 'unavailable', 'locked'])->default('pending')->index(); + $table->tinyInteger('hour_at')->nullable()->index(); + $table->tinyInteger('minute_at')->nullable()->index(); + $table->timestamp('suspended_at')->nullable()->index(); + $table->timestamp('unavailable_at')->nullable()->comment('不可用时间'); + $table->timestamp('locked_at')->nullable()->comment('锁定时间'); $table->softDeletes(); - $table->timestamps(); + + $table->foreign(['module_id'])->references(['id'])->on('modules')->onUpdate('CASCADE')->onDelete('NO ACTION'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('NO ACTION')->onDelete('NO ACTION'); }); } diff --git a/database/migrations/2023_02_02_031145_add_soft_deletes_to_users.php b/database/migrations/2023_02_02_031145_add_soft_deletes_to_users.php deleted file mode 100644 index 75d1a91..0000000 --- a/database/migrations/2023_02_02_031145_add_soft_deletes_to_users.php +++ /dev/null @@ -1,38 +0,0 @@ -softDeletes(); - } - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - // if it has column `deleted_at`, drop it - if (Schema::hasColumn('users', 'deleted_at')) { - $table->dropSoftDeletes(); - } - }); - } -}; diff --git a/database/migrations/2023_02_02_193726_add_index_to_modules_table.php b/database/migrations/2023_02_02_193726_add_index_to_modules_table.php deleted file mode 100644 index 1750003..0000000 --- a/database/migrations/2023_02_02_193726_add_index_to_modules_table.php +++ /dev/null @@ -1,32 +0,0 @@ -index('balance'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('modules', function (Blueprint $table) { - $table->dropIndex('balance'); - }); - } -}; diff --git a/database/migrations/2023_02_02_195733_create_tasks_table.php b/database/migrations/2023_02_02_195733_create_tasks_table.php new file mode 100644 index 0000000..8f3c003 --- /dev/null +++ b/database/migrations/2023_02_02_195733_create_tasks_table.php @@ -0,0 +1,40 @@ +uuid()->primary(); + $table->string('title'); + $table->unsignedTinyInteger('progress')->nullable(); + $table->enum('status', ['pending', 'done', 'success', 'failed', 'error', 'cancelled', 'processing', 'need_operation'])->index(); + $table->unsignedBigInteger('user_id')->index(); + $table->unsignedBigInteger('host_id')->index(); + $table->string('module_id')->nullable()->index(); + $table->timestamps(); + }); + + // 设置存储引擎为 MEMORY + DB::statement('ALTER TABLE tasks ENGINE = MEMORY'); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('tasks'); + } +}; diff --git a/database/migrations/2023_02_02_195733_create_user_groups_table.php b/database/migrations/2023_02_02_195733_create_user_groups_table.php new file mode 100644 index 0000000..7fa910f --- /dev/null +++ b/database/migrations/2023_02_02_195733_create_user_groups_table.php @@ -0,0 +1,42 @@ +id(); + $table->string('name')->index()->comment('名称'); + $table->string('color')->nullable()->comment('颜色'); + $table->integer('discount')->default(100)->comment('优惠百分比'); + $table->boolean('exempt')->default(false)->comment('暂停/终止豁免权'); + $table->timestamps(); + }); + + Schema::table('users', function (Blueprint $table) { + $table->foreign(['user_group_id'])->references(['id'])->on('user_groups')->onUpdate('NO ACTION')->onDelete('SET NULL'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropForeign('users_user_group_id_foreign'); + }); + + Schema::dropIfExists('user_groups'); + } +}; diff --git a/database/migrations/2022_08_13_051705_create_workorders_table.php b/database/migrations/2023_02_02_195733_create_work_orders_table.php similarity index 57% rename from database/migrations/2022_08_13_051705_create_workorders_table.php rename to database/migrations/2023_02_02_195733_create_work_orders_table.php index f3f1271..b933e65 100644 --- a/database/migrations/2022_08_13_051705_create_workorders_table.php +++ b/database/migrations/2023_02_02_195733_create_work_orders_table.php @@ -16,28 +16,20 @@ public function up(): void Schema::create('work_orders', function (Blueprint $table) { $table->id(); - // title + $table->uuid()->nullable()->unique(); $table->string('title')->index(); - - // content $table->text('content'); - - // user id $table->unsignedBigInteger('user_id')->index(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - // module id - $table->string('module_id')->index(); - $table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade'); - - // host id - $table->unsignedBigInteger('host_id')->index()->nullable(); - $table->foreign('host_id')->references('id')->on('hosts')->onDelete('cascade'); - - // status + $table->string('module_id')->nullable()->index(); + $table->unsignedBigInteger('host_id')->nullable()->index(); $table->enum('status', ['open', 'user_read', 'closed', 'user_replied', 'replied', 'read', 'on_hold', 'in_progress', 'error', 'pending'])->default('pending')->index(); - + $table->string('ip')->nullable(); + $table->boolean('notify')->default(true)->comment('是否通知'); $table->timestamps(); + + $table->foreign(['host_id'])->references(['id'])->on('hosts')->onUpdate('NO ACTION')->onDelete('CASCADE'); + $table->foreign(['module_id'])->references(['id'])->on('modules')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('NO ACTION')->onDelete('CASCADE'); }); } diff --git a/database/migrations/2022_08_13_051817_create_workorder_replies_table.php b/database/migrations/2023_02_02_195734_create_work_order_replies_table.php similarity index 50% rename from database/migrations/2022_08_13_051817_create_workorder_replies_table.php rename to database/migrations/2023_02_02_195734_create_work_order_replies_table.php index e27898d..fa73dd8 100644 --- a/database/migrations/2022_08_13_051817_create_workorder_replies_table.php +++ b/database/migrations/2023_02_02_195734_create_work_order_replies_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -16,20 +15,19 @@ public function up(): void Schema::create('work_order_replies', function (Blueprint $table) { $table->id(); - // content $table->text('content'); - - // work_order id (on delete cascade) + $table->string('ip')->nullable(); $table->unsignedBigInteger('work_order_id')->index(); - $table->foreign('work_order_id')->references('id')->on('work_orders')->onDelete('cascade'); - - // user id - $table->unsignedBigInteger('user_id')->index(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->string('name')->nullable(); + $table->string('module_id')->nullable()->index(); + $table->string('role')->default('user')->comment('回复角色'); $table->boolean('is_pending')->default(false)->index(); - $table->timestamps(); + + $table->foreign(['module_id'])->references(['id'])->on('modules')->onUpdate('NO ACTION')->onDelete('CASCADE'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('NO ACTION')->onDelete('CASCADE'); + $table->foreign(['work_order_id'])->references(['id'])->on('work_orders')->onUpdate('NO ACTION')->onDelete('CASCADE'); }); } diff --git a/database/migrations/2023_01_17_010152_create_tag_tables.php b/database/migrations/2023_02_02_200339_create_tag_tables.php similarity index 78% rename from database/migrations/2023_01_17_010152_create_tag_tables.php rename to database/migrations/2023_02_02_200339_create_tag_tables.php index b96036b..5925c6c 100644 --- a/database/migrations/2023_01_17_010152_create_tag_tables.php +++ b/database/migrations/2023_02_02_200339_create_tag_tables.php @@ -4,9 +4,9 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateTagTables extends Migration +return new class extends Migration { - public function up() + public function up(): void { Schema::create('tags', function (Blueprint $table) { $table->id(); @@ -27,4 +27,10 @@ public function up() $table->unique(['tag_id', 'taggable_id', 'taggable_type']); }); } -} + + public function down(): void + { + Schema::dropIfExists('taggables'); + Schema::dropIfExists('tags'); + } +};