mvf-tech/db-data-eraser
Composer 安装命令:
composer require mvf-tech/db-data-eraser
包简介
Truncates rows of data from a database after 30 days.
README 文档
README
A package used to truncate rows of data from a database after 30 days.
Releases
0.0.3- use this version for PHP 5.
Installation and Setup
Run
composer require mvf-tech/db-data-eraserusing the preferred versions above to install the package.You will need to use a config file to store the db connection details and table information for the package to use, e.g:
return [
'connection' => [
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' =>'password',
],
'tables' => [
[
'name' => 'table_name_one', // name of table containing the rows to delete
'datetime_column' => 'created_at', // name of column in the table that contains the datetime
'max_age' => '-30 days', // the max age at which we want the data to be deleted
'date_format' => 'Y-m-d H:i:s', // (optional) the default value is 'Y-m-d H:i:s'
'limit' => 1000, // (optional) the default value is 1000
'order_by' => 'created_at', // (optional) the default value is what is entered for the 'datetime_column'
],
[
'name' => 'table_name_two',
'datetime_column' => 'created_at',
'max_age' => '-30 days',
],
],
];
Basic Use
use MVF\DataEraser\DataEraser;
$dbEraser = new DataEraser($config); // use the config file you created above
Create a new "DataEraser" instance. This connects to the database using the connection details defined in the config file.
$dbEraser->run();
Then you can use the run() function which will go through the tables listed in the config file and erase rows that are older than the max_age specified.
$dbEraser->getResultsArray();
For logging purposes there is a $results array which can be accessed via the getResultsArray() function.
$resultsArray = [
'log_messages' => [
'success' => true
],
'eagle_queue' => [
'success' => true
],
'lead_duplicate' => [
'success' => false
]
];
After running $dbEraser->run(), this will return an array of results containing the table name, and a success code of 1 for true if the erasure was successful and 0 for false is the erasure was unsuccessful.
In version 1.0.6 logging was added to capture any rows that contain NULL timestamps:
$dbEraser->getRowsWithNullTimestampArray();
After running $dbEraser->run(), this function will return an array containing the table name and the total number of rows which contain a NULL timestamp (if any).
$rowsWithNullTimestamps = [
'log_messages' => [
'number_of_rows_with_null_timestamps' => 1
],
'eagle_queue' => [
'number_of_rows_with_null_timestamps' => 3
],
];
mvf-tech/db-data-eraser 适用场景与选型建议
mvf-tech/db-data-eraser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.63k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mvf-tech/db-data-eraser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mvf-tech/db-data-eraser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-05