mckue/laravel-clear-table
最新稳定版本:v1.1.0
Composer 安装命令:
composer require mckue/laravel-clear-table
包简介
Clear log table data through personalized configuration
README 文档
README
通过配置的方式只需要一个命令可以清理不同的数据表
要求
laravel > 5.8
php >= 7.3
安装
composer require mckue/laravel-clear-table
生成配置文件
php artisan vendor:publish --tag=clear-tables
将会生成一个config/clear-tables.php配置文件
编写配置
<?php
return [
//示例
[
//批次处理删除n条数据
'chunk_size'=>2000,
//模型类 或者 表名
'model' => YourModel::class,
//是否优化表
'is_optimized' => true,
//表条件
'conditions' => function ($query) {
$query->where('type', 1);
// 你可以在这里加入任何其他复杂的查询逻辑....
},
//通过时间字段分段删除(这个字段要求为索引类型的时间字段,否则效果适得其反)
'date_column' =>'created_at',
],
];
执行命令 or 定时任务
执行命令会跑配置项的所有的表
php artisan clear-tables
指定表清理
php artisan clear-tables --table=your_table
清理参数
php artisan clear-tables {startDay=40} {endDay=30} {interval=10} {unit=day} {--table=}
startDay=生成时间段的开始天数 当前时间往前推n天
endDay=生成时间段的结束天数 (如果您要保留30天的数据则这个必须>=30天)
interval=时间段间隔
unit=时间段间隔单位
定时任务
//指定表
$schedule->command('clear-table --table=your_table', '* 5 * * *');
//不指定表
$schedule->command('clear-table', '* 5 * * *');
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-15