module DBNuker

Constants

VERSION

Public Class Methods

boom!() click to toggle source
# File lib/db_nuker.rb, line 4
def self.boom!
  query = tables_to_delete.map do |table|
    "DELETE FROM #{table};"
  end.join("")

  execute query if query.size > 0
end
connection() click to toggle source
# File lib/db_nuker.rb, line 12
def self.connection
  ActiveRecord::Base.connection
end
db_name() click to toggle source
# File lib/db_nuker.rb, line 29
def self.db_name
  @db_name ||= connection.instance_variable_get('@config')[:database]
end
execute(query) click to toggle source
# File lib/db_nuker.rb, line 16
def self.execute(query)
  connection.execute query
end
tables_to_delete() click to toggle source
# File lib/db_nuker.rb, line 20
def self.tables_to_delete
  result = execute("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{db_name}' AND table_rows > 0")
  result.map{ |row| row[0] } - tables_to_skip
end
tables_to_skip() click to toggle source
# File lib/db_nuker.rb, line 25
def self.tables_to_skip
  @tables_to_skip ||= %w{ schema_migrations sessions }
end