pg_saurus 3.7.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0699c08577482320986e7c3c11746ec17ab377ac8adba585cc583352fbe018bc'
4
- data.tar.gz: b1839cae5b6259986dfbbcb56682d856acb25dde4a3c4d1244c70437df225f81
3
+ metadata.gz: ac3e7bc1ed09c54ead47c936f659d1976deca96b498347b748de3411969bbd84
4
+ data.tar.gz: 1c0dbd26312b9cbde30f6fd7a659fa6760b3d7800f092828d9e81542fa5ceb2c
5
5
  SHA512:
6
- metadata.gz: ab4b6daefe71da060aaf4d44ad007cdb2796a2062a65f6d0f3e6f59cba12387de295b8c42241cf74bea9422f5d0857650411918d2d6f6c05a9a79c3fc9bbf165
7
- data.tar.gz: b693cf128dad8b392c9380a3b260c9c73a6ee21685a9ca6b26853abf3be535b852e07737887eec7ab2026c73e61959b19d42f61d529966478ba274a15478fb05
6
+ metadata.gz: 5b2fdd24acf0bbe74f4607f9d189fb90054c4f92092508a390323c0f320d8364f74638b0ff64f358a287ccc20bca78bbd63ed826018387fd7e6b6841afe7efa1
7
+ data.tar.gz: 3e53da8b488c17cfc6f0c168aa59c21d93dc4a1796423efe85cbc36c84b47448ff26cde61f851c24f5faed176fc39202ef383e70d5228975d326fad556728e22
@@ -9,6 +9,12 @@ module ActiveRecord # :nodoc:
9
9
  # Regex to find where clause in index statements
10
10
  INDEX_WHERE_EXPRESSION = /WHERE (.+)$/
11
11
 
12
+ # Taken from https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_index.h#L75
13
+ # Values are in reverse order
14
+ INDOPTION_DESC = 1
15
+ # NULLs are first instead of last
16
+ INDOPTION_NULLS_FIRST = 2
17
+
12
18
  # Returns the list of all tables in the schema search path or a specified schema.
13
19
  #
14
20
  # == Patch:
@@ -71,7 +77,14 @@ module ActiveRecord # :nodoc:
71
77
  schemas = schema ? "ARRAY['#{schema}']" : 'current_schemas(false)'
72
78
 
73
79
  result = query(<<-SQL, name)
74
- SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid, am.amname, d.indclass
80
+ SELECT distinct i.relname,
81
+ d.indisunique,
82
+ d.indkey,
83
+ pg_get_indexdef(d.indexrelid),
84
+ t.oid,
85
+ am.amname,
86
+ d.indclass,
87
+ d.indoption
75
88
  FROM pg_class t
76
89
  INNER JOIN pg_index d ON t.oid = d.indrelid
77
90
  INNER JOIN pg_class i ON d.indexrelid = i.oid
@@ -91,7 +104,8 @@ module ActiveRecord # :nodoc:
91
104
  :definition => row[3],
92
105
  :id => row[4],
93
106
  :access_method => row[5],
94
- :operators => row[6].split(" ")
107
+ :operators => row[6].split(" "),
108
+ :options => row[7].split(" ").map(&:to_i)
95
109
  }
96
110
 
97
111
  column_names = find_column_names(table_name, index)
@@ -140,6 +154,25 @@ module ActiveRecord # :nodoc:
140
154
  remove_type(functional_name)
141
155
  end
142
156
  end
157
+ else
158
+ # In case if column_names if not empty it contains list of column name taken from pg_attribute table.
159
+ # So we need to check indoption column and add DESC and NULLS LAST based on its value.
160
+ # https://stackoverflow.com/questions/18121103/how-to-get-the-index-column-orderasc-desc-nulls-first-from-postgresql/18128457#18128457
161
+ column_names = column_names.map.with_index do |column_name, column_index|
162
+ option = index[:options][column_index]
163
+
164
+ if option != 0
165
+ column_name << " DESC" if option & INDOPTION_DESC > 0
166
+
167
+ if option & INDOPTION_NULLS_FIRST > 0
168
+ column_name << " NULLS FIRST"
169
+ else
170
+ column_name << " NULLS LAST"
171
+ end
172
+ end
173
+
174
+ column_name
175
+ end
143
176
  end
144
177
 
145
178
  column_names
@@ -1,4 +1,4 @@
1
1
  module PgSaurus
2
2
  # Version of pg_saurus gem.
3
- VERSION = "3.7.0"
3
+ VERSION = "3.7.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_saurus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Potapov Sergey
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-09-17 00:00:00.000000000 Z
16
+ date: 2019-10-18 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: pg