populate completed_at
This commit is contained in:
@@ -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
|
||||||
+3
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.1].define(version: 2026_07_01_123007) do
|
ActiveRecord::Schema[8.1].define(version: 2026_07_01_165617) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "btree_gin"
|
enable_extension "btree_gin"
|
||||||
enable_extension "pg_catalog.plpgsql"
|
enable_extension "pg_catalog.plpgsql"
|
||||||
@@ -374,7 +374,9 @@ ActiveRecord::Schema[8.1].define(version: 2026_07_01_123007) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.text "variables"
|
t.text "variables"
|
||||||
t.text "variables_schema"
|
t.text "variables_schema"
|
||||||
|
t.index ["account_id", "completed_at"], name: "index_submissions_on_account_id_and_completed_at", where: "((completed_at IS NOT NULL) AND (archived_at IS NULL))"
|
||||||
t.index ["account_id", "id"], name: "index_submissions_on_account_id_and_id"
|
t.index ["account_id", "id"], name: "index_submissions_on_account_id_and_id"
|
||||||
|
t.index ["account_id", "id"], name: "index_submissions_on_account_id_and_id_pending", where: "((completed_at IS NULL) AND (archived_at IS NULL))"
|
||||||
t.index ["account_id", "template_id", "id"], name: "index_submissions_on_account_id_and_template_id_and_id", where: "(archived_at IS NULL)"
|
t.index ["account_id", "template_id", "id"], name: "index_submissions_on_account_id_and_template_id_and_id", where: "(archived_at IS NULL)"
|
||||||
t.index ["account_id", "template_id", "id"], name: "index_submissions_on_account_id_and_template_id_and_id_archived", where: "(archived_at IS NOT NULL)"
|
t.index ["account_id", "template_id", "id"], name: "index_submissions_on_account_id_and_template_id_and_id_archived", where: "(archived_at IS NOT NULL)"
|
||||||
t.index ["created_by_user_id"], name: "index_submissions_on_created_by_user_id"
|
t.index ["created_by_user_id"], name: "index_submissions_on_created_by_user_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user