-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backfill diff_file_index and diff_line_number columns...
... on table comments
- Loading branch information
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/api/db/data/20241017123303_backfill_diff_fields_on_comments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DataMigrate::Data.define(version: 20240814142031) | ||
DataMigrate::Data.define(version: 20241017123303) |