I totally agree with .dump instead of generating a json dump. But just for curiosity, I wrote a script to convert all models to json.
Rails.application.eager_load! # To load all models app/models/**/*.rb all_records = ActiveRecord::Base.descendants.map &:all all_records.to_json
But it may take so long to execute in a real environment with many records.
Another way (which I recommend for this case) , since Sqlite3 is just a file, just copy the db/development.sqlite3 file to db/development.sqlite3.backup . When you want to restore it, just copy it back cp -f db/development.sqlite3.backup db/development.sqlite3 . Remember that .dump creates an ASCII text file with inserts and creates statements, you cannot restore it to the database that it extracted, because it will try to duplicate records.
Pablo cantero
source share