schema_plus_pg_indexes 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90cf88d2c3f18bd96b37a1e8f3992d3aab05279e
4
- data.tar.gz: 49d6ff69c0bde3a80ec17e74c7a8404b46eb3e11
3
+ metadata.gz: 5586f2b3408a3890cc6967d852d27ce9644380f7
4
+ data.tar.gz: 7d22c43ab14375ce9b48106e2e380f1d19ed6564
5
5
  SHA512:
6
- metadata.gz: 752811cfa4644870286808f4662ac4e1178d81f2de43745a7d1b438f35a782a5a5f54a9059f4e55896a90ec1be3077cfd9065489f341c112d22042f34b66435f
7
- data.tar.gz: f865110fc609f48e0965765b4c8220d8e5494389ae27522deebfbca6141b29afa88daeab02dd8bd9e6ebc3dc45e26dfa4e6370801f5e9488de57e753673819e2
6
+ metadata.gz: a0e0425e6f627918c211b4ece0f892088dd1d4446a19dd26fac39bc26d10aebcae04acbe69f9d7d1a5c1a842242a6353de444c4a8eab448abaf61c03d8f90af3
7
+ data.tar.gz: e075301f4c44a74edf3bfe577663caeed80afb1288764e5c54ce88bb2c16fdd05be173cfdf1b671e2b2520689547de03b6791a730d19d8732422baa459c82be2
data/README.md CHANGED
@@ -62,6 +62,7 @@ schema_plus_pg_indexes is tested on
62
62
 
63
63
  ## Release Notes
64
64
 
65
+ * v0.3.1 - Bug fix: schema dump for complex order clause (#19). Thanks to [@joxxoxo](https://github.com/joxxoxo).
65
66
  * v0.3.0 - Added Rails 5.1.0 support
66
67
  * v0.2.1 - Added Rails 5.0.1 support (Removed Rails 5.0.0 support)
67
68
  * v0.2.0 - Added Rails 5 support (Removed Rails 4.2 support)
@@ -93,9 +93,16 @@ module SchemaPlusPgIndexes
93
93
  ]
94
94
  operator_classes.delete_if{|k,v| v.nil?}
95
95
 
96
- # add info on sort order for columns (only desc order is explicitly specified, asc is the default)
97
- desc_order_columns = inddef.scan(/(\w+) DESC/).flatten
98
- orders = desc_order_columns.any? ? Hash[column_names.map {|column| [column, desc_order_columns.include?(column) ? :desc : :asc]}] : {}
96
+ orders = {}
97
+ order_clause = inddef[/\((\w+[^)]+)\)\z/, 1]
98
+ if order_clause && (using.downcase == "btree")
99
+ order_clause.split(/,\s+/).each do |order_by_column|
100
+ match = /\A(\w+)\s*(.+)?\z/.match(order_by_column)
101
+ column, order = match[1], match[2] || 'asc'
102
+ order = order.downcase.to_sym if order && order =~ /\A(desc|asc)\z/i
103
+ orders[column] = order
104
+ end
105
+ end
99
106
 
100
107
  ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(env.table_name, column_names,
101
108
  name: index_name,
@@ -1,3 +1,3 @@
1
1
  module SchemaPlusPgIndexes
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -130,6 +130,33 @@ describe "Schema dump" do
130
130
  end
131
131
  end
132
132
 
133
+ it "should define index with order" do
134
+ with_index Post, [:str_short], order: 'desc' do
135
+ potential_lines = dump_posts.each_line.grep(/str_short/).join.strip
136
+ expect(potential_lines).to match(/t\.string\s+"str_short",\s+:index=>{:name=>"index_posts_on_str_short", :order=>{.*str_short.*=>:desc}}/)
137
+ end
138
+ end
139
+
140
+ it "should define index with order for multiple columns" do
141
+ with_index Post, [:str_short, :string_no_default], order: { str_short: :desc, string_no_default: :asc } do
142
+ potential_lines = dump_posts.each_line.grep(/str_short/).join.strip
143
+ expect(potential_lines).to match(/t\.string\s+"str_short",\s+:index=>{[^}]+:order=>{.*str_short.*=>:desc, .*string_no_default.*=>:asc}}/)
144
+ end
145
+ end
146
+
147
+ it "should define index with order with NULLS specified" do
148
+ with_index Post, [:str_short], order: 'desc NULLS LAST' do
149
+ potential_lines = dump_posts.each_line.grep(/str_short/).join.strip
150
+ expect(potential_lines).to match(/t\.string\s+"str_short",\s+:index=>{[^}]+:order=>{.*str_short.*=>"DESC NULLS LAST"}}/)
151
+ end
152
+ end
153
+
154
+ it "should define index with order with NULLS specified for multiple columns" do
155
+ with_index Post, [:str_short, :string_no_default], order: { str_short: 'desc NULLS LAST', string_no_default: :desc } do
156
+ potential_lines = dump_posts.each_line.grep(/str_short/).join.strip
157
+ expect(potential_lines).to match(/t\.string\s+"str_short",\s+:index=>{[^}]+:order=>{.*str_short.*=>"DESC NULLS LAST", .*string_no_default.*=>:desc}}/)
158
+ end
159
+ end
133
160
 
134
161
  it "should not define :case_sensitive => false with non-trivial expression" do
135
162
  with_index Post, :name => "posts_user_body_index", :expression => "BTRIM(LOWER(body))" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_pg_indexes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-24 00:00:00.000000000 Z
11
+ date: 2017-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord