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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/column.rb +15 -0
  3. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb +170 -0
  4. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb +42 -0
  5. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb +70 -0
  6. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb +52 -0
  7. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb +13 -0
  8. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb +15 -0
  9. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb +48 -0
  10. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb +21 -0
  11. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb +13 -0
  12. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb +19 -0
  13. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb +59 -0
  14. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb +13 -0
  15. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb +10 -0
  16. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb +23 -0
  17. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb +39 -0
  18. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb +43 -0
  19. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb +50 -0
  20. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb +93 -0
  21. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb +15 -0
  22. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb +109 -0
  23. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb +21 -0
  24. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb +26 -0
  25. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb +28 -0
  26. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb +31 -0
  27. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb +116 -0
  28. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb +49 -0
  29. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb +180 -0
  30. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb +47 -0
  31. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb +682 -0
  32. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb +35 -0
  33. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb +77 -0
  34. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb +856 -0
  35. data/lib/{models → ovirt_metrics/models}/calendar.rb +0 -0
  36. data/lib/{models → ovirt_metrics/models}/cluster_configuration.rb +0 -0
  37. data/lib/{models → ovirt_metrics/models}/datacenter_configuration.rb +0 -0
  38. data/lib/{models → ovirt_metrics/models}/datacenter_daily_history.rb +0 -0
  39. data/lib/{models → ovirt_metrics/models}/datacenter_hourly_history.rb +0 -0
  40. data/lib/{models → ovirt_metrics/models}/datacenter_samples_history.rb +0 -0
  41. data/lib/{models → ovirt_metrics/models}/datacenter_storage_domain_map.rb +0 -0
  42. data/lib/{models → ovirt_metrics/models}/disks_vm_map.rb +0 -0
  43. data/lib/{models → ovirt_metrics/models}/enum_translator.rb +0 -0
  44. data/lib/{models → ovirt_metrics/models}/history_configuration.rb +0 -0
  45. data/lib/{models → ovirt_metrics/models}/host_configuration.rb +0 -0
  46. data/lib/{models → ovirt_metrics/models}/host_daily_history.rb +0 -0
  47. data/lib/{models → ovirt_metrics/models}/host_hourly_history.rb +0 -0
  48. data/lib/{models → ovirt_metrics/models}/host_interface_configuration.rb +0 -0
  49. data/lib/{models → ovirt_metrics/models}/host_interface_daily_history.rb +0 -0
  50. data/lib/{models → ovirt_metrics/models}/host_interface_hourly_history.rb +0 -0
  51. data/lib/{models → ovirt_metrics/models}/host_interface_samples_history.rb +0 -0
  52. data/lib/{models → ovirt_metrics/models}/host_samples_history.rb +0 -0
  53. data/lib/ovirt_metrics/models/ovirt_history.rb +12 -0
  54. data/lib/{models → ovirt_metrics/models}/period.rb +0 -0
  55. data/lib/{models → ovirt_metrics/models}/storage_domain_configuration.rb +0 -0
  56. data/lib/{models → ovirt_metrics/models}/storage_domain_daily_history.rb +0 -0
  57. data/lib/{models → ovirt_metrics/models}/storage_domain_hourly_history.rb +0 -0
  58. data/lib/{models → ovirt_metrics/models}/storage_domain_samples_history.rb +0 -0
  59. data/lib/{models → ovirt_metrics/models}/tag_details.rb +0 -0
  60. data/lib/{models → ovirt_metrics/models}/tag_relations_history.rb +0 -0
  61. data/lib/{models → ovirt_metrics/models}/vm_configuration.rb +0 -0
  62. data/lib/{models → ovirt_metrics/models}/vm_daily_history.rb +0 -0
  63. data/lib/{models → ovirt_metrics/models}/vm_disk_configuration.rb +0 -0
  64. data/lib/{models → ovirt_metrics/models}/vm_disk_daily_history.rb +0 -0
  65. data/lib/{models → ovirt_metrics/models}/vm_disk_hourly_history.rb +0 -0
  66. data/lib/{models → ovirt_metrics/models}/vm_disk_samples_history.rb +0 -0
  67. data/lib/{models → ovirt_metrics/models}/vm_disks_usage_daily_history.rb +0 -0
  68. data/lib/{models → ovirt_metrics/models}/vm_disks_usage_hourly_history.rb +0 -0
  69. data/lib/{models → ovirt_metrics/models}/vm_disks_usage_samples_history.rb +0 -0
  70. data/lib/{models → ovirt_metrics/models}/vm_hourly_history.rb +0 -0
  71. data/lib/{models → ovirt_metrics/models}/vm_interface_configuration.rb +0 -0
  72. data/lib/{models → ovirt_metrics/models}/vm_interface_daily_history.rb +0 -0
  73. data/lib/{models → ovirt_metrics/models}/vm_interface_hourly_history.rb +0 -0
  74. data/lib/{models → ovirt_metrics/models}/vm_interface_samples_history.rb +0 -0
  75. data/lib/{models → ovirt_metrics/models}/vm_samples_history.rb +0 -0
  76. data/lib/ovirt_metrics/version.rb +1 -1
  77. data/lib/ovirt_metrics.rb +11 -3
  78. metadata +114 -47
  79. data/lib/models/ovirt_history.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0972797c4ecb7eddabc08532a7890321e856027
