QuestionController.class.php 1.09 KB
<?php
/**
 * Created by PhpStorm.
 * User: heyuelong
 * Date:2017年12月23日14:23:56
 */

namespace Frontend\Controller\UpdateDB;

class QuestionController extends AbstractController
{
    /**
     * V2.0迭代新增置顶字段
     * @author heyuelong
     * @date 2017年12月23日14:23:49
     */
    public function Index()
    {
        $sql = $this->_updateSql();
        if (empty($sql)) {
            exit('没有可升级的sql');
        }

        $db = \Think\Db::getInstance();
        try {
            $db->execute($sql);
        } catch (\Exception $e) {
            exit("数据库升级失败:" . $e->getMessage());
        }

        exit('数据库升级完成');
    }

    /**
     * 待升级的sql
     *      1、oa_answer_question新增置顶时间,根据置顶时间展示倒序;
     * @return string
     */
    private function _updateSql()
    {
        $alterSql = "
            ALTER TABLE `oa_answer_question` ADD `top_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '置顶时间(根据置顶时间倒序)' AFTER `check_status`;
        ";

        return $alterSql;
    }
}