Skip to content

Commit 1f8a900

Browse files
committed
Merge add_value_to_item_tag_position_rake_task into phase1-rails-api
2 parents 83f5699 + c729d0a commit 1f8a900

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/tasks/item_tags.rake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace :item_tags do
2+
desc "Backfill position for existing item_tags grouped by shop, ordered by created_at"
3+
task backfill_position: :environment do
4+
ActsAsTenant.without_tenant do
5+
Shop.find_each do |shop|
6+
next_position = (shop.item_tags.maximum(:position) || 0) + 1
7+
8+
shop.item_tags.where(position: nil).order(:created_at, :id).each do |item_tag|
9+
item_tag.update_columns(position: next_position)
10+
puts "Shop #{shop.id} - ItemTag #{item_tag.id}: position=#{next_position}"
11+
next_position += 1
12+
end
13+
end
14+
end
15+
16+
puts "Done."
17+
end
18+
end

0 commit comments

Comments
 (0)