mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 11:44:00 +08:00
Add DbHelper.find(needle)
* searches the entire database for a text string (such as an old CDN name)
This commit is contained in:
parent
620a1524cb
commit
8d57c712c3
|
@ -22,4 +22,21 @@ class DbHelper
|
|||
SiteSetting.refresh!
|
||||
end
|
||||
|
||||
def self.find(needle)
|
||||
connection = ActiveRecord::Base.connection.raw_connection
|
||||
text_columns = connection.async_exec(REMAP_SQL).to_a
|
||||
args = ["%#{needle}%"]
|
||||
found = {}
|
||||
|
||||
text_columns.each do |rc|
|
||||
table_name = rc["table_name"]
|
||||
column_name = rc["column_name"]
|
||||
result = connection.async_exec("SELECT #{column_name} FROM #{table_name} WHERE #{column_name} LIKE $1", args) rescue nil
|
||||
if result&.ntuples > 0
|
||||
found["#{column_name}.#{table_name}"] = result.map {|r| r[column_name]}
|
||||
end
|
||||
end
|
||||
found
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user