You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: discourse_merger.rb
    path of file: ./repos/discourse/script/bulk_import
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require_relative "base"

class BulkImport::DiscourseMerger < BulkImport::Base
  NOW ||= "now()"
  CUSTOM_FIELDS = %w[category group post topic user]

  # DB_NAME: name of database being merged into the current local db
  # DB_HOST: hostname of database being merged
  # DB_PASS: password used to access the Discourse database by the postgres user
  # UPLOADS_PATH: absolute path of the directory containing "original"
  #               and "optimized" dirs. e.g. /home/discourse/other-site/public/uploads/default
  # SOURCE_BASE_URL: base url of the site being merged. e.g. https://meta.
    
  def copy_model(
    klass,
    skip_if_merged: false,
    is_a_user_model: false,
    skip_processing: false,
    mapping: nil,
    select_sql: nil
  )
    puts "copying #{klass.table_name}..."

    columns = klass.columns.map(&:name)
    has_custom_fields = CUSTOM_FIELDS.include?(klass.name.downcase)
    imported_ids = []
    last_id = columns.include?("id") ? (klass.unscoped.maximum(:id) || 1) : nil

    sql = "COPY #{klass.table_name} (#{columns.map { |c| "\"#{c}\"" }.join(", ")}) FROM STDIN"
    @raw_connection.copy_data(sql, @encoder) do
      source_raw_connection
        .exec(
          select_sql ||
            "SELECT #{columns.map { |c| "\"#{c}\"" }.join(", ")} FROM #{klass.table_name}",
        )
        .each do |row|
          if row["user_id"]
            old_user_id = row["user_id"].to_i

            next if skip_if_merged && @merged_user_ids.include?(old_user_id)

            if is_a_user_model
              next if old_user_id < 1
              next if user_id_from_imported_id(old_user_id).nil?
              # We import non primary emails as long as they are not already in use as primary
              if klass.table_name == "user_emails" && row["primary"] == "f" &&
                   UserEmail.where(email: row["email"]).first
                next
              end
            end

            if old_user_id >= 1
              row["user_id"] = user_id_from_imported_id(old_user_id)
              if is_a_user_model && row["user_id"].nil?
                raise "user_id nil for user id '#{old_user_id}'"
              end