diff --git a/db/migrations/20210324064239.php b/db/migrations/20210324064239.php index b5eaafd4..3c170df3 100644 --- a/db/migrations/20210324064239.php +++ b/db/migrations/20210324064239.php @@ -3268,619 +3268,6 @@ final class V20210324064239 extends AbstractMigration 'after' => 'create_time', ]) ->create(); - $this->table('kg_im_friend_group', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('user_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '用户编号', - 'after' => 'id', - ]) - ->addColumn('name', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 100, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '名称', - 'after' => 'user_id', - ]) - ->addColumn('priority', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '优先级', - 'after' => 'name', - ]) - ->addColumn('deleted', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '删除标识', - 'after' => 'priority', - ]) - ->addColumn('user_count', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '成员数', - 'after' => 'deleted', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'user_count', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->addIndex(['user_id'], [ - 'name' => 'user_id', - 'unique' => true, - ]) - ->create(); - $this->table('kg_im_friend_user', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('user_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '用户编号', - 'after' => 'id', - ]) - ->addColumn('friend_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '目标编号', - 'after' => 'user_id', - ]) - ->addColumn('group_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '分组编号', - 'after' => 'friend_id', - ]) - ->addColumn('msg_count', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '消息数', - 'after' => 'group_id', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'msg_count', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->addIndex(['user_id', 'friend_id'], [ - 'name' => 'user_friend', - 'unique' => false, - ]) - ->create(); - $this->table('kg_im_group', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('owner_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '群主编号', - 'after' => 'id', - ]) - ->addColumn('course_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '课程编号', - 'after' => 'owner_id', - ]) - ->addColumn('type', 'integer', [ - 'null' => false, - 'default' => '1', - 'limit' => MysqlAdapter::INT_REGULAR, - 'comment' => '类型', - 'after' => 'course_id', - ]) - ->addColumn('name', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 100, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '名称', - 'after' => 'type', - ]) - ->addColumn('avatar', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 100, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '头像', - 'after' => 'name', - ]) - ->addColumn('about', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 255, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '简介', - 'after' => 'avatar', - ]) - ->addColumn('published', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '发布标识', - 'after' => 'about', - ]) - ->addColumn('deleted', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '删除标识', - 'after' => 'published', - ]) - ->addColumn('user_count', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '成员数', - 'after' => 'deleted', - ]) - ->addColumn('msg_count', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '消息数', - 'after' => 'user_count', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'msg_count', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->create(); - $this->table('kg_im_group_user', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('group_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '群组编号', - 'after' => 'id', - ]) - ->addColumn('user_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '用户编号', - 'after' => 'group_id', - ]) - ->addColumn('priority', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '优先级', - 'after' => 'user_id', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'priority', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->addIndex(['group_id'], [ - 'name' => 'group_id', - 'unique' => false, - ]) - ->addIndex(['group_id', 'user_id'], [ - 'name' => 'group_user', - 'unique' => false, - ]) - ->addIndex(['user_id'], [ - 'name' => 'user_id', - 'unique' => false, - ]) - ->create(); - $this->table('kg_im_message', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('chat_id', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 30, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '对话编号', - 'after' => 'id', - ]) - ->addColumn('sender_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '发送方', - 'after' => 'chat_id', - ]) - ->addColumn('receiver_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '接收方', - 'after' => 'sender_id', - ]) - ->addColumn('receiver_type', 'integer', [ - 'null' => false, - 'default' => '1', - 'limit' => MysqlAdapter::INT_REGULAR, - 'comment' => '接收方类型', - 'after' => 'receiver_id', - ]) - ->addColumn('content', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 3000, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '内容', - 'after' => 'receiver_type', - ]) - ->addColumn('viewed', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '已读标识', - 'after' => 'content', - ]) - ->addColumn('deleted', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '删除标识', - 'after' => 'viewed', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'deleted', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->addIndex(['chat_id'], [ - 'name' => 'chat_id', - 'unique' => false, - ]) - ->addIndex(['receiver_id', 'receiver_type'], [ - 'name' => 'receiver', - 'unique' => false, - ]) - ->create(); - $this->table('kg_im_notice', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('sender_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '发送方', - 'after' => 'id', - ]) - ->addColumn('receiver_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '接收方', - 'after' => 'sender_id', - ]) - ->addColumn('item_type', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '条目类型', - 'after' => 'receiver_id', - ]) - ->addColumn('item_info', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 1500, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '条目内容', - 'after' => 'item_type', - ]) - ->addColumn('viewed', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '已读标识', - 'after' => 'item_info', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'viewed', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->addIndex(['receiver_id'], [ - 'name' => 'receiver_id', - 'unique' => false, - ]) - ->addIndex(['sender_id'], [ - 'name' => 'sender_id', - 'unique' => false, - ]) - ->create(); - $this->table('kg_im_user', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '主键编号', - ]) - ->addColumn('name', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 30, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '名称', - 'after' => 'id', - ]) - ->addColumn('avatar', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 100, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '头像', - 'after' => 'name', - ]) - ->addColumn('sign', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 30, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '签名', - 'after' => 'avatar', - ]) - ->addColumn('skin', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 100, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '皮肤', - 'after' => 'sign', - ]) - ->addColumn('status', 'string', [ - 'null' => false, - 'default' => 'hide', - 'limit' => 15, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '在线状态', - 'after' => 'skin', - ]) - ->addColumn('deleted', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '删除标识', - 'after' => 'status', - ]) - ->addColumn('friend_count', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '好友数', - 'after' => 'deleted', - ]) - ->addColumn('group_count', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '群组数', - 'after' => 'friend_count', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'group_count', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->create(); $this->table('kg_learning', [ 'id' => false, 'primary_key' => ['id'], diff --git a/db/migrations/20210403184518.php b/db/migrations/20210403184518.php index 85189d44..5c3aa05a 100644 --- a/db/migrations/20210403184518.php +++ b/db/migrations/20210403184518.php @@ -46,15 +46,6 @@ final class V20210403184518 extends AbstractMigration ]; $this->table('kg_user')->insert($user)->saveData(); - - $imUser = [ - 'id' => $user['id'], - 'name' => $user['name'], - 'avatar' => $user['avatar'], - 'create_time' => $now, - ]; - - $this->table('kg_im_user')->insert($imUser)->saveData(); } protected function initRoleData() @@ -949,7 +940,6 @@ final class V20210403184518 extends AbstractMigration 'course_review' => ['enabled' => 1, 'point' => 50], 'chapter_study' => ['enabled' => 1, 'point' => 10], 'site_visit' => ['enabled' => 1, 'point' => 10], - 'im_discuss' => ['enabled' => 1, 'point' => 10], 'article_post' => ['enabled' => 1, 'point' => 20, 'limit' => 50], 'question_post' => ['enabled' => 1, 'point' => 5, 'limit' => 50], 'answer_post' => ['enabled' => 1, 'point' => 5, 'limit' => 50], diff --git a/db/migrations/20210720153027.php b/db/migrations/20210720153027.php index 21e1f9d8..0a980597 100644 --- a/db/migrations/20210720153027.php +++ b/db/migrations/20210720153027.php @@ -27,7 +27,13 @@ final class V20210720153027 extends AbstractMigration protected function createCourseTagTable() { - $this->table('kg_course_tag', [ + $tableName = 'kg_course_tag'; + + if ($this->table($tableName)->exists()) { + return; + } + + $this->table($tableName, [ 'id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', @@ -80,8 +86,10 @@ final class V20210720153027 extends AbstractMigration protected function alterCourseTable() { - $this->table('kg_course') - ->addColumn('tags', 'string', [ + $table = $this->table('kg_course'); + + if ($table->hasColumn('tags') == false) { + $table->addColumn('tags', 'string', [ 'null' => false, 'default' => '', 'limit' => 255, @@ -89,13 +97,18 @@ final class V20210720153027 extends AbstractMigration 'encoding' => 'utf8mb4', 'comment' => '标签', 'after' => 'summary', - ])->save(); + ]); + } + + $table->save(); } protected function alterCategoryTable() { - $this->table('kg_category') - ->addColumn('alias', 'string', [ + $table = $this->table('kg_category'); + + if ($table->hasColumn('alias') == false) { + $table->addColumn('alias', 'string', [ 'null' => false, 'default' => '', 'limit' => 30, @@ -103,7 +116,11 @@ final class V20210720153027 extends AbstractMigration 'encoding' => 'utf8mb4', 'comment' => '别名', 'after' => 'name', - ])->addColumn('icon', 'string', [ + ]); + } + + if ($table->hasColumn('icon') == false) { + $table->addColumn('icon', 'string', [ 'null' => false, 'default' => '', 'limit' => 100, @@ -111,13 +128,19 @@ final class V20210720153027 extends AbstractMigration 'encoding' => 'utf8mb4', 'comment' => '图标', 'after' => 'name', - ])->save(); + ]); + } + + $table->save(); } protected function alterTagTable() { - $this->table('kg_tag') - ->addColumn('scopes', 'string', [ + $table = $this->table('kg_tag'); + + if ($table->hasColumn('scopes') == false) { + + $table->addColumn('scopes', 'string', [ 'null' => false, 'default' => '', 'limit' => 100, @@ -125,32 +148,43 @@ final class V20210720153027 extends AbstractMigration 'encoding' => 'utf8mb4', 'comment' => '范围', 'after' => 'icon', - ]) - ->addColumn('course_count', 'integer', [ + ]); + } + + if ($table->hasColumn('course_count') == false) { + $table->addColumn('course_count', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '课程数', 'after' => 'follow_count', - ]) - ->addColumn('article_count', 'integer', [ + ]); + } + + if ($table->hasColumn('article_count') == false) { + $table->addColumn('article_count', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '文章数', 'after' => 'course_count', - ]) - ->addColumn('question_count', 'integer', [ + ]); + } + + if ($table->hasColumn('question_count') == false) { + $table->addColumn('question_count', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '问题数', 'after' => 'article_count', - ]) - ->save(); + ]); + } + + $table->save(); } protected function handleCourseTags() diff --git a/db/migrations/20210802021814.php b/db/migrations/20210802021814.php index 51852a92..59f542dd 100644 --- a/db/migrations/20210802021814.php +++ b/db/migrations/20210802021814.php @@ -17,8 +17,10 @@ final class V20210802021814 extends AbstractMigration protected function alterPageTable() { - $this->table('kg_page') - ->addColumn('alias', 'string', [ + $table = $this->table('kg_page'); + + if ($table->hasColumn('alias') == false) { + $table->addColumn('alias', 'string', [ 'null' => false, 'default' => '', 'limit' => 50, @@ -26,7 +28,10 @@ final class V20210802021814 extends AbstractMigration 'encoding' => 'utf8mb4', 'comment' => '别名', 'after' => 'title', - ])->save(); + ]); + } + + $table->save(); } } diff --git a/db/migrations/20210809153030.php b/db/migrations/20210809153030.php index a8d7ee89..bd94311b 100644 --- a/db/migrations/20210809153030.php +++ b/db/migrations/20210809153030.php @@ -5,19 +5,22 @@ * @link https://www.koogua.com */ +require_once 'SettingTrait.php'; + use Phinx\Migration\AbstractMigration; final class V20210809153030 extends AbstractMigration { + use SettingTrait; + public function up() { - $this->handleVodSetting(); - $this->handleImSetting(); + $this->handleVodSettings(); $this->handleRemotePlayUrl(); } - protected function handleVodSetting() + protected function handleVodSettings() { $rows = [ [ @@ -32,18 +35,7 @@ final class V20210809153030 extends AbstractMigration ], ]; - $this->table('kg_setting')->insert($rows)->save(); - } - - protected function handleImSetting() - { - $row = [ - 'section' => 'im.main', - 'item_key' => 'enabled', - 'item_value' => '1', - ]; - - $this->table('kg_setting')->insert($row)->saveData(); + $this->insertSettings($rows); } protected function handleRemotePlayUrl() diff --git a/db/migrations/20210820064755.php b/db/migrations/20210820064755.php index 657de33f..8c19c82b 100644 --- a/db/migrations/20210820064755.php +++ b/db/migrations/20210820064755.php @@ -5,17 +5,21 @@ * @link https://www.koogua.com */ +require_once 'SettingTrait.php'; + use Phinx\Migration\AbstractMigration; final class V20210820064755 extends AbstractMigration { + use SettingTrait; + public function up() { - $this->handleContactSetting(); + $this->handleContactSettings(); } - protected function handleContactSetting() + protected function handleContactSettings() { $rows = [ [ @@ -65,7 +69,7 @@ final class V20210820064755 extends AbstractMigration ], ]; - $this->table('kg_setting')->insert($rows)->save(); + $this->insertSettings($rows); } } diff --git a/db/migrations/20210825111618.php b/db/migrations/20210825111618.php index 5b337651..d3553457 100644 --- a/db/migrations/20210825111618.php +++ b/db/migrations/20210825111618.php @@ -19,9 +19,11 @@ final class V20210825111618 extends AbstractMigration { $table = $this->table('kg_upload'); - $table->removeIndexByName('md5')->save(); + if ($table->hasIndexByName('md5')) { + $table->removeIndexByName('md5')->save(); + $table->addIndex('md5')->save(); + } - $table->addIndex('md5')->save(); } } diff --git a/db/migrations/20210903040558.php b/db/migrations/20210903040558.php index d998c32b..57f655b1 100644 --- a/db/migrations/20210903040558.php +++ b/db/migrations/20210903040558.php @@ -5,17 +5,21 @@ * @link https://www.koogua.com */ +require_once 'SettingTrait.php'; + use Phinx\Migration\AbstractMigration; final class V20210903040558 extends AbstractMigration { + use SettingTrait; + public function up() { - $this->handleVodSetting(); + $this->handleVodSettings(); } - protected function handleVodSetting() + protected function handleVodSettings() { $row = $this->getQueryBuilder() ->select('*') diff --git a/db/migrations/20210916072842.php b/db/migrations/20210916072842.php index e8b001eb..8aa7b850 100644 --- a/db/migrations/20210916072842.php +++ b/db/migrations/20210916072842.php @@ -7,15 +7,19 @@ use Phinx\Migration\AbstractMigration; +require_once 'SettingTrait.php'; + final class V20210916072842 extends AbstractMigration { + use SettingTrait; + public function up() { - $this->handleLocalAuthSetting(); + $this->handleLocalAuthSettings(); } - protected function handleLocalAuthSetting() + protected function handleLocalAuthSettings() { $rows = [ [ @@ -30,7 +34,7 @@ final class V20210916072842 extends AbstractMigration ] ]; - $this->table('kg_setting')->insert($rows)->save(); + $this->insertSettings($rows); } } diff --git a/db/migrations/20210917093354.php b/db/migrations/20210917093354.php index 08a64015..0b68b55b 100644 --- a/db/migrations/20210917093354.php +++ b/db/migrations/20210917093354.php @@ -5,16 +5,20 @@ * @link https://www.koogua.com */ +require_once 'SettingTrait.php'; + use Phinx\Db\Adapter\MysqlAdapter; class V20210917093354 extends Phinx\Migration\AbstractMigration { + use SettingTrait; + public function up() { $this->alterConnectTable(); $this->alterWechatSubscribeTable(); - $this->handleLocalAuthSetting(); + $this->handleLocalAuthSettings(); } protected function alterConnectTable() @@ -92,7 +96,7 @@ class V20210917093354 extends Phinx\Migration\AbstractMigration $table->save(); } - protected function handleLocalAuthSetting() + protected function handleLocalAuthSettings() { $rows = [ [ @@ -107,7 +111,7 @@ class V20210917093354 extends Phinx\Migration\AbstractMigration ] ]; - $this->table('kg_setting')->insert($rows)->save(); + $this->insertSettings($rows); } } diff --git a/db/migrations/20211017085325.php b/db/migrations/20211017085325.php index 6d01c66a..f9f52167 100644 --- a/db/migrations/20211017085325.php +++ b/db/migrations/20211017085325.php @@ -18,15 +18,20 @@ final class V20211017085325 extends AbstractMigration protected function alterCourseTable() { - $this->table('kg_course') - ->addColumn('fake_user_count', 'integer', [ + $table = $this->table('kg_course'); + + if ($table->hasColumn('fake_user_count') == false) { + $table->addColumn('fake_user_count', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '伪造用户数', 'after' => 'user_count', - ])->save(); + ]); + } + + $table->save(); } } diff --git a/db/migrations/20211019093522.php b/db/migrations/20211019093522.php index 5946d094..9c9c2d0e 100644 --- a/db/migrations/20211019093522.php +++ b/db/migrations/20211019093522.php @@ -19,28 +19,38 @@ final class V20211019093522 extends AbstractMigration protected function alterUserSessionTable() { - $this->table('kg_user_session') - ->addColumn('deleted', 'integer', [ + $table = $this->table('kg_user_session'); + + if ($table->hasColumn('deleted') == false) { + $table->addColumn('deleted', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '删除标识', 'after' => 'client_ip', - ])->save(); + ]); + } + + $table->save(); } protected function alterUserTokenTable() { - $this->table('kg_user_token') - ->addColumn('deleted', 'integer', [ + $table = $this->table('kg_user_token'); + + if ($table->hasColumn('deleted') == false) { + $table->addColumn('deleted', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '删除标识', 'after' => 'client_ip', - ])->save(); + ]); + } + + $table->save(); } } diff --git a/db/migrations/20211231013226.php b/db/migrations/20211231013226.php index a3f35979..69337b25 100644 --- a/db/migrations/20211231013226.php +++ b/db/migrations/20211231013226.php @@ -2,26 +2,29 @@ use Phinx\Migration\AbstractMigration; +require_once 'SettingTrait.php'; + final class V20211231013226 extends AbstractMigration { + use SettingTrait; + public function up() { - $this->handleSmsSetting(); + $this->handleSmsSettings(); } - protected function handleSmsSetting() + protected function handleSmsSettings() { - $row = + $rows = [ [ - [ - 'section' => 'sms', - 'item_key' => 'region', - 'item_value' => 'ap-guangzhou', - ] - ]; + 'section' => 'sms', + 'item_key' => 'region', + 'item_value' => 'ap-guangzhou', + ] + ]; - $this->table('kg_setting')->insert($row)->save(); + $this->insertSettings($rows); } } diff --git a/db/migrations/20220607014823.php b/db/migrations/20220607014823.php index 5c8a5778..95b40e8d 100644 --- a/db/migrations/20220607014823.php +++ b/db/migrations/20220607014823.php @@ -21,29 +21,28 @@ final class V20220607014823 extends AbstractMigration protected function handleSiteSettings() { - $rows = + $rows = [ [ - [ - 'section' => 'site', - 'item_key' => 'isp_sn', - 'item_value' => '', - ], - [ - 'section' => 'site', - 'item_key' => 'isp_link', - 'item_value' => 'https://dxzhgl.miit.gov.cn', - ], - [ - 'section' => 'site', - 'item_key' => 'company_sn', - 'item_value' => '', - ], - [ - 'section' => 'site', - 'item_key' => 'company_sn_link', - 'item_value' => '', - ], - ]; + 'section' => 'site', + 'item_key' => 'isp_sn', + 'item_value' => '', + ], + [ + 'section' => 'site', + 'item_key' => 'isp_link', + 'item_value' => 'https://dxzhgl.miit.gov.cn', + ], + [ + 'section' => 'site', + 'item_key' => 'company_sn', + 'item_value' => '', + ], + [ + 'section' => 'site', + 'item_key' => 'company_sn_link', + 'item_value' => '', + ], + ]; $this->insertSettings($rows); } diff --git a/db/migrations/20220801025747.php b/db/migrations/20220801025747.php index 21a3e9ea..6ceec26c 100644 --- a/db/migrations/20220801025747.php +++ b/db/migrations/20220801025747.php @@ -20,7 +20,13 @@ class V20220801025747 extends Phinx\Migration\AbstractMigration protected function createMigrationTaskTable() { - $this->table('kg_migration_task', [ + $tableName = 'kg_migration_task'; + + if ($this->table($tableName)->exists()) { + return; + } + + $this->table($tableName, [ 'id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', @@ -70,13 +76,21 @@ class V20220801025747 extends Phinx\Migration\AbstractMigration protected function dropImTables() { - $this->table('kg_im_friend_group')->drop()->save(); - $this->table('kg_im_friend_user')->drop()->save(); - $this->table('kg_im_group')->drop()->save(); - $this->table('kg_im_group_user')->drop()->save(); - $this->table('kg_im_message')->drop()->save(); - $this->table('kg_im_notice')->drop()->save(); - $this->table('kg_im_user')->drop()->save(); + $tableNames = [ + 'kg_im_friend_group', + 'kg_im_friend_user', + 'kg_im_group', + 'kg_im_group_user', + 'kg_im_message', + 'kg_im_notice', + 'kg_im_user', + ]; + + foreach ($tableNames as $tableName) { + if ($this->table($tableName)->exists()) { + $this->table($tableName)->drop()->save(); + } + } } protected function deleteImGroupNav()