From 9d4225f6636fb9adb595f36f0fe0a21d66859788 Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 3 Mar 2021 17:29:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/ImNotice.php | 28 ---------- app/Repos/Connect.php | 4 -- app/Repos/CourseFavorite.php | 4 -- app/Repos/ImFriendUser.php | 4 -- app/Repos/ImNotice.php | 4 -- app/Repos/UserSession.php | 1 - app/Repos/UserToken.php | 1 - .../20201004095647_create_online_table.php | 29 ----------- ...201205112717_insert_oauth_setting_data.php | 17 ++++-- .../20201212112717_data_202012121830.php | 27 +++++----- .../20210228035113_data_202102280351.php | 52 ++++++++----------- .../20210302021013_schema_202103021010.php | 6 +++ 12 files changed, 54 insertions(+), 123 deletions(-) diff --git a/app/Models/ImNotice.php b/app/Models/ImNotice.php index 73fe6bfd..258f77fb 100644 --- a/app/Models/ImNotice.php +++ b/app/Models/ImNotice.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class ImNotice extends Model { @@ -59,13 +57,6 @@ class ImNotice extends Model */ public $item_info = ''; - /** - * 优先级 - * - * @var int - */ - public $priority = 0; - /** * 阅读标识 * @@ -73,13 +64,6 @@ class ImNotice extends Model */ public $viewed = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -99,18 +83,6 @@ class ImNotice extends Model return 'kg_im_notice'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { if (!empty($this->item_info)) { diff --git a/app/Repos/Connect.php b/app/Repos/Connect.php index 49c07865..5337cfac 100644 --- a/app/Repos/Connect.php +++ b/app/Repos/Connect.php @@ -28,10 +28,6 @@ class Connect extends Repository $query->andWhere('provider = :provider:', ['provider' => $where['provider']]); } - if (isset($where['deleted'])) { - $query->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - $query->orderBy('id DESC'); return $query->execute(); diff --git a/app/Repos/CourseFavorite.php b/app/Repos/CourseFavorite.php index 8ea512b9..4fc7ad04 100644 --- a/app/Repos/CourseFavorite.php +++ b/app/Repos/CourseFavorite.php @@ -25,10 +25,6 @@ class CourseFavorite extends Repository $builder->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]); } - if (isset($where['deleted'])) { - $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - switch ($sort) { default: $orderBy = 'id DESC'; diff --git a/app/Repos/ImFriendUser.php b/app/Repos/ImFriendUser.php index 355b1e44..39d0467e 100644 --- a/app/Repos/ImFriendUser.php +++ b/app/Repos/ImFriendUser.php @@ -25,10 +25,6 @@ class ImFriendUser extends Repository $builder->andWhere('friend_id = :friend_id:', ['friend_id' => $where['friend_id']]); } - if (isset($where['blocked'])) { - $builder->andWhere('blocked = :blocked:', ['blocked' => $where['blocked']]); - } - switch ($sort) { case 'oldest': $orderBy = 'id ASC'; diff --git a/app/Repos/ImNotice.php b/app/Repos/ImNotice.php index ee87d26c..e502fd37 100644 --- a/app/Repos/ImNotice.php +++ b/app/Repos/ImNotice.php @@ -27,10 +27,6 @@ class ImNotice extends Repository $builder->andWhere('receiver_id = :receiver_id:', ['receiver_id' => $where['receiver_id']]); } - if (isset($where['deleted'])) { - $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - switch ($sort) { case 'oldest': $orderBy = 'id ASC'; diff --git a/app/Repos/UserSession.php b/app/Repos/UserSession.php index be56e73c..d1cd85d5 100644 --- a/app/Repos/UserSession.php +++ b/app/Repos/UserSession.php @@ -17,7 +17,6 @@ class UserSession extends Repository { return UserSessionModel::query() ->where('user_id = :user_id:', ['user_id' => $userId]) - ->andWhere('deleted = 0') ->execute(); } diff --git a/app/Repos/UserToken.php b/app/Repos/UserToken.php index 70da5427..799ddb20 100644 --- a/app/Repos/UserToken.php +++ b/app/Repos/UserToken.php @@ -17,7 +17,6 @@ class UserToken extends Repository { return UserTokenModel::query() ->where('user_id = :user_id:', ['user_id' => $userId]) - ->andWhere('deleted = 0') ->execute(); } diff --git a/db/migrations/20201004095647_create_online_table.php b/db/migrations/20201004095647_create_online_table.php index 9f9438e7..25497498 100644 --- a/db/migrations/20201004095647_create_online_table.php +++ b/db/migrations/20201004095647_create_online_table.php @@ -81,35 +81,6 @@ class CreateOnlineTable extends Phinx\Migration\AbstractMigration 'unique' => false, ]) ->create(); - $this->table('kg_task', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->save(); - $this->table('kg_trade', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '主键编号', - 'row_format' => 'DYNAMIC', - ]) - ->changeColumn('channel_sn', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 64, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '平台序号', - 'after' => 'channel', - ]) - ->save(); } } diff --git a/db/migrations/20201205112717_insert_oauth_setting_data.php b/db/migrations/20201205112717_insert_oauth_setting_data.php index 0b5643cc..8bde8590 100644 --- a/db/migrations/20201205112717_insert_oauth_setting_data.php +++ b/db/migrations/20201205112717_insert_oauth_setting_data.php @@ -80,9 +80,20 @@ final class InsertOauthSettingData extends AbstractMigration public function down() { - $this->execute("DELETE FROM kg_setting WHERE section = 'oauth.qq'"); - $this->execute("DELETE FROM kg_setting WHERE section = 'oauth.weixin'"); - $this->execute("DELETE FROM kg_setting WHERE section = 'oauth.weibo'"); + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'oauth.qq']) + ->execute(); + + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'oauth.weixin']) + ->execute(); + + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'oauth.weibo']) + ->execute(); } } \ No newline at end of file diff --git a/db/migrations/20201212112717_data_202012121830.php b/db/migrations/20201212112717_data_202012121830.php index ae7c66ba..e73b008e 100644 --- a/db/migrations/20201212112717_data_202012121830.php +++ b/db/migrations/20201212112717_data_202012121830.php @@ -60,30 +60,27 @@ final class Data202012121830 extends AbstractMigration protected function updateSmsTemplate() { - $table = 'kg_setting'; - - $where = ['section' => 'sms', 'item_key' => 'template']; - $setting = $this->getQueryBuilder() ->select('*') - ->from($table) - ->where($where) - ->execute() - ->fetch('assoc'); + ->from('kg_setting') + ->where(['section' => 'sms', 'item_key' => 'template']) + ->execute()->fetch('assoc'); + + if (!$setting) return; $itemValue = json_decode($setting['item_value'], true); $newItemValue = json_encode([ - 'verify' => $itemValue['verify'], - 'order_finish' => $itemValue['order'], - 'refund_finish' => $itemValue['refund'], - 'live_begin' => $itemValue['live'], - 'consult_reply' => '', + 'verify' => $itemValue['verify'] ?? '', + 'order_finish' => $itemValue['order'] ?? '', + 'refund_finish' => $itemValue['refund'] ?? '', + 'live_begin' => $itemValue['live'] ?? '', + 'consult_reply' => $itemValue['consult'] ?? '', ]); $this->getQueryBuilder() - ->update($table) - ->where($where) + ->update('kg_setting') + ->where(['id' => $setting['id']]) ->set('item_value', $newItemValue) ->execute(); } diff --git a/db/migrations/20210228035113_data_202102280351.php b/db/migrations/20210228035113_data_202102280351.php index 3d1a4968..ebb5faab 100644 --- a/db/migrations/20210228035113_data_202102280351.php +++ b/db/migrations/20210228035113_data_202102280351.php @@ -13,27 +13,24 @@ final class Data202102280351 extends AbstractMigration protected function updateSmsNoticeTemplate() { - $table = 'kg_setting'; - - $where = [ - 'section' => 'sms', - 'item_key' => 'template', - ]; - $setting = $this->getQueryBuilder() ->select('*') - ->from($table) - ->where($where) - ->execute() - ->fetch('assoc'); + ->from('kg_setting') + ->where(['section' => 'sms', 'item_key' => 'template']) + ->execute()->fetch('assoc'); + + if (!$setting) return; $itemValue = json_decode($setting['item_value'], true); $newItemValue = []; + /** + * 更改数据结构 + */ foreach ($itemValue as $key => $value) { - $newItemValue[$key]['id'] = $value; - $newItemValue[$key]['enabled'] = 1; + $newItemValue[$key]['id'] = $value['id'] ?? $value; + $newItemValue[$key]['enabled'] = $value['enabled'] ?? 1; } /** @@ -44,35 +41,30 @@ final class Data202102280351 extends AbstractMigration $itemValue = json_encode($newItemValue); $this->getQueryBuilder() - ->update($table) - ->where($where) + ->update('kg_setting') + ->where(['id' => $setting['id']]) ->set('item_value', $itemValue) ->execute(); } protected function updateWechatNoticeTemplate() { - $table = 'kg_setting'; - - $where = [ - 'section' => 'wechat.oa', - 'item_key' => 'notice_template', - ]; - $setting = $this->getQueryBuilder() ->select('*') - ->from($table) - ->where($where) - ->execute() - ->fetch('assoc'); + ->from('kg_setting') + ->where(['section' => 'wechat.oa', 'item_key' => 'notice_template']) + ->execute()->fetch('assoc'); $itemValue = json_decode($setting['item_value'], true); $newItemValue = []; + /** + * 更改数据结构 + */ foreach ($itemValue as $key => $value) { - $newItemValue[$key]['id'] = $value; - $newItemValue[$key]['enabled'] = 1; + $newItemValue[$key]['id'] = $value['id'] ?? $value; + $newItemValue[$key]['enabled'] = $value['enabled'] ?? 1; } /** @@ -83,8 +75,8 @@ final class Data202102280351 extends AbstractMigration $itemValue = json_encode($newItemValue); $this->getQueryBuilder() - ->update($table) - ->where($where) + ->update('kg_setting') + ->where(['id' => $setting['id']]) ->set('item_value', $itemValue) ->execute(); } diff --git a/db/migrations/20210302021013_schema_202103021010.php b/db/migrations/20210302021013_schema_202103021010.php index d9418857..5829d86d 100644 --- a/db/migrations/20210302021013_schema_202103021010.php +++ b/db/migrations/20210302021013_schema_202103021010.php @@ -33,6 +33,12 @@ class Schema202103021010 extends Phinx\Migration\AbstractMigration $table->removeColumn('deleted')->save(); } + $table = $this->table('kg_im_notice'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); + } + $table = $this->table('kg_learning'); if ($table->hasColumn('deleted')) {