Rails
ActiveRecord
Inspect tables and columns en masse
ActiveRecord::Base.connection.tables.flat_map do |table_name|
ActiveRecord::Base.connection.columns(table_name).map do |c|
[table_name, c.name, c.sql_type_metadata.sql_type, c.sql_type_metadata.type]
end
end
Time Query
def time_query(q)
start = Time.now
r = ActiveRecord::Base.connection.execute(q)
puts "Duration: #{Time.now - start}"
return r
end
Fixing backtrace for engines
If the backtrace is getting killed for an engine is getting killed you can add this into an initializer:
Rail.backtrace_cleaner.tap do |cleaner|
cleaner.add_silencer do |line|
(line !~ Rails::BacktraceCleaner::APP_DIRS_PATTERN) &&
(line !~ /registries-api/)
end
cleaner.add_silencer do |l|
l == "app/controllers/application_controller.rb:72:in `set_time_zone'"
end
end
Notice that the code from the engine is being included along with lines that match the app pattern