From f643ba50746c9d406de2a921eae3cd27466bbd06 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Thu, 23 Nov 2023 17:00:32 +1100 Subject: [PATCH] Update only User who are enterprise owner --- ...d_terms_of_service_accepted_at_to_spree_users.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/db/migrate/20231103061213_add_terms_of_service_accepted_at_to_spree_users.rb b/db/migrate/20231103061213_add_terms_of_service_accepted_at_to_spree_users.rb index b7b357adcd..ead6faa159 100644 --- a/db/migrate/20231103061213_add_terms_of_service_accepted_at_to_spree_users.rb +++ b/db/migrate/20231103061213_add_terms_of_service_accepted_at_to_spree_users.rb @@ -3,7 +3,18 @@ class AddTermsOfServiceAcceptedAtToSpreeUsers < ActiveRecord::Migration[7.0] add_column :spree_users, :terms_of_service_accepted_at, :datetime if Spree::Config.enterprises_require_tos == true - Spree::User.update_all(terms_of_service_accepted_at: Time.zone.now) + # Update only user who are owners of at least 1 enterprise + ActiveRecord::Base.sanitize_sql([" + UPDATE spree_users + SET terms_of_service_accepted_at = :time + WHERE spree_users.id IN( + SELECT id FROM spree_users WHERE EXISTS ( + SELECT 1 FROM enterprises WHERE spree_users.id = enterprises.owner_id + ) + )".squish, + time: Time.zone.now + ]) + ActiveRecord::Base.connection.execute(sql) end end