Skip to content

Instantly share code, notes, and snippets.

@cesartalves
Last active June 22, 2021 21:02
Show Gist options
  • Save cesartalves/3b213c3be3478db269bf387396b709a7 to your computer and use it in GitHub Desktop.
Save cesartalves/3b213c3be3478db269bf387396b709a7 to your computer and use it in GitHub Desktop.
corrected = []
File.open('original.txt', 'r').each_line do |date|
new_date = Time.parse(date, '%Y-%m-%d %H%M%S')
if new_date.month == 6 && new_date.year == 2021
corrected << new_date.next_month.beginning_of_month
next
end
while new_date.past?
next_date += 3.months
end
corrected << new_date
end
File.open('corrected.txt', 'w') do |f|
corrected.each { |date| f.puts date }
end
subs = SolidusSubscriptions::Subscription.joins(:tags).where(tags: { name: 'legacy'}).distinct
subs.each do |sub|
new_date = sub.actionable_date
if new_date.month == 6 && new_date.year == 2021
sub.actionable_date = new_date.next_month.beginning_of_month
sub.save!
next
end
while new_date.past?
new_date += 3.months
end
sub.actionable_date = new_date
sub.save!
end
end
@aamyot
Copy link

aamyot commented Jun 22, 2021

ah!!! I meant notes!

SolidusSubscriptions::Subscription.where.not(notes: nil).

The imported subscriptions will have the id in the notes field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment