Download the PHP package nexusbrother/laravel-archivable without Composer
On this page you can find all versions of the php package nexusbrother/laravel-archivable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download nexusbrother/laravel-archivable
More information about nexusbrother/laravel-archivable
Files in nexusbrother/laravel-archivable
Download nexusbrother/laravel-archivable
More information about nexusbrother/laravel-archivable
Files in nexusbrother/laravel-archivable
Vendor nexusbrother
Package laravel-archivable
Short Description This is laravel extension packages
License MIT
Homepage https://github.com/nexusbrother/laravel-archivable
Package laravel-archivable
Short Description This is laravel extension packages
License MIT
Homepage https://github.com/nexusbrother/laravel-archivable
Please rate this library. Is it a good library?
Informations about the package laravel-archivable
Laravel Archivable
Laravel Archivable 是一个数据库记录归档扩展包,能够将过期记录从主库自动迁移到独立的归档数据库,同时保持表结构同步。
功能特性
- 📦 将模型记录归档到独立的归档数据库
- 🔄 自动同步主库与归档库之间的表结构(新增/修改字段、索引)
- 📅 支持基于日期字段的自动归档(
DateFieldArchivable) - 🗓️ 支持按月自动分表归档(
MonthlyArchivable) - ⚡ 批量归档,可配置 chunk 大小,支持外键约束自动处理
- 📊 命令行归档时显示实时进度条
- 🔔 归档完成触发
ModelsArchived事件,方便自定义后续逻辑 - ⏰ 内置定时任务调度,可配置执行时间
安装
发布配置文件:
配置
1. 数据库连接
在 config/database.php 的 connections 中添加 archive 连接:
2. 环境变量
3. 配置项
config/archive.php:
使用方法
1. 基于日期字段归档(DateFieldArchivable)
适合按时间归档的场景,所有记录归档到同一张目标表:
2. 按月分表归档(MonthlyArchivable)
适合日志、消息等按月分区的数据,每个月的记录归档到独立的月表(如 logs_202501、logs_202502):
3. 自定义归档条件(Archivable)
完全自定义归档逻辑:
命令行
表结构同步
归档前先同步表结构,确保归档表存在且字段一致:
数据归档
执行时会显示实时进度条:
编程方式使用
事件
归档完成后触发 ModelsArchived 事件:
定时任务
包内置两个定时任务,在 config('archive.enable') 为 true 时自动注册:
| 任务 | 默认时间 | 说明 |
|---|---|---|
model:archive-structure-sync |
09:00 | 同步所有 Archivable 模型的归档表结构 |
model:archive |
09:10 | 执行数据归档 |
两个任务均配置了
onOneServer()和withoutOverlapping(),适合多服务器部署。
系统要求
- PHP >= 8.1
- Laravel 9 / 10 / 11
许可证
MIT License
All versions of laravel-archivable with dependencies
PHP Build Version
Package Version
The package nexusbrother/laravel-archivable contains the following files
Loading the files please wait ...