2019-07-09 07:57:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BackupMetadata < ActiveRecord::Base
|
2020-01-15 17:19:13 -05:00
|
|
|
LAST_RESTORE_DATE = "last_restore_date"
|
|
|
|
|
2019-07-09 07:57:31 -04:00
|
|
|
def self.value_for(name)
|
2023-02-12 23:39:45 -05:00
|
|
|
where(name: name).pick(:value).presence
|
2019-07-09 07:57:31 -04:00
|
|
|
end
|
2020-09-10 15:37:42 -04:00
|
|
|
|
|
|
|
def self.last_restore_date
|
|
|
|
value = value_for(LAST_RESTORE_DATE)
|
|
|
|
value.present? ? Time.zone.parse(value) : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.update_last_restore_date(time = Time.zone.now)
|
|
|
|
BackupMetadata.where(name: LAST_RESTORE_DATE).delete_all
|
|
|
|
BackupMetadata.create!(name: LAST_RESTORE_DATE, value: time.iso8601)
|
|
|
|
end
|
2019-07-09 07:57:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: backup_metadata
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# name :string not null
|
|
|
|
# value :string
|
|
|
|
#
|