Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
优化:数据库结构调整
- Loading branch information
1 parent
23ba984
commit 8515ed5
Showing
69 changed files
with
535 additions
and
379 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,5 @@ | |
'toggle edit mode' => '切换编辑模式', | ||
'Quoted Post' => '引用帖子', | ||
'Add attachments' => '添加附件', | ||
'summary' => '帖子摘要', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/Plugins/Comment/src/migrations/2022_05_24_113652_update_topic_comment_table_add_pid.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Hyperf\Database\Schema\Schema; | ||
use Hyperf\Database\Schema\Blueprint; | ||
use Hyperf\Database\Migrations\Migration; | ||
|
||
class UpdateTopicCommentTableAddPid extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('topic_comment', function (Blueprint $table) { | ||
$table->string('post_id')->nullable()->after('id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('topic_comment', function (Blueprint $table) { | ||
// | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Plugins\Core\src\Command\Update; | ||
|
||
use App\Plugins\Comment\src\Model\TopicComment; | ||
use App\Plugins\Core\src\Models\Post; | ||
use App\Plugins\Topic\src\Models\Topic; | ||
use Hyperf\Command\Command as HyperfCommand; | ||
use Hyperf\Command\Annotation\Command; | ||
use Hyperf\Database\Schema\Blueprint; | ||
use Hyperf\Database\Schema\Schema; | ||
use Hyperf\DbConnection\Db; | ||
use Psr\Container\ContainerInterface; | ||
use Swoole\Coroutine\System; | ||
|
||
/** | ||
* @Command | ||
*/ | ||
#[Command] | ||
class V2_0 extends HyperfCommand | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
|
||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
|
||
parent::__construct('update:2_0'); | ||
|
||
} | ||
|
||
public function configure() | ||
{ | ||
parent::configure(); | ||
$this->setDescription('super-forum 2.0 升级迁移命令'); | ||
} | ||
|
||
public function handle() | ||
{ | ||
if(file_exists(BASE_PATH."/app/CodeFec/storage/update/2_0.lock")){ | ||
$this->error('你已经运行过此升级命令了,安全起见,禁止再次运行此命令'); | ||
$this->line('如有问题,请到论坛反馈: https://runpod.cn'); | ||
} | ||
$this->error('执行前一定要备份数据库 !!!'); | ||
$this->error('Make sure to backup the database before executing !!!'); | ||
$ask_backup = $this->ask('如果你已经备份数据库,请输入yes继续执行,否则请退出程序'); | ||
if($ask_backup !== 'yes'){ | ||
$this->error('退出迁移'); | ||
exit; | ||
} | ||
|
||
$this->info('开始迁移topic表'); | ||
$this->topic(); | ||
$this->info('开始迁移topic_comment表'); | ||
$this->topic_comment(); | ||
$this->info('迁移完毕,接下来开始清理旧数据'); | ||
if($this->ask('这是一个高危操作,请确保你已经备份数据,确认要清理旧数据吗?(yes/no)') === 'yes'){ | ||
$this->info('开始清理旧数据'); | ||
$this->clean_database(); | ||
$this->info('清理完毕'); | ||
|
||
} | ||
|
||
if(!is_dir(BASE_PATH."/app/CodeFec/storage/update")){ | ||
System::exec('mkdir -p '.BASE_PATH."/app/CodeFec/storage/update"); | ||
} | ||
file_put_contents(BASE_PATH."/app/CodeFec/storage/update/2_0.lock",time()); | ||
$this->info('Successfully!'); | ||
} | ||
|
||
private function topic() | ||
{ | ||
$topics = Db::table('topic')->where("post_id",'=',null)->get(['id','content','markdown','user_agent','user_ip','user_id','created_at', 'updated_at']); | ||
foreach($topics as $data){ | ||
$post = Post::query()->create([ | ||
'topic_id' => $data->id, | ||
'user_id' => $data->user_id, | ||
'content' => $data->content, | ||
'markdown' => $data->markdown, | ||
'user_agent' => $data->user_agent, | ||
'user_ip' => $data->user_ip, | ||
'created_at' => $data->created_at, | ||
'updated_at' => $data->updated_at | ||
]); | ||
Topic::query()->where('id',$data->id)->update(['post_id' =>$post['id']]); | ||
} | ||
} | ||
|
||
private function topic_comment() | ||
{ | ||
$comments = Db::table('topic_comment')->where("post_id",'=',null)->get(['id','user_id','content','markdown','user_agent','user_ip','created_at','updated_at']); | ||
foreach($comments as $data){ | ||
$post = Post::query()->create([ | ||
'comment_id' => $data->id, | ||
'user_id' => $data->user_id, | ||
'content' => $data->content, | ||
'markdown' => $data->markdown, | ||
'user_agent' => $data->user_agent, | ||
'user_ip' => $data->user_ip, | ||
'created_at' => $data->created_at, | ||
'updated_at' => $data->updated_at, | ||
]); | ||
TopicComment::query()->where('id',$data->id)->update(['post_id' =>$post['id']]); | ||
} | ||
} | ||
|
||
private function clean_database() | ||
{ | ||
$this->info('清理topic表'); | ||
Schema::table('topic', function (Blueprint $table) { | ||
// 删除 多余字段 | ||
$table->dropColumn(['content','markdown','user_agent','user_ip','like','_token']); | ||
}); | ||
$this->info('清理topic_cpmment表'); | ||
Schema::table('topic_comment', function (Blueprint $table) { | ||
// 删除 多余字段 | ||
$table->dropColumn(['content','markdown','user_agent','user_ip','likes']); | ||
}); | ||
} | ||
} |
Oops, something went wrong.