Skip to content

Commit

Permalink
Backfill diff_file_index and diff_line_number columns...
Browse files Browse the repository at this point in the history
... on table comments
  • Loading branch information
eduardoj committed Oct 18, 2024
1 parent 817bf1f commit fd1cc2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/api/db/data/20241017123303_backfill_diff_fields_on_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class BackfillDiffFieldsOnComments < ActiveRecord::Migration[7.0]
def up
Comment.where.not(diff_ref: nil).where(diff_file_index: nil).in_batches do |batch|
batch.find_each do |comment|
diff_file_index, diff_line_number = comment.diff_ref.match(/diff_([0-9]+)_n([0-9]+)/).captures

comment.update!(diff_file_index:, diff_line_number:)
end
end
end

def down
Comment.where.not(diff_file_index: nil).in_batches do |batch|
batch.find_each do |comment|
comment.update!(diff_file_index: nil, diff_line_number: nil)
end
end
end
end
2 changes: 1 addition & 1 deletion src/api/db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DataMigrate::Data.define(version: 20240814142031)
DataMigrate::Data.define(version: 20241017123303)

0 comments on commit fd1cc2d

Please sign in to comment.