From 88740f0232f73ba7f1ddd61e0d951dc11bb40e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=94=E5=A7=AC=E6=A1=91?= <867057410@qq.com> Date: Wed, 22 Jun 2022 01:12:40 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E6=96=B0=E5=8F=98=E5=8A=A8=E5=AF=B9MYSQL?= =?UTF-8?q?<=3D5.6=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022_01_22_231856_improve_node_table.php | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 database/migrations/5.6/2022_01_22_231856_improve_node_table.php diff --git a/database/migrations/5.6/2022_01_22_231856_improve_node_table.php b/database/migrations/5.6/2022_01_22_231856_improve_node_table.php new file mode 100644 index 00000000..1268729f --- /dev/null +++ b/database/migrations/5.6/2022_01_22_231856_improve_node_table.php @@ -0,0 +1,90 @@ +configs as $config) { + Config::insert(['name' => $config]); + } + + // 插入新字段 + Schema::table('node', function (Blueprint $table) { + $table->text('profile')->comment('节点设置选项')->after('description'); + $table->unsignedInteger('relay_node_id')->nullable()->comment('中转节点对接母节点, 默认NULL')->after('is_relay'); + }); + + foreach (Node::all() as $node) { + $profile = null; + switch ($node->type) { + case 0: + $profile = [ + 'method' => $node->method, + ]; + break; + case 2: + $profile = [ + 'method' => $node->v2_method, + 'v2_alter_id' => $node->v2_alter_id, + 'v2_net' => $node->v2_net, + 'v2_type' => $node->v2_type, + 'v2_host' => $node->v2_host, + 'v2_path' => $node->v2_path, + 'v2_tls' => $node->v2_tls ? 'tls' : '', + 'v2_sni' => $node->v2_sni, + ]; + break; + case 3: + $profile = [ + 'allow_insecure' => false, + ]; + break; + case 1: + case 4: + $profile = [ + 'method' => $node->method, + 'protocol' => $node->protocol, + 'obfs' => $node->obfs, + 'obfs_param' => $node->obfs_param, + 'protocol_param' => $node->protocol_param, + 'passwd' => $node->passwd, + ]; + break; + default: + } + Node::whereId($node->id)->update(['profile' => $profile]); + } + + // 销毁老字段 + Schema::table('node', function (Blueprint $table) { + $table->dropColumn('relay_server', 'relay_port', 'method', 'protocol', 'protocol_param', 'obfs', 'obfs_param', 'compatible', 'single', 'passwd', 'v2_alter_id', + 'v2_method', 'v2_net', 'v2_type', 'v2_host', 'v2_path', 'v2_tls', 'v2_sni', 'tls_provider', 'is_relay'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Config::destroy($this->configs); + // 太复杂了,无法逆转了 + } +}