migrate数据迁移使用说明 topthink/think-migration

2021-12-08 14:50:00 浏览数 (1)

代码语言:javascript复制
php .think migrate:create DistributeUser
php .think migrate:run
复制代码
代码语言:javascript复制
public function up()
    {
//添加字段
        $sql = "ALTER TABLE `area_code` ADD COLUMN `icon` varchar(255) NOT NULL DEFAULT '' COMMENT '国旗url';";
        $this->execute($sql);
    }

public function up()
    {
        //修改字段
        $sql = "ALTER TABLE `promotion_channel` MODIFY `code` VARCHAR(1000) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '渠道码';";
        $this->execute($sql);
    }

    public function down()
    {
//删除字段
        $sql = "ALTER TABLE `distribute_user` DROP COLUMN  `manager_num`;";

        $this->execute($sql);
    }

public function up()
    {
//插入数据
        $sql = "INSERT INTO `game_other_way` (`gid`, `gameid`, `name_en`, `name_cn`, `gtype`, `unable_bet`, `gcode`, `gsort`, `status`, `rtp`) VALUES ('220', '79', 'Dreams of Macau', '澳门壕梦', 'slot', '1', 'dreams-of-macau', '0', '0', '96.73%');
INSERT INTO `game_other_way` (`gid`, `gameid`, `name_en`, `name_cn`, `gtype`, `unable_bet`, `gcode`, `gsort`, `status`, `rtp`) VALUES ('220', '78', 'Five Numbers Hi Lo', '高低五福', 'table', '1', 'five-num-hi-lo', '0', '0', '98.26%');
";
        $this->execute($sql);
    }

public function up()
    {
        //更新数据
        $sql = "UPDATE `config` SET `name` = 'bind_tel_send_gold' WHERE `title` = '注册FB帐号赠送金币';";
        $this->execute($sql);
    }

public function up()
    {
        //删除数据
        $sql = "DELETE FROM `config_lang` WHERE `title` = '新手体验金';DELETE FROM `config_lang` WHERE `title` = '客服奖励';";
        $this->execute($sql);
    }

    public function change()
    {
        // create the table
        $table = $this->table('users',array('engine'=>'MyISAM'));
        $table->addColumn('username', 'string',array('limit' => 15,'default'=>'','comment'=>'用户名,登陆使用'))
            ->addColumn('password', 'string',array('limit' => 32,'default'=>md5('123456'),'comment'=>'用户密码'))
            ->addColumn('login_status', 'boolean',array('limit' => 1,'default'=>0,'comment'=>'登陆状态'))
            ->addColumn('login_code', 'string',array('limit' => 32,'default'=>0,'comment'=>'排他性登陆标识'))
            ->addColumn('last_login_ip', 'integer',array('limit' => 11,'default'=>0,'comment'=>'最后登录IP'))
            ->addColumn('last_login_time', 'datetime',array('default'=>0,'comment'=>'最后登录时间'))
            ->addColumn('is_delete', 'boolean',array('limit' => 1,'default'=>0,'comment'=>'删除状态,1已删除'))
            ->addIndex(array('username'), array('unique' => true))
            ->create();
    }
复制代码

0 人点赞