美文网首页mysqlphp开发技巧
phplaravel 表迁移并使用mysql分区

phplaravel 表迁移并使用mysql分区

作者: 顶尖少爷 | 来源:发表于2023-09-06 17:25 被阅读0次

直接上代码
我是用command 创建了一张表

<?php

namespace App\Console\Commands\CreateTable;

use App\Modules\Game\Repositories\GameRepository;
use Illuminate\Console\Command;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Brokenice\LaravelMysqlPartition\Models\Partition;
use Brokenice\LaravelMysqlPartition\Schema\Schema;
use Log;
class CreateTabUserPayGameTable extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'migrate:tab_user_pay_game';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '创建游戏的订单详细表(支持按照年分区从2021年开启创建30年)';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(GameRepository $gameRepository)
    {
        //先创建表在创建分区
        //按照创建时间天分区
        //一个表最多只能有 1024 个分区
     
   Schema::create($tableName, function (Blueprint $table) {
                    $table->bigInteger('id');
                    $table->string("pay_order_number",100)->index()->default("")->comment("订单号");
                    $table->dateTime('created_at', 0)->nullable();
                    $table->timestamp('updated_at', 0)->nullable();
                    $table->softDeletes();
                    $table->unique(["pay_order_number","created_at"]);
                    $table->primary(["id","created_at"]);
                });
                //强制id自增
                Schema::forceAutoIncrement($tableName, 'id');
              //按照年和月分区                Schema::partitionByYearsAndMonths($tableName,"created_at",2022,2080);
                Log::Info("创建支付表成功",["tableName"=>$tableName]);
        return Command::SUCCESS;
    }
}

相关文章

  • Mysql 分区表删除

    分区表删除部分分区 使用场景:从 MySQL 5.1 开始,支持分区 创建日志表时建议使用分区方式 在上表的分区表...

  • MySQL分区表

    确认mysql是否支持分区表 mysql分区表的特点 创建mysql数据表为hash表 常用mysql分区的类型 ...

  • 十、MySQL表分区

    MySQL表分区介绍   表分区是将⼀个表的数据按照⼀定的规则⽔平划分为不同的逻辑块,并分别进⾏物理存储,这个规则...

  • PHP面试之分库分表

    [TOC] 真题 简述MySQL分表操作和分区操作的工作原理,分别说说分区和分表的使用场景和各自的优缺点。 分区表...

  • PHP面试之分库分表

    真题 简述MySQL分表操作和分区操作的工作原理,分别说说分区和分表的使用场景和各自的优缺点。 分区表的原理 工作...

  • mysql表分区

    mysql表分区主要分为RANGE分区,LIST分区,HASH分区,LINEAR HASH分区,KEY分区 目前,...

  • 分区表后使用dataX迁移数据问题

    1.新建分区表后使用dataX迁移数据报错 com.alibaba.datax.common.exception....

  • mysql分区表测试

    mysql分区表测试 mysql部署情况 使用docker-compose在10.xx.xx.1机器进行部署, 端...

  • Mysql分区分析

    关于什么是分区和分表,可以先参考下面前两篇文章。 MySQL 分库分表与分区的区别和思考搞懂MySQL分区MySQ...

  • mysql 分区实践之按月份分区,定时增加分区和删除分区

    按月份分区,这样再使用分区字段时间来查询数据将会很快,因为这样只需要扫描指定的分区。 1、创建表,并使用RANGE...

网友评论

    本文标题:phplaravel 表迁移并使用mysql分区

    本文链接:https://www.haomeiwen.com/subject/hnokvdtx.html