Rails:用于查找缺失索引的gem /插件?

时间:2011-08-23 10:57:01

标签: ruby-on-rails

是否有像https://github.com/eladmeidar/rails_indexes这样适用于rails3的gem或插件?

2 个答案:

答案 0 :(得分:23)

有一个rails_indexes的分支已经更新,可以与Rails 3和Ruby 1.9一起使用

https://github.com/plentz/lol_dba

答案 1 :(得分:16)

您可以在控制台中粘贴以下代码,以了解丢失的外键索引。但是,这并不像你所指的插件那样能够。它仅搜索在列名末尾有_id的rails样式外键。

c = ActiveRecord::Base.connection
c.tables.collect do |t|  
  columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id") || x.ends_with?("_type")}
  indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
  unindexed = columns - indexed_columns
  unless unindexed.empty?
    puts "#{t}: #{unindexed.join(", ")}"
  end
end

Source

相关问题