Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix migration conflict preflight returning no rows on MySQL

Łukasz Adamczykfa336cee169c
diff --git a/spree/core/lib/tasks/migrate_users_to_customers.rake b/spree/core/lib/tasks/migrate_users_to_customers.rake
index ed324a11e6..b0bdfdbdca 100644
--- a/spree/core/lib/tasks/migrate_users_to_customers.rake
+++ b/spree/core/lib/tasks/migrate_users_to_customers.rake
@@ -80,7 +80,9 @@ namespace :spree do
# Compare case-insensitively to match Spree::Customer's uniqueness
# (case_sensitive: false) — emails are stored case-preserved, so a legacy
# `Alice@` conflicting with an existing `alice@` must be caught here too.
- existing_emails = customer_model.where.not(email: [nil, '']).pluck(:email).map(&:downcase).to_set
+ # Blanks are filtered in Ruby: `where.not(email: [nil, ''])` returns no rows
+ # on MySQL (NOT IN with NULL), which would silently drop every conflict.
+ existing_emails = customer_model.pluck(:email).map { |e| e&.downcase.presence }.compact.to_set
conflict_ids = pending.where("email IS NOT NULL AND email <> ''").pluck(:id, :email).
filter_map { |id, email| id if existing_emails.include?(email.downcase) }
invalid_ids = (blank_email_ids + conflict_ids).uniq