Class: ColdStorage::Metadata

Inherits:
ArchiveRecord show all
Defined in:
lib/cold_storage/metadata.rb

Overview

Key/value store in the archive database. Holds the migration version the mirrored schema was last synced against.

Constant Summary collapse

SCHEMA_VERSION_KEY =
'schema_version'

Class Method Summary collapse

Methods inherited from ArchiveRecord

connect!, database_config, reset_connection!, #restore!, source_model, #source_model, with_archive_connection

Class Method Details

.get(key) ⇒ Object



13
14
15
16
# File 'lib/cold_storage/metadata.rb', line 13

def get(key)
  InternalSchema.ensure!
  where(key: key.to_s).pick(:value)
end

.schema_versionObject



24
25
26
# File 'lib/cold_storage/metadata.rb', line 24

def schema_version
  get(SCHEMA_VERSION_KEY)
end

.schema_version=(version) ⇒ Object



28
29
30
# File 'lib/cold_storage/metadata.rb', line 28

def schema_version=(version)
  set(SCHEMA_VERSION_KEY, version)
end

.set(key, value) ⇒ Object



18
19
20
21
22
# File 'lib/cold_storage/metadata.rb', line 18

def set(key, value)
  InternalSchema.ensure!
  upsert({ key: key.to_s, value: value.to_s, updated_at: Time.current }, unique_by: :key)
  value
end