Skip to content

Commit

Permalink
Merge 9140ef7 into 40ca4c3
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Feb 7, 2020
2 parents 40ca4c3 + 9140ef7 commit 0e24b93
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/complete_moab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CompleteMoab < ApplicationRecord

belongs_to :preserved_object, inverse_of: :complete_moabs
belongs_to :moab_storage_root, inverse_of: :complete_moabs
belongs_to :from_moab_storage_root, class_name: 'MoabStorageRoot', required: false

has_many :zipped_moab_versions, dependent: :restrict_with_exception, inverse_of: :complete_moab

delegate :s3_key, to: :druid_version_zip
Expand Down
1 change: 1 addition & 0 deletions app/models/moab_storage_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Metadata about a Moab storage root (a POSIX file system which contains Moab objects).
class MoabStorageRoot < ApplicationRecord
has_many :complete_moabs, dependent: :restrict_with_exception
has_many :migrated_moabs, class_name: 'CompleteMoab', foreign_key: :from_moab_storage_root_id
has_many :preserved_objects, through: :complete_moabs
has_and_belongs_to_many :preservation_policies

Expand Down
1 change: 1 addition & 0 deletions app/services/storage_root_migration_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def to_root
end

def migrate_moab(moab)
moab.from_moab_storage_root = from_root
moab.moab_storage_root = to_root
moab.status = 'validity_unknown' # This will queue a CV.
# Fate of this to be determined by https://github.com/sul-dlss/preservation_catalog/issues/1329
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddFromMoabStorageRootToCompleteMoabs < ActiveRecord::Migration[6.0]
def change
add_column :complete_moabs, :from_moab_storage_root_id, :bigint
add_foreign_key :complete_moabs, :moab_storage_roots, column: :from_moab_storage_root_id
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_01_22_001712) do
ActiveRecord::Schema.define(version: 2020_02_06_163659) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -28,6 +28,7 @@
t.datetime "last_version_audit"
t.datetime "last_archive_audit"
t.string "status_details"
t.bigint "from_moab_storage_root_id"
t.index ["created_at"], name: "index_complete_moabs_on_created_at"
t.index ["last_archive_audit"], name: "index_complete_moabs_on_last_archive_audit"
t.index ["last_checksum_validation"], name: "index_complete_moabs_on_last_checksum_validation"
Expand Down Expand Up @@ -118,6 +119,7 @@
end

add_foreign_key "complete_moabs", "moab_storage_roots"
add_foreign_key "complete_moabs", "moab_storage_roots", column: "from_moab_storage_root_id"
add_foreign_key "complete_moabs", "preserved_objects"
add_foreign_key "moab_storage_roots_preservation_policies", "moab_storage_roots"
add_foreign_key "moab_storage_roots_preservation_policies", "preservation_policies"
Expand Down
5 changes: 5 additions & 0 deletions spec/services/storage_root_migration_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

let(:complete_moab3) { create(:complete_moab) }

# rubocop:disable RSpec/MultipleExpectations
it 'migrates the storage root' do
# Before migration
expect(complete_moab1.moab_storage_root).to eq(complete_moab2.moab_storage_root)
Expand All @@ -30,8 +31,11 @@
complete_moab2.reload

expect(complete_moab1.moab_storage_root).to eq(to_storage_root)
expect(complete_moab1.from_moab_storage_root).to eq(from_storage_root)
expect(complete_moab2.moab_storage_root).to eq(to_storage_root)
expect(complete_moab2.from_moab_storage_root).to eq(from_storage_root)
end
# rubocop:enable RSpec/MultipleExpectations

it 'resets field values' do
described_class.new(from_storage_root.name, to_storage_root.name).migrate
Expand All @@ -53,5 +57,6 @@
complete_moab3.reload

expect(complete_moab3.moab_storage_root).to eq(orig_complete_moab3_storage_root)
expect(complete_moab3.from_moab_storage_root).to be_nil
end
end

0 comments on commit 0e24b93

Please sign in to comment.