FIX: Vanilla importer fixes (#14699)

FIX: Vanilla importer fixes (#14699)

Import script was out of date

diff --git a/script/bulk_import/vanilla.rb b/script/bulk_import/vanilla.rb
index 92ddf3f..cb85b85 100644
--- a/script/bulk_import/vanilla.rb
+++ b/script/bulk_import/vanilla.rb
@@ -5,6 +5,8 @@ require "mysql2"
 require "rake"
 require "htmlentities"
 
+# NOTE: this importer expects a MySQL DB to directly connect to
+
 class BulkImport::Vanilla < BulkImport::Base
 
   VANILLA_DB = "dbname"
diff --git a/script/import_scripts/vanilla.rb b/script/import_scripts/vanilla.rb
index 08f8ada..1d67cd0 100644
--- a/script/import_scripts/vanilla.rb
+++ b/script/import_scripts/vanilla.rb
@@ -3,6 +3,9 @@
 require "csv"
 require File.expand_path(File.dirname(__FILE__) + "/base.rb")
 
+# NOTE: this importer expects a text file obtained through Vanilla Porter
+# user documentation: https://meta.discourse.org/t/how-to-migrate-import-from-vanilla-to-discourse/27273
+
 class ImportScripts::Vanilla < ImportScripts::Base
 
   def initialize
@@ -199,7 +202,9 @@ class ImportScripts::Vanilla < ImportScripts::Base
       user_emails_in_conversation = @users.select { |u| user_ids_in_conversation.include?(u[:user_id]) }
         .map { |u| u[:email] }
       # retrieve their usernames from the database
-      target_usernames = User.where("email IN (?)", user_emails_in_conversation).pluck(:username).to_a
+      target_usernames = User.joins(:user_emails)
+        .where(user_emails: { email: user_emails_in_conversation })
+        .pluck(:username)
 
       next if target_usernames.blank?
 
@@ -207,7 +212,6 @@ class ImportScripts::Vanilla < ImportScripts::Base
       first_message = @conversation_messages.select { |cm| cm[:message_id] == conversation[:first_message_id] }.first
 
       {
-        archetype: Archetype.private_message,
         id: "conversation#" + conversation[:conversation_id],
         user_id: user.id,
         title: "Private message from #{user.username}",

GitHub sha: 48a08cc397acf3862f4edacdd8a8d05ac8c07881

This commit appears in #14699 which was approved by gschlager. It was merged by gschlager.