A Rails gem that provides Rake tasks to back up and restore your database records across environments.
The gem iterates over all ActiveRecord models in your app, serializes their records to Ruby files, and can replay those files to restore the data. Useful for seeding a staging environment from production data or creating snapshots.
Add this line to your Gemfile:
gem 'database-cloner-rails'Then run:
bundle installDumps all records from every model into individual .rb files under lib/tasks/database_cloner/db_dump/:
rake database:downloadEach file contains Model.create(...) calls — one per record — with id, created_at, and updated_at stripped out.
Replays the dumped files to recreate records in the current database:
rake database:uploadIf a model's dump file fails to load, it prints a warning and continues with the rest.
- Only models that can be resolved via
classify.safe_constantizeare included. - Records are ordered by
idduring the dump. - The
db_dump/directory must exist before runningdatabase:download.