Download the PHP package helgesverre/laravel-prunekeeper without Composer
On this page you can find all versions of the php package helgesverre/laravel-prunekeeper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download helgesverre/laravel-prunekeeper
More information about helgesverre/laravel-prunekeeper
Files in helgesverre/laravel-prunekeeper
Package laravel-prunekeeper
Short Description Archive prunable Eloquent records before deletion
License MIT
Homepage https://github.com/HelgeSverre/laravel-prunekeeper
Informations about the package laravel-prunekeeper
Prunekeeper
Archive prunable Eloquent records before deletion.
Laravel's Prunable trait lets you automatically clean up old database records.
But once they're gone, they're
gone forever.
Prunekeeper hooks into Laravel's pruning process to export records to CSV or SQL before deletion. Archives are compressed and uploaded to any Laravel filesystem disk (S3, local, etc.), giving you a safety net for compliance, auditing, or "just in case."
When you run php artisan model:prune, Prunekeeper automatically:
- Exports matching records to CSV (or SQL)
- Compresses the export (ZIP, gzip, bzip2, or tar.gz)
- Uploads to your configured storage disk
- Allows Laravel to proceed with deletion
Installation
Optionally publish the configuration:
Requirements: PHP 8.2+ and Laravel 11 or 12.
Basic Usage
Add the ArchivePrunedRecords trait to any model that uses Laravel's Prunable or MassPrunable trait:
That's it. When Laravel prunes the model, Prunekeeper archives the records first.
Using with MassPrunable
Works the same way with MassPrunable (bulk deletion without model events):
Configuration
Export Formats
| Format | Description | Best For |
|---|---|---|
| CSV (default) | Portable, database-agnostic | General archiving, analytics, data portability |
| SQL | Database-specific INSERT statements |
Direct database restoration |
SQL exports automatically use the correct identifier quoting for your database:
- MySQL/MariaDB: backticks (
`) - PostgreSQL/SQLite: double quotes (
") - SQL Server: square brackets (
[])
Compression Drivers
Choose from multiple compression formats:
| Driver | Extension | Requirements |
|---|---|---|
zip (default) |
.zip |
ext-zip |
gzip |
.gz |
ext-zlib |
bzip2 |
.bz2 |
ext-bz2 |
targz |
.tar.gz |
ext-phar, ext-zlib, phar.readonly=0 |
Configure in config/prunekeeper.php or via environment:
Artisan Commands
Archive without deleting
Archive records without triggering deletion:
Validate configuration
Validate that column configurations are correct:
Run this in CI/CD to catch configuration errors before deployment.
Customization
Export specific columns
By default, all columns are exported. To limit which columns are archived:
If you specify columns that don't exist, Prunekeeper throws an InvalidColumnException with a helpful message showing
available columns.
Exclude sensitive columns globally
Apply column filtering across all models. Configure Prunekeeper in a service provider's boot method:
Custom filename
Override the default filename pattern globally:
Or per-model:
Lifecycle hooks
Hook into the archiving process:
Events
Prunekeeper dispatches Laravel events for integration with queues, notifications, or monitoring:
| Event | Dispatched When |
|---|---|
ArchiveStarting |
Before archive begins |
ArchiveCompleted |
After successful archive |
ArchiveFailed |
When archive fails |
ArchiveSkipped |
When archive is skipped (disabled, no records, pretend mode) |
Disable archiving conditionally
Disable archiving for specific models or environments:
Model discovery
The prunekeeper:archive and prunekeeper:validate commands auto-discover models using the ArchivePrunedRecords trait.
By default, models are discovered in app/Models and app/. Configure custom paths:
Glob patterns are supported:
| Pattern | Matches |
|---|---|
app/Models |
Standard Laravel location |
app/Domain/*/Models |
app/Domain/Users/Models, app/Domain/Orders/Models, etc. |
app/Modules/**/Models |
Recursively finds all Models directories under app/Modules/ |
You can also specify models directly via the --model option:
Scheduling
Add pruning to your scheduler in routes/console.php:
Or in Laravel 11+ with bootstrap/app.php:
Preview what will be pruned:
Performance
Prunekeeper handles large datasets efficiently:
- Chunked processing: Records are exported in configurable chunks (default: 1000)
- Streamed uploads: Files are streamed to storage, not loaded entirely into memory
- Configurable chunk size: Adjust
PRUNEKEEPER_CHUNK_SIZEbased on your constraints
For very large tables (millions of records):
- Run
prunekeeper:archiveduring off-peak hours - Use a dedicated queue worker for the prune command
- Increase
chunk_sizeif memory allows (improves speed)
Security
When archiving data that may contain sensitive information:
- Use column filtering: Implement
getArchivableColumns()or useresolveColumnsUsing()to exclude sensitive fields - Use secure storage: Configure your storage disk with appropriate access controls and encryption
- Run validation: Use
prunekeeper:validatein CI/CD to catch configuration errors
Testing
Changelog
See CHANGELOG for version history.
Contributing
Contributions are welcome! Please see the repository for guidelines.
Security
If you discover a security vulnerability, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). See LICENSE for details.
All versions of laravel-prunekeeper with dependencies
illuminate/contracts Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/events Version ^11.0|^12.0
illuminate/filesystem Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
league/csv Version ^9.6
spatie/laravel-package-tools Version ^1.16
ext-zip Version *