ovirt_metrics 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/column.rb +15 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb +170 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb +42 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb +70 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb +52 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb +13 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb +15 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb +48 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb +21 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb +13 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb +19 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb +59 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb +13 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb +10 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb +23 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb +39 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb +43 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb +50 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb +93 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb +15 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb +109 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb +21 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb +26 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb +28 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb +31 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb +116 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb +49 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb +180 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb +47 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb +682 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb +35 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb +77 -0
- data/lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb +856 -0
- data/lib/{models → ovirt_metrics/models}/calendar.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/cluster_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/datacenter_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/datacenter_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/datacenter_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/datacenter_samples_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/datacenter_storage_domain_map.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/disks_vm_map.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/enum_translator.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/history_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_interface_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_interface_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_interface_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_interface_samples_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/host_samples_history.rb +0 -0
- data/lib/ovirt_metrics/models/ovirt_history.rb +12 -0
- data/lib/{models → ovirt_metrics/models}/period.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/storage_domain_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/storage_domain_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/storage_domain_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/storage_domain_samples_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/tag_details.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/tag_relations_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disk_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disk_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disk_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disk_samples_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disks_usage_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disks_usage_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_disks_usage_samples_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_interface_configuration.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_interface_daily_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_interface_hourly_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_interface_samples_history.rb +0 -0
- data/lib/{models → ovirt_metrics/models}/vm_samples_history.rb +0 -0
- data/lib/ovirt_metrics/version.rb +1 -1
- data/lib/ovirt_metrics.rb +11 -3
- metadata +114 -47
- data/lib/models/ovirt_history.rb +0 -24
@@ -0,0 +1,43 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module OID # :nodoc:
|
5
|
+
class Point < Type::Value # :nodoc:
|
6
|
+
include Type::Helpers::Mutable
|
7
|
+
|
8
|
+
def type
|
9
|
+
:point
|
10
|
+
end
|
11
|
+
|
12
|
+
def cast(value)
|
13
|
+
case value
|
14
|
+
when ::String
|
15
|
+
if value[0] == '(' && value[-1] == ')'
|
16
|
+
value = value[1...-1]
|
17
|
+
end
|
18
|
+
cast(value.split(','))
|
19
|
+
when ::Array
|
20
|
+
value.map { |v| Float(v) }
|
21
|
+
else
|
22
|
+
value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def serialize(value)
|
27
|
+
if value.is_a?(::Array)
|
28
|
+
"(#{number_for_point(value[0])},#{number_for_point(value[1])})"
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def number_for_point(number)
|
37
|
+
number.to_s.gsub(/\.0$/, '')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
Point = Struct.new(:x, :y)
|
3
|
+
|
4
|
+
module ConnectionAdapters
|
5
|
+
module OvirtLegacyPostgreSQL
|
6
|
+
module OID # :nodoc:
|
7
|
+
class Rails51Point < Type::Value # :nodoc:
|
8
|
+
include Type::Helpers::Mutable
|
9
|
+
|
10
|
+
def type
|
11
|
+
:point
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(value)
|
15
|
+
case value
|
16
|
+
when ::String
|
17
|
+
if value[0] == '(' && value[-1] == ')'
|
18
|
+
value = value[1...-1]
|
19
|
+
end
|
20
|
+
x, y = value.split(",")
|
21
|
+
build_point(x, y)
|
22
|
+
when ::Array
|
23
|
+
build_point(*value)
|
24
|
+
else
|
25
|
+
value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def serialize(value)
|
30
|
+
if value.is_a?(ActiveRecord::Point)
|
31
|
+
"(#{number_for_point(value.x)},#{number_for_point(value.y)})"
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def number_for_point(number)
|
40
|
+
number.to_s.gsub(/\.0$/, '')
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_point(x, y)
|
44
|
+
ActiveRecord::Point.new(Float(x), Float(y))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'active_support/core_ext/string/filters'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module OvirtLegacyPostgreSQL
|
6
|
+
module OID # :nodoc:
|
7
|
+
class Range < Type::Value # :nodoc:
|
8
|
+
attr_reader :subtype, :type
|
9
|
+
delegate :user_input_in_time_zone, to: :subtype
|
10
|
+
|
11
|
+
def initialize(subtype, type = :range)
|
12
|
+
@subtype = subtype
|
13
|
+
@type = type
|
14
|
+
end
|
15
|
+
|
16
|
+
def type_cast_for_schema(value)
|
17
|
+
value.inspect.gsub('Infinity', '::Float::INFINITY')
|
18
|
+
end
|
19
|
+
|
20
|
+
def cast_value(value)
|
21
|
+
return if value == 'empty'
|
22
|
+
return value unless value.is_a?(::String)
|
23
|
+
|
24
|
+
extracted = extract_bounds(value)
|
25
|
+
from = type_cast_single extracted[:from]
|
26
|
+
to = type_cast_single extracted[:to]
|
27
|
+
|
28
|
+
if !infinity?(from) && extracted[:exclude_start]
|
29
|
+
raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
|
30
|
+
end
|
31
|
+
::Range.new(from, to, extracted[:exclude_end])
|
32
|
+
end
|
33
|
+
|
34
|
+
def serialize(value)
|
35
|
+
if value.is_a?(::Range)
|
36
|
+
from = type_cast_single_for_database(value.begin)
|
37
|
+
to = type_cast_single_for_database(value.end)
|
38
|
+
"[#{from},#{to}#{value.exclude_end? ? ')' : ']'}"
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def ==(other)
|
45
|
+
other.is_a?(Range) &&
|
46
|
+
other.subtype == subtype &&
|
47
|
+
other.type == type
|
48
|
+
end
|
49
|
+
|
50
|
+
def map(value) # :nodoc:
|
51
|
+
new_begin = yield(value.begin)
|
52
|
+
new_end = yield(value.end)
|
53
|
+
::Range.new(new_begin, new_end, value.exclude_end?)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def type_cast_single(value)
|
59
|
+
infinity?(value) ? value : @subtype.deserialize(value)
|
60
|
+
end
|
61
|
+
|
62
|
+
def type_cast_single_for_database(value)
|
63
|
+
infinity?(value) ? '' : @subtype.serialize(value)
|
64
|
+
end
|
65
|
+
|
66
|
+
def extract_bounds(value)
|
67
|
+
from, to = value[1..-2].split(',')
|
68
|
+
{
|
69
|
+
from: (value[1] == ',' || from == '-infinity') ? infinity(negative: true) : from,
|
70
|
+
to: (value[-2] == ',' || to == 'infinity') ? infinity : to,
|
71
|
+
exclude_start: (value[0] == '('),
|
72
|
+
exclude_end: (value[-1] == ')')
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def infinity(negative: false)
|
77
|
+
if subtype.respond_to?(:infinity)
|
78
|
+
subtype.infinity(negative: negative)
|
79
|
+
elsif negative
|
80
|
+
-::Float::INFINITY
|
81
|
+
else
|
82
|
+
::Float::INFINITY
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def infinity?(value)
|
87
|
+
value.respond_to?(:infinite?) && value.infinite?
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module OID # :nodoc:
|
5
|
+
class SpecializedString < Type::String # :nodoc:
|
6
|
+
attr_reader :type
|
7
|
+
|
8
|
+
def initialize(type)
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module OID # :nodoc:
|
5
|
+
# This class uses the data from PostgreSQL pg_type table to build
|
6
|
+
# the OID -> Type mapping.
|
7
|
+
# - OID is an integer representing the type.
|
8
|
+
# - Type is an OID::Type object.
|
9
|
+
# This class has side effects on the +store+ passed during initialization.
|
10
|
+
class TypeMapInitializer # :nodoc:
|
11
|
+
def initialize(store)
|
12
|
+
@store = store
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(records)
|
16
|
+
nodes = records.reject { |row| @store.key? row['oid'].to_i }
|
17
|
+
mapped, nodes = nodes.partition { |row| @store.key? row['typname'] }
|
18
|
+
ranges, nodes = nodes.partition { |row| row['typtype'] == 'r'.freeze }
|
19
|
+
enums, nodes = nodes.partition { |row| row['typtype'] == 'e'.freeze }
|
20
|
+
domains, nodes = nodes.partition { |row| row['typtype'] == 'd'.freeze }
|
21
|
+
arrays, nodes = nodes.partition { |row| row['typinput'] == 'array_in'.freeze }
|
22
|
+
composites, nodes = nodes.partition { |row| row['typelem'].to_i != 0 }
|
23
|
+
|
24
|
+
mapped.each { |row| register_mapped_type(row) }
|
25
|
+
enums.each { |row| register_enum_type(row) }
|
26
|
+
domains.each { |row| register_domain_type(row) }
|
27
|
+
arrays.each { |row| register_array_type(row) }
|
28
|
+
ranges.each { |row| register_range_type(row) }
|
29
|
+
composites.each { |row| register_composite_type(row) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def query_conditions_for_initial_load(type_map)
|
33
|
+
known_type_names = type_map.keys.map { |n| "'#{n}'" }
|
34
|
+
known_type_types = %w('r' 'e' 'd')
|
35
|
+
<<-SQL % [known_type_names.join(", "), known_type_types.join(", ")]
|
36
|
+
WHERE
|
37
|
+
t.typname IN (%s)
|
38
|
+
OR t.typtype IN (%s)
|
39
|
+
OR t.typinput = 'array_in(cstring,oid,integer)'::regprocedure
|
40
|
+
OR t.typelem != 0
|
41
|
+
SQL
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def register_mapped_type(row)
|
46
|
+
alias_type row['oid'], row['typname']
|
47
|
+
end
|
48
|
+
|
49
|
+
def register_enum_type(row)
|
50
|
+
register row['oid'], OID::Enum.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def register_array_type(row)
|
54
|
+
register_with_subtype(row['oid'], row['typelem'].to_i) do |subtype|
|
55
|
+
OID::Array.new(subtype, row['typdelim'])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def register_range_type(row)
|
60
|
+
register_with_subtype(row['oid'], row['rngsubtype'].to_i) do |subtype|
|
61
|
+
OID::Range.new(subtype, row['typname'].to_sym)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def register_domain_type(row)
|
66
|
+
if base_type = @store.lookup(row["typbasetype"].to_i)
|
67
|
+
register row['oid'], base_type
|
68
|
+
else
|
69
|
+
warn "unknown base type (OID: #{row["typbasetype"]}) for domain #{row["typname"]}."
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def register_composite_type(row)
|
74
|
+
if subtype = @store.lookup(row['typelem'].to_i)
|
75
|
+
register row['oid'], OID::Vector.new(row['typdelim'], subtype)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def register(oid, oid_type = nil, &block)
|
80
|
+
oid = assert_valid_registration(oid, oid_type || block)
|
81
|
+
if block_given?
|
82
|
+
@store.register_type(oid, &block)
|
83
|
+
else
|
84
|
+
@store.register_type(oid, oid_type)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def alias_type(oid, target)
|
89
|
+
oid = assert_valid_registration(oid, target)
|
90
|
+
@store.alias_type(oid, target)
|
91
|
+
end
|
92
|
+
|
93
|
+
def register_with_subtype(oid, target_oid)
|
94
|
+
if @store.key?(target_oid)
|
95
|
+
register(oid) do |_, *args|
|
96
|
+
yield @store.lookup(target_oid, *args)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def assert_valid_registration(oid, oid_type)
|
102
|
+
raise ArgumentError, "can't register nil type for OID #{oid}" if oid_type.nil?
|
103
|
+
oid.to_i
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module OID # :nodoc:
|
5
|
+
class Uuid < Type::Value # :nodoc:
|
6
|
+
ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x
|
7
|
+
|
8
|
+
alias_method :serialize, :deserialize
|
9
|
+
|
10
|
+
def type
|
11
|
+
:uuid
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(value)
|
15
|
+
value.to_s[ACCEPTABLE_UUID, 0]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module OID # :nodoc:
|
5
|
+
class Vector < Type::Value # :nodoc:
|
6
|
+
attr_reader :delim, :subtype
|
7
|
+
|
8
|
+
# +delim+ corresponds to the `typdelim` column in the pg_types
|
9
|
+
# table. +subtype+ is derived from the `typelem` column in the
|
10
|
+
# pg_types table.
|
11
|
+
def initialize(delim, subtype)
|
12
|
+
@delim = delim
|
13
|
+
@subtype = subtype
|
14
|
+
end
|
15
|
+
|
16
|
+
# FIXME: this should probably split on +delim+ and use +subtype+
|
17
|
+
# to cast the values. Unfortunately, the current Rails behavior
|
18
|
+
# is to just return the string.
|
19
|
+
def cast(value)
|
20
|
+
value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module OID # :nodoc:
|
5
|
+
class Xml < Type::String # :nodoc:
|
6
|
+
def type
|
7
|
+
:xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize(value)
|
11
|
+
return unless value
|
12
|
+
Data.new(super)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Data # :nodoc:
|
16
|
+
def initialize(value)
|
17
|
+
@value = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/array'
|
2
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit'
|
3
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying'
|
4
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea'
|
5
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr'
|
6
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time'
|
7
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal'
|
8
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum'
|
9
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore'
|
10
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet'
|
11
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/json'
|
12
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb'
|
13
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/money'
|
14
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/point'
|
15
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point'
|
16
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/range'
|
17
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string'
|
18
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid'
|
19
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector'
|
20
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml'
|
21
|
+
|
22
|
+
require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer'
|
23
|
+
|
24
|
+
module ActiveRecord
|
25
|
+
module ConnectionAdapters
|
26
|
+
module OvirtLegacyPostgreSQL
|
27
|
+
module OID # :nodoc:
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module Quoting
|
5
|
+
# Escapes binary strings for bytea input to the database.
|
6
|
+
def escape_bytea(value)
|
7
|
+
@connection.escape_bytea(value) if value
|
8
|
+
end
|
9
|
+
|
10
|
+
# Unescapes bytea output from a database to the binary string it represents.
|
11
|
+
# NOTE: This is NOT an inverse of escape_bytea! This is only to be used
|
12
|
+
# on escaped binary output from database drive.
|
13
|
+
def unescape_bytea(value)
|
14
|
+
@connection.unescape_bytea(value) if value
|
15
|
+
end
|
16
|
+
|
17
|
+
# Quotes strings for use in SQL input.
|
18
|
+
def quote_string(s) #:nodoc:
|
19
|
+
@connection.escape(s)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Checks the following cases:
|
23
|
+
#
|
24
|
+
# - table_name
|
25
|
+
# - "table.name"
|
26
|
+
# - schema_name.table_name
|
27
|
+
# - schema_name."table.name"
|
28
|
+
# - "schema.name".table_name
|
29
|
+
# - "schema.name"."table.name"
|
30
|
+
def quote_table_name(name) # :nodoc:
|
31
|
+
@quoted_table_names[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted
|
32
|
+
end
|
33
|
+
|
34
|
+
# Quotes schema names for use in SQL queries.
|
35
|
+
def quote_schema_name(name)
|
36
|
+
PGconn.quote_ident(name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def quote_table_name_for_assignment(table, attr)
|
40
|
+
quote_column_name(attr)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Quotes column names for use in SQL queries.
|
44
|
+
def quote_column_name(name) # :nodoc:
|
45
|
+
@quoted_column_names[name] ||= PGconn.quote_ident(super)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Quote date/time values for use in SQL input.
|
49
|
+
def quoted_date(value) #:nodoc:
|
50
|
+
if value.year <= 0
|
51
|
+
bce_year = format("%04d", -value.year + 1)
|
52
|
+
super.sub(/^-?\d+/, bce_year) + " BC"
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def quote_default_expression(value, column) # :nodoc:
|
59
|
+
if value.is_a?(Proc)
|
60
|
+
value.call
|
61
|
+
elsif column.type == :uuid && value =~ /\(\)/
|
62
|
+
value # Does not quote function default values for UUID columns
|
63
|
+
elsif column.respond_to?(:array?)
|
64
|
+
value = type_cast_from_column(column, value)
|
65
|
+
quote(value)
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def lookup_cast_type_from_column(column) # :nodoc:
|
72
|
+
type_map.lookup(column.oid, column.fmod, column.sql_type)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def _quote(value)
|
78
|
+
case value
|
79
|
+
when Type::Binary::Data
|
80
|
+
"'#{escape_bytea(value.to_s)}'"
|
81
|
+
when OID::Xml::Data
|
82
|
+
"xml '#{quote_string(value.to_s)}'"
|
83
|
+
when OID::Bit::Data
|
84
|
+
if value.binary?
|
85
|
+
"B'#{value}'"
|
86
|
+
elsif value.hex?
|
87
|
+
"X'#{value}'"
|
88
|
+
end
|
89
|
+
when Float
|
90
|
+
if value.infinite? || value.nan?
|
91
|
+
"'#{value}'"
|
92
|
+
else
|
93
|
+
super
|
94
|
+
end
|
95
|
+
else
|
96
|
+
super
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def _type_cast(value)
|
101
|
+
case value
|
102
|
+
when Type::Binary::Data
|
103
|
+
# Return a bind param hash with format as binary.
|
104
|
+
# See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
|
105
|
+
# for more information
|
106
|
+
{ value: value.to_s, format: 1 }
|
107
|
+
when OID::Xml::Data, OID::Bit::Data
|
108
|
+
value.to_s
|
109
|
+
else
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module OvirtLegacyPostgreSQL
|
4
|
+
module ReferentialIntegrity # :nodoc:
|
5
|
+
def supports_disable_referential_integrity? # :nodoc:
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
def disable_referential_integrity # :nodoc:
|
10
|
+
if supports_disable_referential_integrity?
|
11
|
+
original_exception = nil
|
12
|
+
|
13
|
+
begin
|
14
|
+
transaction(requires_new: true) do
|
15
|
+
execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
|
16
|
+
end
|
17
|
+
rescue ActiveRecord::ActiveRecordError => e
|
18
|
+
original_exception = e
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
yield
|
23
|
+
rescue ActiveRecord::InvalidForeignKey => e
|
24
|
+
warn <<-WARNING
|
25
|
+
WARNING: Rails was not able to disable referential integrity.
|
26
|
+
|
27
|
+
This is most likely caused due to missing permissions.
|
28
|
+
Rails needs superuser privileges to disable referential integrity.
|
29
|
+
|
30
|
+
cause: #{original_exception.try(:message)}
|
31
|
+
|
32
|
+
WARNING
|
33
|
+
raise e
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
transaction(requires_new: true) do
|
38
|
+
execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
|
39
|
+
end
|
40
|
+
rescue ActiveRecord::ActiveRecordError
|
41
|
+
end
|
42
|
+
else
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|