debian-mirror-gitlab/app/models/pages_deployment.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
# PagesDeployment stores a zip archive containing GitLab Pages web-site
class PagesDeployment < ApplicationRecord
2021-03-11 19:13:27 +05:30
include EachBatch
2021-01-03 14:25:43 +05:30
include FileStoreMounter
2021-03-11 19:13:27 +05:30
MIGRATED_FILE_NAME = "_migrated.zip"
2021-01-29 00:20:46 +05:30
attribute :file_store, :integer, default: -> { ::Pages::DeploymentUploader.default_store }
2020-11-24 15:15:51 +05:30
belongs_to :project, optional: false
belongs_to :ci_build, class_name: 'Ci::Build', optional: true
2021-01-29 00:20:46 +05:30
scope :older_than, -> (id) { where('id < ?', id) }
2021-03-11 19:13:27 +05:30
scope :migrated_from_legacy_storage, -> { where(file: MIGRATED_FILE_NAME) }
2021-01-29 00:20:46 +05:30
2020-11-24 15:15:51 +05:30
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 }
2021-01-29 00:20:46 +05:30
validates :file_count, presence: true, numericality: { greater_than_or_equal_to: 0, only_integer: true }
validates :file_sha256, presence: true
2021-01-03 14:25:43 +05:30
before_validation :set_size, if: :file_changed?
mount_file_store_uploader ::Pages::DeploymentUploader
2021-01-29 00:20:46 +05:30
def log_geo_deleted_event
# this is to be adressed in https://gitlab.com/groups/gitlab-org/-/epics/589
end
2021-03-11 19:13:27 +05:30
def migrated?
file.filename == MIGRATED_FILE_NAME
end
2021-01-03 14:25:43 +05:30
private
def set_size
self.size = file.size
end
2020-11-24 15:15:51 +05:30
end