Skip to content

add rake task to update morpheus models #2198

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

Merged
merged 6 commits into from
Jun 5, 2025
Merged
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
33 changes: 33 additions & 0 deletions lib/tasks/seek_upgrades.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ namespace :seek do
# these are the tasks required for this version upgrade
task upgrade_version_tasks: %i[
environment
db:seed:003_model_formats
db:seed:004_model_recommended_environments
db:seed:007_sample_attribute_types
update_rdf
update_observation_unit_policies
fix_xlsx_marked_as_zip
add_policies_to_existing_sample_types
fix_previous_sample_type_permissions
update_morpheus_model
]

# these are the tasks that are executes for each upgrade as standard, and rarely change
Expand Down Expand Up @@ -91,6 +94,36 @@ namespace :seek do
end
end

task(update_morpheus_model: [:environment]) do
puts "... updating morpheus model"
affected_models = []
errors = []
Model.find_each do |model|
next unless model.is_morpheus_supported?
begin
unless model.model_format
model.model_format = ModelFormat.find_by!(title: 'Morpheus')
end
unless model.recommended_environment
model.recommended_environment = RecommendedModelEnvironment.find_by!(title: 'Morpheus')
end
rescue ActiveRecord::RecordNotFound => e
error_message = "Error: #{e.message}. Ensure that the required 'Morpheus' records exist in the database."
puts error_message
errors << error_message
next
end
model.update_columns(model_format_id: model.model_format_id, recommended_environment_id: model.recommended_environment_id)
affected_models << model
end
ReindexingQueue.enqueue(affected_models)
puts "... reindexing job triggered for #{affected_models.count} models"
unless errors.empty?
puts "The following errors were encountered during the update:"
errors.each { |error| puts error }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it still needs to trigger a reindexing job for the affected models, using ReindexingQueue.enqueue(models) - where models are the affected models

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is because the callbacks are skipped with update_columns

end

task(add_policies_to_existing_sample_types: [:environment]) do
puts '... Adding policies to existing sample types'
counter = 0
Expand Down