[openstreetmap/openstreetmap-website] Note: Add body & author (PR #4481)

Gregory Igelmund notifications at github.com
Wed Feb 7 16:56:20 UTC 2024


@grekko commented on this pull request.



> +  desc "Backfills notes-columns `body`, `author_ip` and `author_id`"
+  task :migrate_notes => :environment do
+    scope = Note.where(:body => nil, :author => nil, :author_ip => nil)
+    total_count = scope.count
+    remaining_count = total_count
+    puts "A total of #{total_count} Note-records have to be migrated."
+
+    # NB: default batch size is 1000
+    scope.find_in_batches do |batch|
+      puts "Processing batch of #{batch.size} records."
+      batch.each do |record|
+        opened_comment = record.comments.unscope(:where => :visible).find_by(:event => "opened")
+        (putc "x" && next) unless opened_comment
+
+        attributes = opened_comment.attributes.slice(*%w[body author_id author_ip]).compact_blank
+        record.update_columns(attributes) # rubocop:disable Rails/SkipsModelValidations

> Situation A is before we do anything - no body, two comments. At the end of the project, we're aiming for situation C.

correct.

Thanks for the test, that made it easy to spot the error 👍🏽 `Note#build_comments_with_extra_open_comment` needs not to check wether the migration was performed – Situation B – but needs to check wether the `open`-comment was removed – Situation C.

See d09085eac27360b8fe5f469028f3d221f444ba3b

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1481800377
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4481/review/1868330904 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240207/65624b85/attachment.htm>


More information about the rails-dev mailing list