blob: 89e5d153b85eaa70b3e21b78c8d141503fd8a1e1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
require_relative "scoping/default"
require_relative "scoping/named"
module ActiveRecord
# This class is used to create a table that keeps track of values and keys such
# as which environment migrations were run in.
class InternalMetadata < ActiveRecord::Base # :nodoc:
class << self
def primary_key
"key"
end
def table_name
"#{table_name_prefix}#{ActiveRecord::Base.internal_metadata_table_name}#{table_name_suffix}"
end
def []=(key, value)
find_or_initialize_by(key: key).update_attributes!(value: value)
end
def [](key)
where(key: key).pluck(:value).first
end
def table_exists?
connection.table_exists?(table_name)
end
# Creates an internal metadata table with columns +key+ and +value+
def create_table
unless table_exists?
key_options = connection.internal_string_options_for_primary_key
connection.create_table(table_name, id: false) do |t|
t.string :key, key_options
t.string :value
t.timestamps
end
end
end
end
end
end
|