2020-09-17 17:09:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# PagesDeployment stores a zip archive containing GitLab Pages web-site
|
|
|
|
class PagesDeployment < ApplicationRecord
|
2021-02-10 07:09:45 -05:00
|
|
|
include EachBatch
|
2020-09-24 14:09:51 -04:00
|
|
|
include FileStoreMounter
|
|
|
|
|
2021-02-09 13:09:59 -05:00
|
|
|
MIGRATED_FILE_NAME = "_migrated.zip"
|
|
|
|
|
2020-11-11 10:08:46 -05:00
|
|
|
attribute :file_store, :integer, default: -> { ::Pages::DeploymentUploader.default_store }
|
|
|
|
|
2020-09-17 17:09:39 -04:00
|
|
|
belongs_to :project, optional: false
|
|
|
|
belongs_to :ci_build, class_name: 'Ci::Build', optional: true
|
|
|
|
|
2020-10-29 11:09:12 -04:00
|
|
|
scope :older_than, -> (id) { where('id < ?', id) }
|
2021-02-09 13:09:59 -05:00
|
|
|
scope :migrated_from_legacy_storage, -> { where(file: MIGRATED_FILE_NAME) }
|
2021-04-15 11:09:11 -04:00
|
|
|
scope :with_files_stored_locally, -> { where(file_store: ::ObjectStorage::Store::LOCAL) }
|
|
|
|
scope :with_files_stored_remotely, -> { where(file_store: ::ObjectStorage::Store::REMOTE) }
|
2021-09-14 11:12:05 -04:00
|
|
|
scope :project_id_in, ->(ids) { where(project_id: ids) }
|
2020-10-29 11:09:12 -04:00
|
|
|
|
2020-09-17 17:09:39 -04:00
|
|
|
validates :file, presence: true
|
|
|
|
validates :file_store, presence: true, inclusion: { in: ObjectStorage::SUPPORTED_STORES }
|
|
|
|
validates :size, presence: true, numericality: { greater_than: 0, only_integer: true }
|
2020-10-22 11:08:25 -04:00
|
|
|
validates :file_count, presence: true, numericality: { greater_than_or_equal_to: 0, only_integer: true }
|
|
|
|
validates :file_sha256, presence: true
|
2020-09-24 14:09:51 -04:00
|
|
|
|
2020-10-12 14:08:31 -04:00
|
|
|
before_validation :set_size, if: :file_changed?
|
|
|
|
|
2020-09-24 14:09:51 -04:00
|
|
|
mount_file_store_uploader ::Pages::DeploymentUploader
|
2020-10-12 14:08:31 -04:00
|
|
|
|
2021-02-09 13:09:59 -05:00
|
|
|
def migrated?
|
|
|
|
file.filename == MIGRATED_FILE_NAME
|
|
|
|
end
|
|
|
|
|
2020-10-12 14:08:31 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_size
|
|
|
|
self.size = file.size
|
|
|
|
end
|
2020-09-17 17:09:39 -04:00
|
|
|
end
|
2021-08-31 14:10:24 -04:00
|
|
|
|
|
|
|
PagesDeployment.prepend_mod
|