mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-23 22:12:30 -05:00
189cb3ff12
- new hidden site setting 'migrate_to_new_scheme' (defaults to false) - new rake tasks to toggle migration to new scheme - FIX: migrate_to_new_scheme also works with CDN - PERF: improve perf of the DbHelper.remap method - REFACTOR: UrlHelper is now a class
23 lines
741 B
Ruby
23 lines
741 B
Ruby
class DbHelper
|
|
|
|
REMAP_SQL ||= "
|
|
SELECT table_name, column_name
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'public'
|
|
AND is_updatable = 'YES'
|
|
AND (data_type LIKE 'char%' OR data_type LIKE 'text%')
|
|
ORDER BY table_name, column_name"
|
|
|
|
def self.remap(from, to)
|
|
connection = ActiveRecord::Base.connection.raw_connection
|
|
remappable_columns = connection.async_exec(REMAP_SQL).to_a
|
|
args = [from, to, "%#{from}%"]
|
|
|
|
remappable_columns.each do |rc|
|
|
table_name = rc["table_name"]
|
|
column_name = rc["column_name"]
|
|
connection.async_exec("UPDATE #{table_name} SET #{column_name} = REPLACE(#{column_name}, $1, $2) WHERE #{column_name} LIKE $3", args) rescue nil
|
|
end
|
|
end
|
|
|
|
end
|