Skip to content

Instantly share code, notes, and snippets.

View Ch4s3's full-sized avatar

Chase Gilliam Ch4s3

View GitHub Profile
@Ch4s3
Ch4s3 / dump_db_to_json.rb
Last active May 14, 2021 15:17 — forked from brianburridge/gist:8d2755a73dd5b4f0332b
Export local db to JSON and load that dump back to the db later
namespace :json do
desc 'Export all data to JSON files'
task :export => :environment do
Rails.application.eager_load!
ApplicationRecord.descendants.each do |model|
next if model.table_name.nil? || model.table_name == ''
begin
data = model.all
next if data == []