Update only User who are enterprise owner

This commit is contained in:
Gaetan Craig-Riou
2023-11-23 17:00:32 +11:00
committed by Konrad
parent 56b75ad9fb
commit f643ba5074

View File

@@ -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