We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 83f5699 + c729d0a commit 1f8a900Copy full SHA for 1f8a900
1 file changed
lib/tasks/item_tags.rake
@@ -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
14
15
16
+ puts "Done."
17
18
+end
0 commit comments