当前位置:网站首页>Laravel generate sub table script example
Laravel generate sub table script example
2022-07-19 10:08:00 【Brother, your wig】
Ideas :
The single table record is too large, and the query efficiency is low , Consider dividing the table into months , Annual table to save data .
Create table script : ( The following is just an example , Adjust according to actual needs )
<?php
namespace App\Console\Commands\Table;
use Illuminate\Console\Command;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class TableCopy extends Command
{
protected $signature = 'cron:table-copy {table?}';
protected $table_date_format = 'Y';
public function handle()
{
$table_base = $this->argument('table') ?: 'promotion_water';
try {
switch($table_base) {
case 'promotion_water':
$table_name = $table_base.'_'.date($this->table_date_format);
$rt = $this->check_promotion_running_water_table($table_name);
// $rt && $this->info('created table success! table:'.$table_name);
$rt && logger('created table success! table:'.$table_name);
break ;
default:
break ;
}
} catch (\Exception $e) {
logger('TableCreate.error',['table_base'=> $table_base,$e->getMessage()]);
}
}
public function check_promotion_running_water_table($table_name)
{
if(!Schema::hasTable($table_name)) {
Schema::create($table_name, function (Blueprint $table) {
$table->increments('id');
$table->string('serial_number')->index()->comment(' Serial number ');
$table->string('seller_id')->index()->comment(' Channel number ');
$table->string('userno')->index()->comment(' Promoters ID');
$table->string('cardId')->index()->comment(' card ID');
$table->string('proCode')->index()->comment(' Source code ');
$table->string('link')->index()->comment(' Landing page links ');
$table->string('from')->index()->comment(' source ');
$table->string('ip')->index()->comment('IP');
$table->datetime('time')->index()->comment('');
$table->timestamps();
});
if(Schema::hasTable($table_name)) {
return true;
}
}
return false;
}
}
Timing task configuration
//app/Console/Kernel.php
$schedule->command('cron:table-copy')->dailyAt('00:00')->runInBackground();
边栏推荐
猜你喜欢

网络安全学习(千锋网络安全笔记)1--搭建虚拟机

Chapter 4 - consistency of first-order multi-agent systems - > consistency of continuous time systems with time delays

Flink introduction to actual combat - phase IV (time and window diagram)

Experiment 1: camera calibration experiment using Matlab toolbox

喜报

Packet knowledge

Fiddler replay attack, simple simulated replay attack

CLWY权限管理(二)--- 用户模块

喜报

Machine learning basics that can be easily introduced in 5 minutes
随机推荐
【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件
基于AI智能关联技术的5G网络切片研究与实现
自己创建的模块 使用cmd打开报 ModuleNotFoundError: No module named 解决方案
NPM usage
在线教育知识付费网站源码系统+直播+小程序,安装教程
壳聚糖包裹PCN224纳米粒子|金属-有机骨架Fe-MIL-88NH2|镍基MOF材料(Ni-MOF/NF)
[C language] involves constants and variables
软件工程——软科中国大学专业排名
AsyncLocalStorage 的妙用
Pfsense configure tailscal site to site connection
[565. Array nesting]
Huawei ascend910 running yolov3 tutorial
Week 1: introduction to deep learning and foundation of pytorch
【原创】Magisk+Shamiko过APP ROOT检测
PTA 1037 change at Hogwarts
氟改性UiO-66|3,4-二羟基苯甲醛改性UiO-66-NH2|喜树碱衍生物/寡肽@ZIF-8纳米载药体系
fiddler 重放攻击,简单的模拟重放攻击
vim诡异的未知函数0
6G空天地一体化网络高空平台基站下行频谱效率研究
【C语言】浅涉选择、循环语句、函数及数组