mirror of https://github.com/docusealco/docuseal
parent
1902cdaa55
commit
9194879c43
@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PopulateSubmissionCompletedAt < ActiveRecord::Migration[8.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class MigrationSubmission < ApplicationRecord
|
||||
self.table_name = 'submissions'
|
||||
end
|
||||
|
||||
def up
|
||||
max_id = MigrationSubmission.maximum(:id)
|
||||
|
||||
return unless max_id
|
||||
|
||||
max_completed_at =
|
||||
Arel::Nodes::Grouping.new(
|
||||
Submitter.arel_table.project(Submitter.arel_table[:completed_at].maximum)
|
||||
.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id]))
|
||||
.ast
|
||||
)
|
||||
|
||||
(1..max_id).step(10_000) do |start_id|
|
||||
range = start_id...(start_id + 10_000)
|
||||
|
||||
incomplete_submitter =
|
||||
Submitter.where(completed_at: nil, submission_id: range)
|
||||
.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id]))
|
||||
.select(1)
|
||||
|
||||
MigrationSubmission.where(completed_at: nil, id: range)
|
||||
.where.not(incomplete_submitter.arel.exists)
|
||||
.update_all(completed_at: max_completed_at)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
nil
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddIndexOnSubmissionsCompletedAt < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_index :submissions, %i[account_id completed_at],
|
||||
where: 'completed_at IS NOT NULL AND archived_at IS NULL',
|
||||
name: 'index_submissions_on_account_id_and_completed_at',
|
||||
if_not_exists: true
|
||||
|
||||
return unless connection.supports_partial_index?
|
||||
|
||||
add_index :submissions, %i[account_id id],
|
||||
where: 'completed_at IS NULL AND archived_at IS NULL',
|
||||
name: 'index_submissions_on_account_id_and_id_pending',
|
||||
if_not_exists: true
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue