Skip to content

Instantly share code, notes, and snippets.

@lazaronixon
Last active July 25, 2025 15:37
Show Gist options
  • Save lazaronixon/21fd84db843b5b6d9f024f62fa843bd8 to your computer and use it in GitHub Desktop.
Save lazaronixon/21fd84db843b5b6d9f024f62fa843bd8 to your computer and use it in GitHub Desktop.
Demote standalone buyers
# Demote standalone buyers
begin
plan = Plan.find_by_plan_code!("change-it")
customer_profiles = CustomerProfile.kept.where(subscription: plan.subscriptions)
customer_profiles.find_each do |customer_profile|
puts "Setting skip_billing_at for customer: #{customer_profile.id}"
# Cleanup skip_billing_at
clients = customer_profile.clients
clients.update_all(skip_billing_at: nil)
# Demote standalone buyers
buyers = customer_profile.standalone_buyers.where.not(lockbox_uid: customer_profile.lockbox_uid)
buyers.update_all(skip_billing_at: Time.current)
# Reprocess index
clients = customer_profile.clients.select(:id)
clients.find_in_batches(batch_size: 500) do |clients|
Search::BulkIndexClientComposite.call(client_ids: clients.pluck(:id))
end
# Enable DBO
customer_profile.enable_unpaid_prospect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment