{"id":34016747,"url":"https://github.com/ringlesoft/db-archive","last_synced_at":"2026-04-09T04:31:44.943Z","repository":{"id":281370564,"uuid":"942263587","full_name":"ringlesoft/db-archive","owner":"ringlesoft","description":"Laravel Package for Archiving old database entries","archived":false,"fork":false,"pushed_at":"2025-07-15T01:37:10.000Z","size":180,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-03-11T03:47:07.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ringlesoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-03T20:47:14.000Z","updated_at":"2026-02-12T07:17:03.000Z","dependencies_parsed_at":"2025-07-15T03:26:49.075Z","dependency_job_id":"390fde61-58e2-4c81-9ee0-9086ee25b5b8","html_url":"https://github.com/ringlesoft/db-archive","commit_stats":null,"previous_names":["ringlesoft/db-archive"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ringlesoft/db-archive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringlesoft%2Fdb-archive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringlesoft%2Fdb-archive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringlesoft%2Fdb-archive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringlesoft%2Fdb-archive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ringlesoft","download_url":"https://codeload.github.com/ringlesoft/db-archive/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringlesoft%2Fdb-archive/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31586403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-13T14:05:17.832Z","updated_at":"2026-04-09T04:31:44.924Z","avatar_url":"https://github.com/ringlesoft.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/ringunger","https://github.com/sponsors/ringlesoft"],"categories":[],"sub_categories":[],"readme":"# Laravel DB Archive\n\nEasily archive your Laravel database tables periodically to keep your application database lean and performant.\n***\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/ringlesoft/db-archive.svg)](https://packagist.org/packages/ringlesoft/db-archive)\n[![Total Downloads](https://img.shields.io/packagist/dt/ringlesoft/db-archive.svg)](https://packagist.org/packages/ringlesoft/db-archive)\n[![PHP Version Require](https://poser.pugx.org/ringlesoft/db-archive/require/php)](https://packagist.org/ringlesoft/db-archive)\n[![Dependents](https://poser.pugx.org/ringlesoft/db-archive/dependents)](https://packagist.org/packages/ringlesoft/db-archive)\n***\n## Introduction\n\n`Laravel DB Archive` is a package that provides a simple and efficient way to archive old records from your database tables in Laravel applications.  It helps maintain your application's database performance by moving historical data to archive tables, while keeping your primary tables focused on recent and relevant information.\n\n\u003e Laravel 10.x and above\n\n## Installation\nYou can install the package via composer:\n\n```bash\ncomposer require ringlesoft/db-archive\n```\n\n## Configuration\nPublish the configuration file with:\n\n```bash\nphp artisan vendor:publish --provider=\"RingleSoft\\DbArchive\\DbArchiveServiceProvider\" --tag=\"config\"\n```\n\n### Configuration Options:\n#### `connection`:\n- The database connection name to be used for creating archive tables and moving data.\n- Ensure this connection is defined in your `config/database.php` file.\n- I recommend using a different connection from your application's default connection.\n- Defaults to `mysql_archive` and can be overridden using the `ARCHIVE_DB_CONNECTION` environment variable.\n\n#### `settings`:\n- `table_prefix`:\n  - Prefix to be added to the archived tables (e.g., archive_).\n  - Set to `null` for no prefix.\n\n- `batch_size`:\n  - Number of records to process in each batch during archiving.\n  - Adjust this value based on your server resources and table size.\n  - Defaults to 1000.\n\n- `date_column`:\n    - The database column used to determine the age of records for archiving (e.g., `created_at`, `updated_at`).\n    - Defaults to `created_at`.\n  \n- `archive_older_than_days`:\n  - Number of days after which records are considered old enough to be archived.\n  - Records with a date in the `date_column` older than this value will be archived.\n  - Defaults to `365` days .\n\n- `conditions`:\n  - An array of additional where conditions to filter records for archiving.\n  - Allows for more specific criteria for selecting records to archive.\n  - Defaults to an empty array `[]`.\n  - Example: `[['status', 'active']]` or `[['id', '\u003c=', 100]]`\n\n#### `enable_logging`:\n- Boolean value to enable or disable logging of the archiving process.\n- Logs are stored in the default Laravel log file.\n- Defaults to true.\n\n#### `notifications`:\n- `email`:\n  - Email address to receive notifications about the archiving process (success or failure).\n  - Set to null to disable email notifications.\n  - Defaults to `admin@example.com`.\n  - This only works if batching is enabled (for now).\n  \n#### `tables`:\n- An array defining the tables to be archived.\n- User plain table names array for default settings or associative array for specific settings.\n\n## Setting Up\nTo setup the package, run the following command:\n```bash\nphp artisan db-archive:setup\n```\nThis will create the backup database and tables if not already present.\n\n\n## Queueing and Batching\n- This package supports job queuing and job batches. \n- To use jobs and batches, make sure you have both jobs and batches enabled in your application.\n\n### Jobs Table\n```bash\nphp artisan queue:table\nphp artisan migrate\n```\n\n### Batches table\n```bash\nphp artisan queue:batches-table\nphp artisan migrate\n```\n\n\n## Usage\n### Artisan Command\nRun the archive command to process tables defined in your configuration:\n```bash\nphp artisan db-archive:archive\n```\nThis command will:\n- **Check Configuration**: Load the `db-archive.php` configuration file.\n- **Process Tables**: Iterate through the tables defined in the tables array.\n- **Archive Records**: Move records from the original table to the archive table based on the configured settings (age, conditions, etc.).\n- **Logging and Notifications**: Log the archiving process and send notifications if enabled.\n\n### Scheduling\nTo automate the archiving process, schedule the `db-archive:archive` command in your `Kernel.php` file:\n\n\u003e// app/Console/Kernel.php\n\n```php\nprotected function schedule(Schedule $schedule)\n{\n    $schedule-\u003ecommand('db-archive:archive')-\u003edailyAt('01:00'); // Run daily at 1:00 AM\n}\n\n```\nAdjust the scheduling as per your requirements (e.g., daily, weekly, monthly).\n    \n## Examples\n\n### Basic Usage \n(Archive orders table with default settings)\n\u003e // config/db-archive.php\n\n```php\n'connection' =\u003e 'mysql_archive',\n...\n'tables' =\u003e [\n    'orders',\n    'comments'\n],\n```\nThis configuration will archive records from the `users` table in your default connection that are older than 365 days (based on the `created_at` column) to `users` table in the `mysql_archive` connection.\n\n### Custom Settings\n\n\u003e // config/db-archive.php\n\n```php\n'connection' =\u003e 'mysql_archive',\n...\n'tables' =\u003e [\n    'orders' =\u003e [\n        'archive_older_than_days' =\u003e 90, // Archive orders older than 90 days\n        'date_column' =\u003e 'order_date',   // Use 'order_date' column for age check\n        'batch_size' =\u003e 5000,            // Process in batches of 5000\n        'conditions' =\u003e [                 // Additional conditions\n            ['status', '=', 'completed'],\n        ],\n    ],\n];\n```\nThis configuration will archive records from the `orders` table that are older than `90` days (based on the `order_date` column), processed in batches of `5000`, and only for orders with a `status` of '`completed`'.\n\nEnjoy!\n *** \n\n## Contributing\nContributions are welcome! Please feel free to submit pull requests or open issues to suggest improvements or report bugs.\n\n## License\nThe Laravel DB Archive package is open-sourced software licensed under the MIT license.\n\n\n## Support\n- [Buy me a Coffee](https://www.buymeacoffee.com/ringunger)\n- [Github Sponsors](https://github.com/sponsors/ringlesoft)\n\n## Contacts\n\nFollow me on \u003ca href=\"https://x.com/ringunger\"\u003eX\u003c/a\u003e: \u003ca href=\"https://x.com/ringunger\"\u003e@ringunger\u003c/a\u003e\u003cbr\u003e\nEmail me: \u003ca href=\"mailto:ringunger@gmail.com\"\u003eringunger@gmail.com\u003c/a\u003e\u003cbr\u003e\nWebsite: [https://ringlesoft.com](https://ringlesoft.com/packages/db-archive)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringlesoft%2Fdb-archive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fringlesoft%2Fdb-archive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringlesoft%2Fdb-archive/lists"}