mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:16:41 +08:00
25a226279a
The #pluck_first freedom patch, first introduced by @danielwaterworth has served us well, and is used widely throughout both core and plugins. It seems to have been a common enough use case that Rails 6 introduced it's own method #pick with the exact same implementation. This allows us to retire the freedom patch and switch over to the built-in ActiveRecord method. There is no replacement for #pluck_first!, but a quick search shows we are using this in a very limited capacity, and in some cases incorrectly (by assuming a nil return rather than an exception), which can quite easily be replaced with #pick plus some extra handling.
29 lines
686 B
Ruby
29 lines
686 B
Ruby
# frozen_string_literal: true
|
|
|
|
class BackupMetadata < ActiveRecord::Base
|
|
LAST_RESTORE_DATE = "last_restore_date"
|
|
|
|
def self.value_for(name)
|
|
where(name: name).pick(:value).presence
|
|
end
|
|
|
|
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
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: backup_metadata
|
|
#
|
|
# id :bigint not null, primary key
|
|
# name :string not null
|
|
# value :string
|
|
#
|