Database Snapshots
Database snapshots allow you to save the current state of your database and quickly restore it later. This is invaluable during development when you need to:
- Test data modifications and quickly reset to a known state
- Quickly switch between different test scenarios
- Preserve data before making potentially destructive changes
Creating Snapshots
Section titled “Creating Snapshots”Basic Snapshot Creation
Section titled “Basic Snapshot Creation”Create a snapshot with a descriptive name:
php artisan db:snapshot:create my-snapshot-nameThe snapshot will be saved to the database/snapshots/ directory.
Example Workflow
Section titled “Example Workflow”# Rebuild database with fresh dataphp artisan db:rebuild
# Create some test data through the UI
# Save this statephp artisan db:snapshot:create clean-test-data
# Now you can make changes, and restore whenever neededphp artisan db:snapshot:restore clean-test-dataListing Snapshots
Section titled “Listing Snapshots”View all available snapshots:
php artisan db:snapshot:listRestoring Snapshots
Section titled “Restoring Snapshots”Restore a snapshot by name:
php artisan db:snapshot:restore my-snapshot-nameCreate an automatic backup before restoring:
php artisan db:snapshot:restore my-snapshot-name --backupViewing Snapshot Details
Section titled “Viewing Snapshot Details”Get detailed information about a specific snapshot:
php artisan db:snapshot:info my-snapshot-nameThis displays:
- File path and size
- Creation timestamp
- Schema checksum and migration/seeder counts
- Comparison with current codebase schema
Deleting Snapshots
Section titled “Deleting Snapshots”Delete a single snapshot:
php artisan db:snapshot:delete my-snapshot-nameDelete all snapshots:
php artisan db:snapshot:delete --allBoth the SQL file and any associated metadata will be removed.