2020-09-16 08:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Terraform
|
|
|
|
class StateVersion < ApplicationRecord
|
2022-06-02 23:09:20 -04:00
|
|
|
include EachBatch
|
2020-09-16 08:10:15 -04:00
|
|
|
include FileStoreMounter
|
|
|
|
|
|
|
|
belongs_to :terraform_state, class_name: 'Terraform::State', optional: false
|
|
|
|
belongs_to :created_by_user, class_name: 'User', optional: true
|
2020-10-25 20:09:02 -04:00
|
|
|
belongs_to :build, class_name: 'Ci::Build', optional: true, foreign_key: :ci_build_id
|
2020-09-16 08:10:15 -04:00
|
|
|
|
|
|
|
scope :ordered_by_version_desc, -> { order(version: :desc) }
|
2021-01-22 01:08:52 -05:00
|
|
|
scope :with_files_stored_locally, -> { where(file_store: Terraform::StateUploader::Store::LOCAL) }
|
|
|
|
scope :preload_state, -> { includes(:terraform_state) }
|
2020-09-16 08:10:15 -04:00
|
|
|
|
2020-11-23 07:09:11 -05:00
|
|
|
default_value_for(:file_store) { StateUploader.default_store }
|
2020-09-16 08:10:15 -04:00
|
|
|
|
2020-11-23 07:09:11 -05:00
|
|
|
mount_file_store_uploader StateUploader
|
2020-09-16 08:10:15 -04:00
|
|
|
|
|
|
|
delegate :project_id, :uuid, to: :terraform_state, allow_nil: true
|
|
|
|
end
|
|
|
|
end
|
2020-09-24 23:09:30 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Terraform::StateVersion.prepend_mod_with('Terraform::StateVersion')
|