debian-mirror-gitlab/lib/gitlab/database/background_migration_job.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Gitlab
module Database
2022-03-02 08:16:31 +05:30
class BackgroundMigrationJob < SharedModel
2020-11-24 15:15:51 +05:30
include EachBatch
2021-12-11 22:18:48 +05:30
include BulkInsertSafe
2020-11-24 15:15:51 +05:30
2020-07-28 23:09:34 +05:30
self.table_name = :background_migration_jobs
scope :for_migration_class, -> (class_name) { where(class_name: normalize_class_name(class_name)) }
scope :for_migration_execution, -> (class_name, arguments) do
2021-06-08 01:23:25 +05:30
for_migration_class(class_name).where('arguments = ?', arguments.to_json) # rubocop:disable Rails/WhereEquals
2020-07-28 23:09:34 +05:30
end
scope :for_partitioning_migration, -> (class_name, table_name) do
for_migration_class(class_name).where('arguments ->> 2 = ?', table_name)
end
enum status: {
pending: 0,
succeeded: 1
}
def self.mark_all_as_succeeded(class_name, arguments)
self.pending.for_migration_execution(class_name, arguments)
.update_all("status = #{statuses[:succeeded]}, updated_at = NOW()")
end
def self.normalize_class_name(class_name)
return class_name unless class_name.present? && class_name.start_with?('::')
class_name[2..]
end
def class_name=(value)
write_attribute(:class_name, self.class.normalize_class_name(value))
end
end
end
end