4
- data.tar.gz: ec1207a571b31f0a97edc69c49f99ce6cbf72910
3
+ metadata.gz: d77fbff78ca341555af7b4aedeacfb4cdc993b19
4
+ data.tar.gz: 0abdcd35775f8553286f60341eb9790f18ec646e
5
5
  SHA512:
6
- metadata.gz: 57da84932314838e52e990ffe4c55ec49a8066e1f7d3f1b49b565f66a587aa384f8b7a16e327da8a583a6d74ddb5f69fc277069987103d2fb277aed018887ff4
7
- data.tar.gz: 3a1c778df4042d75041f418391d10a9ac13faf685e251f7f5507d264a9a2da7b134b5938907144b8559cd4a94143ddce5d0b2ea67b8991fed1dae76864d132fa
6
+ metadata.gz: 50ddf0f9c933aefe585b85431e7b85c1a5064f8dc06137548500805512f18a65a2f9e27ae67e1d6035043401443fce3a2c8165df76f4a3a858733620cc86f369
7
+ data.tar.gz: aa04cc6baec4d034ae7a4ead3db42c6e965990163574b762d7fef83e19ca1bcf8cf2833617908b66d8c09f521469bd14ee6e47e0d710eda1ab382ca88b4cece2
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ # PostgreSQL-specific extensions to column definitions in a table.
4
+ class OvirtLegacyPostgreSQLColumn < Column #:nodoc:
5
+ delegate :array, :oid, :fmod, to: :sql_type_metadata
6
+ alias :array? :array
7
+
8
+ def serial?
9
+ return unless default_function
10
+
11
+ %r{\Anextval\('"?#{table_name}_#{name}_seq"?'::regclass\)\z} === default_function
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,170 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module DatabaseStatements
5
+ def explain(arel, binds = [])
6
+ sql = "EXPLAIN #{to_sql(arel, binds)}"
7
+ OvirtLegacyPostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
8
+ end
9
+
10
+ def select_value(arel, name = nil, binds = [])
11
+ arel, binds = binds_from_relation arel, binds
12
+ sql = to_sql(arel, binds)
13
+ execute_and_clear(sql, name, binds) do |result|
14
+ result.getvalue(0, 0) if result.ntuples > 0 && result.nfields > 0
15
+ end
16
+ end
17
+
18
+ def select_values(arel, name = nil, binds = [])
19
+ arel, binds = binds_from_relation arel, binds
20
+ sql = to_sql(arel, binds)
21
+ execute_and_clear(sql, name, binds) do |result|
22
+ if result.nfields > 0
23
+ result.column_values(0)
24
+ else
25
+ []
26
+ end
27
+ end
28
+ end
29
+
30
+ # Executes a SELECT query and returns an array of rows. Each row is an
31
+ # array of field values.
32
+ def select_rows(sql, name = nil, binds = [])
33
+ execute_and_clear(sql, name, binds) do |result|
34
+ result.values
35
+ end
36
+ end
37
+
38
+ # The internal PostgreSQL identifier of the money data type.
39
+ MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
40
+ # The internal PostgreSQL identifier of the BYTEA data type.
41
+ BYTEA_COLUMN_TYPE_OID = 17 #:nodoc:
42
+
43
+ # create a 2D array representing the result set
44
+ def result_as_array(res) #:nodoc:
45
+ # check if we have any binary column and if they need escaping
46
+ ftypes = Array.new(res.nfields) do |i|
47
+ [i, res.ftype(i)]
48
+ end
49
+
50
+ rows = res.values
51
+ return rows unless ftypes.any? { |_, x|
52
+ x == BYTEA_COLUMN_TYPE_OID || x == MONEY_COLUMN_TYPE_OID
53
+ }
54
+
55
+ typehash = ftypes.group_by { |_, type| type }
56
+ binaries = typehash[BYTEA_COLUMN_TYPE_OID] || []
57
+ monies = typehash[MONEY_COLUMN_TYPE_OID] || []
58
+
59
+ rows.each do |row|
60
+ # unescape string passed BYTEA field (OID == 17)
61
+ binaries.each do |index, _|
62
+ row[index] = unescape_bytea(row[index])
63
+ end
64
+
65
+ # If this is a money type column and there are any currency symbols,
66
+ # then strip them off. Indeed it would be prettier to do this in
67
+ # OvirtLegacyPostgreSQLColumn.string_to_decimal but would break form input
68
+ # fields that call value_before_type_cast.
69
+ monies.each do |index, _|
70
+ data = row[index]
71
+ # Because money output is formatted according to the locale, there are two
72
+ # cases to consider (note the decimal separators):
73
+ # (1) $12,345,678.12
74
+ # (2) $12.345.678,12
75
+ case data
76
+ when /^-?\D+[\d,]+\.\d{2}$/ # (1)
77
+ data.gsub!(/[^-\d.]/, '')
78
+ when /^-?\D+[\d.]+,\d{2}$/ # (2)
79
+ data.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ # Queries the database and returns the results in an Array-like object
86
+ def query(sql, name = nil) #:nodoc:
87
+ log(sql, name) do
88
+ result_as_array @connection.async_exec(sql)
89
+ end
90
+ end
91
+
92
+ # Executes an SQL statement, returning a PGresult object on success
93
+ # or raising a PGError exception otherwise.
94
+ # Note: the PGresult object is manually memory managed; if you don't
95
+ # need it specifically, you many want consider the exec_query wrapper.
96
+ def execute(sql, name = nil)
97
+ log(sql, name) do
98
+ @connection.async_exec(sql)
99
+ end
100
+ end
101
+
102
+ def exec_query(sql, name = 'SQL', binds = [], prepare: false)
103
+ execute_and_clear(sql, name, binds, prepare: prepare) do |result|
104
+ types = {}
105
+ fields = result.fields
106
+ fields.each_with_index do |fname, i|
107
+ ftype = result.ftype i
108
+ fmod = result.fmod i
109
+ types[fname] = get_oid_type(ftype, fmod, fname)
110
+ end
111
+ ActiveRecord::Result.new(fields, result.values, types)
112
+ end
113
+ end
114
+
115
+ def exec_delete(sql, name = 'SQL', binds = [])
116
+ execute_and_clear(sql, name, binds) {|result| result.cmd_tuples }
117
+ end
118
+ alias :exec_update :exec_delete
119
+
120
+ def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :nodoc:
121
+ if pk.nil?
122
+ # Extract the table from the insert sql. Yuck.
123
+ table_ref = extract_table_ref_from_insert_sql(sql)
124
+ pk = primary_key(table_ref) if table_ref
125
+ end
126
+
127
+ if pk && use_insert_returning?
128
+ sql = "#{sql} RETURNING #{quote_column_name(pk)}"
129
+ end
130
+
131
+ super
132
+ end
133
+
134
+ def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
135
+ val = exec_query(sql, name, binds)
136
+ if !use_insert_returning? && pk
137
+ unless sequence_name
138
+ table_ref = extract_table_ref_from_insert_sql(sql)
139
+ sequence_name = default_sequence_name(table_ref, pk)
140
+ return val unless sequence_name
141
+ end
142
+ last_insert_id_result(sequence_name)
143
+ else
144
+ val
145
+ end
146
+ end
147
+
148
+ # Begins a transaction.
149
+ def begin_db_transaction
150
+ execute "BEGIN"
151
+ end
152
+
153
+ def begin_isolated_db_transaction(isolation)
154
+ begin_db_transaction
155
+ execute "SET TRANSACTION ISOLATION LEVEL #{transaction_isolation_levels.fetch(isolation)}"
156
+ end
157
+
158
+ # Commits a transaction.
159
+ def commit_db_transaction
160
+ execute "COMMIT"
161
+ end
162
+
163
+ # Aborts a transaction.
164
+ def exec_rollback_db_transaction
165
+ execute "ROLLBACK"
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,42 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ class ExplainPrettyPrinter # :nodoc:
5
+ # Pretty prints the result of an EXPLAIN in a way that resembles the output of the
6
+ # PostgreSQL shell:
7
+ #
8
+ # QUERY PLAN
9
+ # ------------------------------------------------------------------------------
10
+ # Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
11
+ # Join Filter: (posts.user_id = users.id)
12
+ # -> Index Scan using users_pkey on users (cost=0.00..8.27 rows=1 width=4)
13
+ # Index Cond: (id = 1)
14
+ # -> Seq Scan on posts (cost=0.00..28.88 rows=8 width=4)
15
+ # Filter: (posts.user_id = 1)
16
+ # (6 rows)
17
+ #
18
+ def pp(result)
19
+ header = result.columns.first
20
+ lines = result.rows.map(&:first)
21
+
22
+ # We add 2 because there's one char of padding at both sides, note
23
+ # the extra hyphens in the example above.
24
+ width = [header, *lines].map(&:length).max + 2
25
+
26
+ pp = []
27
+
28
+ pp << header.center(width).rstrip
29
+ pp << '-' * width
30
+
31
+ pp += lines.map {|line| " #{line}"}
32
+
33
+ nrows = result.rows.length
34
+ rows_label = nrows == 1 ? 'row' : 'rows'
35
+ pp << "(#{nrows} #{rows_label})"
36
+
37
+ pp.join("\n") + "\n"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,70 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Array < Type::Value # :nodoc:
6
+ include Type::Helpers::Mutable
7
+
8
+ attr_reader :subtype, :delimiter
9
+ delegate :type, :user_input_in_time_zone, :limit, to: :subtype
10
+
11
+ def initialize(subtype, delimiter = ',')
12
+ @subtype = subtype
13
+ @delimiter = delimiter
14
+
15
+ @pg_encoder = PG::TextEncoder::Array.new name: "#{type}[]", delimiter: delimiter
16
+ @pg_decoder = PG::TextDecoder::Array.new name: "#{type}[]", delimiter: delimiter
17
+ end
18
+
19
+ def deserialize(value)
20
+ if value.is_a?(::String)
21
+ type_cast_array(@pg_decoder.decode(value), :deserialize)
22
+ else
23
+ super
24
+ end
25
+ end
26
+
27
+ def cast(value)
28
+ if value.is_a?(::String)
29
+ value = @pg_decoder.decode(value)
30
+ end
31
+ type_cast_array(value, :cast)
32
+ end
33
+
34
+ def serialize(value)
35
+ if value.is_a?(::Array)
36
+ @pg_encoder.encode(type_cast_array(value, :serialize))
37
+ else
38
+ super
39
+ end
40
+ end
41
+
42
+ def ==(other)
43
+ other.is_a?(Array) &&
44
+ subtype == other.subtype &&
45
+ delimiter == other.delimiter
46
+ end
47
+
48
+ def type_cast_for_schema(value)
49
+ return super unless value.is_a?(::Array)
50
+ "[" + value.map { |v| subtype.type_cast_for_schema(v) }.join(", ") + "]"
51
+ end
52
+
53
+ def map(value, &block)
54
+ value.map(&block)
55
+ end
56
+
57
+ private
58
+
59
+ def type_cast_array(value, method)
60
+ if value.is_a?(::Array)
61
+ value.map { |item| type_cast_array(item, method) }
62
+ else
63
+ @subtype.public_send(method, value)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,52 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Bit < Type::Value # :nodoc:
6
+ def type
7
+ :bit
8
+ end
9
+
10
+ def cast(value)
11
+ if ::String === value
12
+ case value
13
+ when /^0x/i
14
+ value[2..-1].hex.to_s(2) # Hexadecimal notation
15
+ else
16
+ value # Bit-string notation
17
+ end
18
+ else
19
+ value
20
+ end
21
+ end
22
+
23
+ def serialize(value)
24
+ Data.new(super) if value
25
+ end
26
+
27
+ class Data
28
+ def initialize(value)
29
+ @value = value
30
+ end
31
+
32
+ def to_s
33
+ value
34
+ end
35
+
36
+ def binary?
37
+ /\A[01]*\Z/ === value
38
+ end
39
+
40
+ def hex?
41
+ /\A[0-9A-F]*\Z/i === value
42
+ end
43
+
44
+ protected
45
+
46
+ attr_reader :value
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class BitVarying < OID::Bit # :nodoc:
6
+ def type
7
+ :bit_varying
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Bytea < Type::Binary # :nodoc:
6
+ def deserialize(value)
7
+ return if value.nil?
8
+ return value.to_s if value.is_a?(Type::Binary::Data)
9
+ PGconn.unescape_bytea(super)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ require 'ipaddr'
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module OvirtLegacyPostgreSQL
6
+ module OID # :nodoc:
7
+ class Cidr < Type::Value # :nodoc:
8
+ def type
9
+ :cidr
10
+ end
11
+
12
+ def type_cast_for_schema(value)
13
+ subnet_mask = value.instance_variable_get(:@mask_addr)
14
+
15
+ # If the subnet mask is equal to /32, don't output it
16
+ if subnet_mask == (2**32 - 1)
17
+ "\"#{value}\""
18
+ else
19
+ "\"#{value}/#{subnet_mask.to_s(2).count('1')}\""
20
+ end
21
+ end
22
+
23
+ def serialize(value)
24
+ if IPAddr === value
25
+ "#{value}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
26
+ else
27
+ value
28
+ end
29
+ end
30
+
31
+ def cast_value(value)
32
+ if value.nil?
33
+ nil
34
+ elsif String === value
35
+ begin
36
+ IPAddr.new(value)
37
+ rescue ArgumentError
38
+ nil
39
+ end
40
+ else
41
+ value
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class DateTime < Type::DateTime # :nodoc:
6
+ def cast_value(value)
7
+ case value
8
+ when 'infinity' then ::Float::INFINITY
9
+ when '-infinity' then -::Float::INFINITY
10
+ when / BC$/
11
+ astronomical_year = format("%04d", -value[/^\d+/].to_i + 1)
12
+ super(value.sub(/ BC$/, "").sub(/^\d+/, astronomical_year))
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Decimal < Type::Decimal # :nodoc:
6
+ def infinity(options = {})
7
+ BigDecimal.new("Infinity") * (options[:negative] ? -1 : 1)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Enum < Type::Value # :nodoc:
6
+ def type
7
+ :enum
8
+ end
9
+
10
+ private
11
+
12
+ def cast_value(value)
13
+ value.to_s
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Hstore < Type::Value # :nodoc:
6
+ include Type::Helpers::Mutable
7
+
8
+ def type
9
+ :hstore
10
+ end
11
+
12
+ def deserialize(value)
13
+ if value.is_a?(::String)
14
+ ::Hash[value.scan(HstorePair).map { |k, v|
15
+ v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
16
+ k = k.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
17
+ [k, v]
18
+ }]
19
+ else
20
+ value
21
+ end
22
+ end
23
+
24
+ def serialize(value)
25
+ if value.is_a?(::Hash)
26
+ value.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(', ')
27
+ else
28
+ value
29
+ end
30
+ end
31
+
32
+ def accessor
33
+ ActiveRecord::Store::StringKeyedHashAccessor
34
+ end
35
+
36
+ private
37
+
38
+ HstorePair = begin
39
+ quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"/
40
+ unquoted_string = /(?:\\.|[^\s,])[^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*/
41
+ /(#{quoted_string}|#{unquoted_string})\s*=>\s*(#{quoted_string}|#{unquoted_string})/
42
+ end
43
+
44
+ def escape_hstore(value)
45
+ if value.nil?
46
+ 'NULL'
47
+ else
48
+ if value == ""
49
+ '""'
50
+ else
51
+ '"%s"' % value.to_s.gsub(/(["\\])/, '\\\\\1')
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Inet < Cidr # :nodoc:
6
+ def type
7
+ :inet
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Json < Type::Internal::AbstractJson
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Jsonb < Json # :nodoc:
6
+ def type
7
+ :jsonb
8
+ end
9
+
10
+ def changed_in_place?(raw_old_value, new_value)
11
+ # Postgres does not preserve insignificant whitespaces when
12
+ # round-tripping jsonb columns. This causes some false positives for
13
+ # the comparison here. Therefore, we need to parse and re-dump the
14
+ # raw value here to ensure the insignificant whitespaces are
15
+ # consistent with our encoder's output.
16
+ raw_old_value = serialize(deserialize(raw_old_value))
17
+ super(raw_old_value, new_value)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module OvirtLegacyPostgreSQL
4
+ module OID # :nodoc:
5
+ class Money < Type::Decimal # :nodoc:
6
+ def type
7
+ :money
8
+ end
9
+
10
+ def scale
11
+ 2
12
+ end
13
+
14
+ def cast_value(value)
15
+ return value unless ::String === value
16
+
17
+ # Because money output is formatted according to the locale, there are two
18
+ # cases to consider (note the decimal separators):
19
+ # (1) $12,345,678.12
20
+ # (2) $12.345.678,12
21
+ # Negative values are represented as follows:
22
+ # (3) -$2.55
23
+ # (4) ($2.55)
24
+
25
+ value.sub!(/^\((.+)\)$/, '-\1') # (4)
26
+ case value
27
+ when /^-?\D+[\d,]+\.\d{2}$/ # (1)
28
+ value.gsub!(/[^-\d.]/, '')
29
+ when /^-?\D+[\d.]+,\d{2}$/ # (2)
30
+ value.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
31
+ end
32
+
33
+ super(value)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end