Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Db Snapshots

Laravel Db Snapshots Laravel Package

spatie/laravel-db-snapshots

Artisan commands to quickly create, load, list, and clean up database snapshots in Laravel. Dump and restore MySQL, PostgreSQL, and SQLite databases with named or latest snapshots—ideal for local/dev workflows and fast resets.

View on GitHub
Deep Wiki
Context7

Quickly dump and load databases

Frequently asked questions about Laravel Db Snapshots
How do I install spatie/laravel-db-snapshots in a Laravel project?
Run `composer require spatie/laravel-db-snapshots` in your project directory. The package auto-registers and adds Artisan commands. No additional setup is needed unless you want to publish the config file with `php artisan vendor:publish --tag=db-snapshots-config`.
Which Laravel and PHP versions does this package support?
The package supports Laravel 10–13 and PHP 8.1+. For older Laravel versions (6.x–9.x), use version 1.x of the package. Always check the [GitHub releases](https://github.com/spatie/laravel-db-snapshots/releases) for the latest compatibility details.
Can I use this package in CI/CD pipelines to reset the database before tests?
Yes. You can automate snapshot creation and loading in CI/CD using Artisan commands. For example, create a snapshot before tests with `php artisan snapshot:create ci_${{ github.sha }}` and load it before each test suite. Combine with Laravel’s `refreshDatabase` for a clean state.
How do I exclude certain tables (e.g., sessions, failed_jobs) from snapshots?
Publish the config file with `php artisan vendor:publish --tag=db-snapshots-config`, then add the table names to the `excluded_tables` array in the `snapshots.php` config. This ensures those tables are skipped during dump and restore operations.
Will this package work with large databases (e.g., >1GB)?
For large databases, use the `--stream` flag with `snapshot:load` to avoid memory issues. The package streams the dump file directly to the database, reducing memory overhead. However, very large databases may still require optimization like excluding non-critical tables.
How do I restore a snapshot to a specific Laravel environment (e.g., staging)?
Ensure the database connection in `.env` matches the target environment (e.g., `DB_CONNECTION=pgsql` for PostgreSQL). Run `php artisan snapshot:load <name>` in the environment where you want to restore the snapshot. For multi-environment setups, use distinct snapshot names (e.g., `staging_2024-05-01`).
Are there any alternatives to spatie/laravel-db-snapshots for Laravel?
Alternatives include `laravel-dump-server` for debugging, `laravel-backup` for full backups, or custom scripts using `Artisan::call('migrate:fresh')` + `Artisan::call('db:seed')`. However, this package is unique for its simplicity, named snapshots, and event-driven extensibility for Laravel-specific workflows.
How do I clean up old snapshots automatically?
Use the `snapshot:cleanup` command with the `--keep` flag to retain only the most recent snapshots. For example, `php artisan snapshot:cleanup --keep=5` keeps the 5 newest snapshots and deletes the rest. Schedule this via Laravel’s task scheduler or cron for automated cleanup.
Can I use this package with SQLite in Laravel?
Yes, the package fully supports SQLite. The commands (`snapshot:create`, `snapshot:load`, etc.) work identically with SQLite databases. Ensure your Laravel `config/database.php` is configured for SQLite before running snapshot commands.
How do I handle schema changes between snapshots (e.g., dropped tables)?
By default, the package drops tables before restoring a snapshot to avoid schema conflicts. To disable this, use the `--drop-tables=0` flag with `snapshot:load`. For complex migrations, consider manually syncing schemas or using Laravel’s `migrate:fresh` before restoring snapshots.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai