summaryrefslogtreecommitdiff
path: root/app/models/container_repository.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-10 15:12:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-10 15:12:42 +0000
commit74d9798736a89f07e047698e5e32964829bf8859 (patch)
treeb969a2a5e29f2f83b3f7fcddfc3804f62432bbb4 /app/models/container_repository.rb
parent190128fc72e015c383e7a96c128276d1833f3beb (diff)
downloadgitlab-ce-74d9798736a89f07e047698e5e32964829bf8859.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/container_repository.rb')
-rw-r--r--app/models/container_repository.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb
index c1fb2726d03..ebc6537637d 100644
--- a/app/models/container_repository.rb
+++ b/app/models/container_repository.rb
@@ -10,6 +10,7 @@ class ContainerRepository < ApplicationRecord
REQUIRING_CLEANUP_STATUSES = %i[cleanup_unscheduled cleanup_scheduled].freeze
IDLE_MIGRATION_STATES = %w[default pre_import_done import_done import_aborted import_skipped].freeze
ACTIVE_MIGRATION_STATES = %w[pre_importing importing].freeze
+ ABORTABLE_MIGRATION_STATES = (ACTIVE_MIGRATION_STATES + ['pre_import_done']).freeze
MIGRATION_STATES = (IDLE_MIGRATION_STATES + ACTIVE_MIGRATION_STATES).freeze
belongs_to :project
@@ -17,7 +18,7 @@ class ContainerRepository < ApplicationRecord
validates :name, length: { minimum: 0, allow_nil: false }
validates :name, uniqueness: { scope: :project_id }
validates :migration_state, presence: true, inclusion: { in: MIGRATION_STATES }
- validates :migration_aborted_in_state, inclusion: { in: ACTIVE_MIGRATION_STATES }, allow_nil: true
+ validates :migration_aborted_in_state, inclusion: { in: ABORTABLE_MIGRATION_STATES }, allow_nil: true
validates :migration_retries_count, presence: true,
numericality: { greater_than_or_equal_to: 0 },
@@ -43,6 +44,9 @@ class ContainerRepository < ApplicationRecord
scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) }
scope :waiting_for_cleanup, -> { where(expiration_policy_cleanup_status: WAITING_CLEANUP_STATUSES) }
scope :expiration_policy_started_at_nil_or_before, ->(timestamp) { where('expiration_policy_started_at < ? OR expiration_policy_started_at IS NULL', timestamp) }
+ scope :with_migration_import_started_at_nil_or_before, ->(timestamp) { where("COALESCE(migration_import_started_at, '01-01-1970') < ?", timestamp) }
+ scope :with_migration_pre_import_started_at_nil_or_before, ->(timestamp) { where("COALESCE(migration_pre_import_started_at, '01-01-1970') < ?", timestamp) }
+ scope :with_migration_pre_import_done_at_nil_or_before, ->(timestamp) { where("COALESCE(migration_pre_import_done_at, '01-01-1970') < ?", timestamp) }
scope :with_stale_ongoing_cleanup, ->(threshold) { cleanup_ongoing.where('expiration_policy_started_at < ?', threshold) }
state_machine :migration_state, initial: :default do
@@ -96,7 +100,7 @@ class ContainerRepository < ApplicationRecord
end
event :abort_import do
- transition ACTIVE_MIGRATION_STATES.map(&:to_sym) => :import_aborted
+ transition ABORTABLE_MIGRATION_STATES.map(&:to_sym) => :import_aborted
end
event :skip_import do
@@ -181,6 +185,22 @@ class ContainerRepository < ApplicationRecord
with_enabled_policy.cleanup_unfinished
end
+ def self.with_stale_migration(before_timestamp)
+ stale_pre_importing = with_migration_states(:pre_importing)
+ .with_migration_pre_import_started_at_nil_or_before(before_timestamp)
+ stale_pre_import_done = with_migration_states(:pre_import_done)
+ .with_migration_pre_import_done_at_nil_or_before(before_timestamp)
+ stale_importing = with_migration_states(:importing)
+ .with_migration_import_started_at_nil_or_before(before_timestamp)
+
+ union = ::Gitlab::SQL::Union.new([
+ stale_pre_importing,
+ stale_pre_import_done,
+ stale_importing
+ ])
+ from("(#{union.to_sql}) #{ContainerRepository.table_name}")
+ end
+
def skip_import(reason:)
self.migration_skipped_reason = reason