Module: SearchCraft::DumpSchema

Included in:
Builder
Defined in:
lib/searchcraft/dump_schema.rb

Instance Method Summary collapse

Instance Method Details

#dump_schema!Object

If in Rails, dump schema.rb after rebuilding views



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/searchcraft/dump_schema.rb', line 3

def dump_schema!
  return unless Rails.env.development?
  require "active_record/tasks/database_tasks"

  env = Rails.env
  db_configs = ActiveRecord::Base.configurations.configs_for(env_name: env)
  db_configs.each do |db_config|
    ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config, ActiveRecord.schema_format)
  end
rescue ActiveRecord::NoDatabaseError
rescue => e
  warn "Error dumping schema: #{e.message}"
  pp e.backtrace
end