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