Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfill diff_file_index and diff_line_number columns on table comments #16969

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)