-
-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So we can use a straightforward foreign key relationship between the version & deletion
- Loading branch information
Showing
7 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Maintenance::BackfillDeletionVersionsTask < MaintenanceTasks::Task | ||
def collection | ||
Deletion.all | ||
end | ||
|
||
def process(deletion) | ||
return if deletion.version_id? | ||
|
||
deletion.update!(version_id: deletion.version.id) | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddVersionIdToDeletions < ActiveRecord::Migration[7.0] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
add_reference :deletions, :version, index: {algorithm: :concurrently} | ||
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
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
27 changes: 27 additions & 0 deletions
27
test/tasks/maintenance/backfill_deletion_versions_task_test.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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Maintenance::BackfillDeletionVersionsTaskTest < ActiveSupport::TestCase | ||
test "#collection" do | ||
assert_equal Deletion.all, Maintenance::BackfillDeletionVersionsTask.collection | ||
end | ||
|
||
test "#process" do | ||
version = create(:version) | ||
deletion = create(:deletion, version:) | ||
|
||
deletion.update_column(:version_id, nil) | ||
|
||
assert_nil deletion.version_id | ||
|
||
Maintenance::BackfillDeletionVersionsTask.process(deletion) | ||
|
||
assert_equal version.id, deletion.version_id | ||
assert_equal version, deletion.version | ||
|
||
assert_no_changes -> { deletion.reload.as_json } do | ||
Maintenance::BackfillDeletionVersionsTask.process(deletion) | ||
end | ||
end | ||
end |