Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/pages_deployment.rb')
-rw-r--r--app/models/pages_deployment.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/pages_deployment.rb b/app/models/pages_deployment.rb
index ec2293fa032..de7b2416258 100644
--- a/app/models/pages_deployment.rb
+++ b/app/models/pages_deployment.rb
@@ -11,13 +11,16 @@ class PagesDeployment < ApplicationRecord
attribute :file_store, :integer, default: -> { ::Pages::DeploymentUploader.default_store }
belongs_to :project, optional: false
+
+ # ci_build is optional, because PagesDeployment must live even if its build/pipeline is removed.
belongs_to :ci_build, class_name: 'Ci::Build', optional: true
- scope :older_than, -> (id) { where('id < ?', id) }
+ scope :older_than, ->(id) { where('id < ?', id) }
scope :migrated_from_legacy_storage, -> { where(file: MIGRATED_FILE_NAME) }
scope :with_files_stored_locally, -> { where(file_store: ::ObjectStorage::Store::LOCAL) }
scope :with_files_stored_remotely, -> { where(file_store: ::ObjectStorage::Store::REMOTE) }
scope :project_id_in, ->(ids) { where(project_id: ids) }
+ scope :active, -> { where(deleted_at: nil) }
validates :file, presence: true
validates :file_store, presence: true, inclusion: { in: ObjectStorage::SUPPORTED_STORES }
@@ -32,6 +35,14 @@ class PagesDeployment < ApplicationRecord
skip_callback :save, :after, :store_file!
after_commit :store_file_after_commit!, on: [:create, :update]
+ def self.deactivate_deployments_older_than(deployment, time: nil)
+ now = Time.now.utc
+ active
+ .older_than(deployment.id)
+ .where(project_id: deployment.project_id, path_prefix: deployment.path_prefix)
+ .update_all(updated_at: now, deleted_at: time || now)
+ end
+
def migrated?
file.filename == MIGRATED_FILE_NAME
end