mirror of
https://github.com/discourse/discourse.git
synced 2025-03-04 02:04:10 +08:00
FIX: add back verbose option to DbHelper.remap
This commit is contained in:
parent
d1434b6600
commit
19dda59932
@ -19,7 +19,7 @@ class DbHelper
|
|||||||
WHERE trigger_name LIKE '%_readonly'
|
WHERE trigger_name LIKE '%_readonly'
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
def self.remap(from, to, anchor_left: false, anchor_right: false, excluded_tables: [])
|
def self.remap(from, to, anchor_left: false, anchor_right: false, excluded_tables: [], verbose: false)
|
||||||
like = "#{anchor_left ? '' : "%"}#{from}#{anchor_right ? '' : "%"}"
|
like = "#{anchor_left ? '' : "%"}#{from}#{anchor_right ? '' : "%"}"
|
||||||
|
|
||||||
triggers = DB.query(TRIGGERS_SQL).map(&:trigger_name).to_set
|
triggers = DB.query(TRIGGERS_SQL).map(&:trigger_name).to_set
|
||||||
@ -43,17 +43,19 @@ class DbHelper
|
|||||||
"#{column} IS NOT NULL AND #{column} LIKE :like"
|
"#{column} IS NOT NULL AND #{column} LIKE :like"
|
||||||
end.join(" OR ")
|
end.join(" OR ")
|
||||||
|
|
||||||
DB.exec(<<~SQL, from: from, to: to, like: like)
|
rows = DB.exec(<<~SQL, from: from, to: to, like: like)
|
||||||
UPDATE #{table}
|
UPDATE #{table}
|
||||||
SET #{set}
|
SET #{set}
|
||||||
WHERE #{where}
|
WHERE #{where}
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
puts "#{table}=#{rows}" if verbose && rows > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
finish!
|
finish!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.regexp_replace(pattern, replacement, flags: "gi", match: "~*", excluded_tables: [])
|
def self.regexp_replace(pattern, replacement, flags: "gi", match: "~*", excluded_tables: [], verbose: false)
|
||||||
triggers = DB.query(TRIGGERS_SQL).map(&:trigger_name).to_set
|
triggers = DB.query(TRIGGERS_SQL).map(&:trigger_name).to_set
|
||||||
|
|
||||||
text_columns = Hash.new { |h, k| h[k] = [] }
|
text_columns = Hash.new { |h, k| h[k] = [] }
|
||||||
@ -75,11 +77,13 @@ class DbHelper
|
|||||||
"#{column} IS NOT NULL AND #{column} #{match} :pattern"
|
"#{column} IS NOT NULL AND #{column} #{match} :pattern"
|
||||||
end.join(" OR ")
|
end.join(" OR ")
|
||||||
|
|
||||||
DB.exec(<<~SQL, pattern: pattern, replacement: replacement, flags: flags, match: match)
|
rows = DB.exec(<<~SQL, pattern: pattern, replacement: replacement, flags: flags, match: match)
|
||||||
UPDATE #{table}
|
UPDATE #{table}
|
||||||
SET #{set}
|
SET #{set}
|
||||||
WHERE #{where}
|
WHERE #{where}
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
puts "#{table}=#{rows}" if verbose && rows > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
finish!
|
finish!
|
||||||
|
@ -269,7 +269,7 @@ class DiscourseCLI < Thor
|
|||||||
|
|
||||||
def do_remap(from, to, regex = false)
|
def do_remap(from, to, regex = false)
|
||||||
begin
|
begin
|
||||||
regex ? DbHelper.regexp_replace(from, to) : DbHelper.remap(from, to)
|
regex ? DbHelper.regexp_replace(from, to, verbose: true) : DbHelper.remap(from, to, verbose: true)
|
||||||
puts 'Done', ''
|
puts 'Done', ''
|
||||||
rescue => ex
|
rescue => ex
|
||||||
puts "Error: #{ex}"
|
puts "Error: #{ex}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user