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

Support UUID primary keys #1131

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions app/models/maintenance_tasks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class Run < ApplicationRecord
with_attached_csv_file if ActiveStorage::Attachment.table_exists?
end

scope :last_completed_per_task, -> do
subquery = completed
.select('task_name, MAX(ended_at) AS latest_ended_at')
.group(:task_name)
joins("INNER JOIN (#{subquery.to_sql}) latest_runs ON latest_runs.task_name = maintenance_tasks_runs.task_name AND latest_runs.latest_ended_at = maintenance_tasks_runs.ended_at")
end

validates_with RunStatusValidator, on: :update

if MaintenanceTasks.active_storage_service.present?
Expand Down
3 changes: 1 addition & 2 deletions app/models/maintenance_tasks/task_data_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def available_tasks
task_names.delete(run.task_name)
end

completed_runs = Run.completed.where(task_name: task_names)
last_runs = Run.with_attached_csv.where(id: completed_runs.select("MAX(id) as id").group(:task_name))
last_runs = Run.with_attached_csv.last_completed_per_task.where(task_name: task_names)
task_names.map do |task_name|
last_run = last_runs.find { |run| run.task_name == task_name }
tasks << TaskDataIndex.new(task_name, last_run)
Expand Down
Loading