Skip to content

Commit

Permalink
Autosave repository_object_versions when repository_object is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Jun 11, 2024
1 parent 6213286 commit 57e665a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/repository_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RepositoryObject < ApplicationRecord
class VersionAlreadyOpened < StandardError; end
class VersionNotOpened < StandardError; end

has_many :versions, -> { order(version: :asc) }, class_name: 'RepositoryObjectVersion', dependent: :destroy, inverse_of: 'repository_object'
has_many :versions, -> { order(version: :asc) }, class_name: 'RepositoryObjectVersion', dependent: :destroy, inverse_of: 'repository_object', autosave: true
has_many :user_versions, through: :versions

belongs_to :head_version, class_name: 'RepositoryObjectVersion', optional: true
Expand Down
2 changes: 2 additions & 0 deletions bin/migrate-cocina
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def perform_migrate(migrator_class:, obj:, mode:)
current_object_version = obj.head_version.version
obj = open_version(cocina_object: obj, version_description: migrator.version_description, mode:) if migrator.version?

# For active record migrations, we need to wrap the migration in a transaction and save the object instead of
# opening/closing versions
if mode == :commit
obj.transaction do
migrator.migrate
Expand Down

0 comments on commit 57e665a

Please sign in to comment.