DEV: remove duplicate Remap class and use DbHelper.remap instead

DEV: remove duplicate Remap class and use DbHelper.remap instead

Follow-up to 9cd3f96dee96d3fdda99174077fb79c1d6f26ea3

diff --git a/lib/db_helper.rb b/lib/db_helper.rb
index 86a8136..63a8208 100644
--- a/lib/db_helper.rb
+++ b/lib/db_helper.rb
@@ -50,7 +50,7 @@ class DbHelper
       SQL
     end
 
-    SiteSetting.refresh!
+    finish!
   end
 
   def self.regexp_replace(pattern, replacement, flags: "gi", match: "~*", excluded_tables: [])
@@ -82,7 +82,7 @@ class DbHelper
       SQL
     end
 
-    SiteSetting.refresh!
+    finish!
   end
 
   def self.find(needle, anchor_left: false, anchor_right: false, excluded_tables: [])
@@ -108,4 +108,12 @@ class DbHelper
     found
   end
 
+  private
+
+  def self.finish!
+    SiteSetting.refresh!
+    Theme.expire_site_cache!
+    SiteIconManager.ensure_optimized!
+  end
+
 end
diff --git a/lib/remap.rb b/lib/remap.rb
deleted file mode 100644
index b49cd7b..0000000
--- a/lib/remap.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-# frozen_string_literal: true
-
-class Remap
-  def initialize(from, to, regex: false, verbose: false)
-    @from = from
-    @to = to
-    @regex = regex
-    @verbose = verbose
-  end
-
-  def perform
-    sql = "SELECT table_name, column_name
-FROM information_schema.columns
-WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%') and is_updatable = 'YES'"
-
-    cnn = ActiveRecord::Base.connection.raw_connection
-
-    results = cnn.async_exec(sql).to_a
-
-    model_map = {}
-
-    results.each do |result|
-      table_name = result["table_name"]
-      column_name = result["column_name"]
-
-      model = begin
-        model_map[table_name] ||= table_name.camelize.singularize.constantize
-      rescue NameError
-        nil
-      end
-
-      if model &&
-        model.respond_to?(:ignored_columns) &&
-        model.ignored_columns.include?(column_name)
-        next
-      end
-
-      log "Remapping #{table_name} #{column_name}"
-
-      result = if @regex
-        cnn.async_exec("UPDATE #{table_name}
-          SET #{column_name} = regexp_replace(#{column_name}, $1, $2, 'g')
-          WHERE NOT #{column_name} IS NULL
-            AND #{column_name} <> regexp_replace(#{column_name}, $1, $2, 'g')", [@from, @to])
-      else
-        cnn.async_exec("UPDATE #{table_name}
-          SET #{column_name} = replace(#{column_name}, $1, $2)
-          WHERE NOT #{column_name} IS NULL
-            AND #{column_name} <> replace(#{column_name}, $1, $2)", [@from, @to])
-      end
-
-      log "#{result.cmd_tuples} rows affected!" if result.cmd_tuples > 0
-    end
-
-    Theme.expire_site_cache!
-    SiteIconManager.ensure_optimized!
-  end
-
-  def log(message)
-    puts(message) if @verbose
-  end
-end
diff --git a/script/discourse b/script/discourse
index 003080c..cacd552 100755
--- a/script/discourse
+++ b/script/discourse
@@ -31,7 +31,7 @@ class DiscourseCLI < Thor
   option :regex, type: :boolean
   def remap(from, to)
     load_rails
-    require 'remap'
+    require 'db_helper'
 
     if options[:regex]
       puts "Rewriting all occurences of #{from} to #{to} using regexp_replace"
@@ -269,7 +269,7 @@ class DiscourseCLI < Thor
 
   def do_remap(from, to, regex = false)
     begin
-      Remap.new(from, to, regex: regex, verbose: true).perform
+      regex ? DbHelper.regexp_replace(from, to) : DbHelper.remap(from, to)
       puts 'Done', ''
     rescue => ex
       puts "Error: #{ex}"

GitHub sha: 89fce2ce