schema_plus_pg_indexes 0.1.12 → 0.2.0

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: dce15f060c1c297e62d79ec6a9686344e0b369d7
4
- data.tar.gz: 57f3ec5dcef7f3830336fa14d9a515427b6934cd
3
+ metadata.gz: a32103d4c7753e4551e51ed658016996e2cdc180
4
+ data.tar.gz: edf9dddc470db8759c183b18d33df4f649dc32f1
5
5
  SHA512:
6
- metadata.gz: e1d3b38c63cf9a3c8a76adc1164ad0ef0c23d10a892469b109ef264974ae3bef546ffee9fc848700f2d2d4521f3ce9ad67a49d6395b158c509b4051c461b024f
7
- data.tar.gz: e524a633fe1e45e3a67fe10895890e39b2c1967b3941a2c38d1fc73957b090cb0d3e36b8c4001b7623e6caafc08a14d8445b5797c37005458a51370997775120
6
+ metadata.gz: 3e304b33918637897b17bb7518f6d962849ed17a2a1606a994a7159c3d9f4a1489abbb8f1d174660c896f3f4f44cfe0083f8480f74cab6b925062e14ae1f0e7a
7
+ data.tar.gz: 774d15bd7fce97f4d39926310c36457861bb44533219b19a9a5f936e8eca9d40e00ded2e9b871971c2fe0209e7271c8eaacdc9f29905e903a9d5d80f0ade2299
data/.travis.yml CHANGED
@@ -5,9 +5,9 @@
5
5
  ---
6
6
  sudo: false
7
7
  rvm:
8
- - 2.1.5
8
+ - 2.3.1
9
9
  gemfile:
10
- - gemfiles/activerecord-4.2/Gemfile.postgresql
10
+ - gemfiles/activerecord-5.0/Gemfile.postgresql
11
11
  env: POSTGRESQL_DB_USER=postgres
12
12
  addons:
13
13
  postgresql: '9.4'
data/README.md CHANGED
@@ -55,12 +55,13 @@ schema_plus_pg_indexes is tested on
55
55
 
56
56
  <!-- SCHEMA_DEV: MATRIX - begin -->
57
57
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
58
- * ruby **2.1.5** with activerecord **4.2**, using **postgresql**
58
+ * ruby **2.3.1** with activerecord **5.0**, using **postgresql**
59
59
 
60
60
  <!-- SCHEMA_DEV: MATRIX - end -->
61
61
 
62
62
  ## History
63
63
 
64
+ * v0.2.0 - Support Rails 5 (Removed Rails 4.2 support)
64
65
  * v0.1.12 - Missing require
65
66
  * v0.1.11 - Explicit gem dependencies
66
67
  * v0.1.10 - Upgrade to schmea_plus_core 1.0
@@ -1,3 +1,3 @@
1
1
  eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gem "activerecord", "~> 4.2.6"
3
+ gem "activerecord", "~> 5.0.0"
@@ -2,44 +2,35 @@ module SchemaPlusPgIndexes
2
2
  module Middleware
3
3
  module Postgresql
4
4
  module Dumper
5
-
6
- module Indexes
5
+ module Table
7
6
 
8
7
  # Dump index extensions
9
8
  def after(env)
10
- index_defs = Dumper.get_index_definitions(env, env.table)
9
+ index_defs = env.connection.indexes(env.table.name)
11
10
 
12
- env.table.indexes.each do |index_dump|
13
- index_def = index_defs.find(&its.name == index_dump.name)
14
- index_dump.options[:case_sensitive] = false unless index_def.case_sensitive?
15
- index_dump.options[:expression] = index_def.expression if index_def.expression and index_def.case_sensitive?
11
+ def set_index_options(name, options, index_defs)
12
+ index_def = index_defs.find(&its.name == name)
13
+ options[:case_sensitive] = false unless index_def.case_sensitive?
14
+ options[:expression] = index_def.expression if index_def.expression and index_def.case_sensitive?
16
15
  unless index_def.operator_classes.blank?
17
16
  if index_def.columns.uniq.length <= 1 && index_def.operator_classes.values.uniq.length == 1
18
- index_dump.options[:operator_class] = index_def.operator_classes.values.first
17
+ options[:operator_class] = index_def.operator_classes.values.first
19
18
  else
20
- index_dump.options[:operator_class] = index_def.operator_classes
19
+ options[:operator_class] = index_def.operator_classes
21
20
  end
22
21
  end
23
22
  end
24
- end
25
- end
26
23
 
27
- module Table
28
-
29
- # Move index definitions inline
30
- def after(env)
31
- index_defs = Dumper.get_index_definitions(env, env.table)
24
+ env.table.columns.each do |column_dump|
25
+ index = column_dump.options[:index]
26
+ set_index_options(index[:name], index, index_defs) if index
27
+ end
32
28
 
33
- env.table.indexes.select(&its.columns.blank?).each do |index|
34
- env.table.statements << "t.index #{{name: index.name}.merge(index.options).to_s.sub(/^{(.*)}$/, '\1')}"
35
- env.table.indexes.delete(index)
29
+ env.table.indexes.each do |index_dump|
30
+ set_index_options(index_dump.name, index_dump.options, index_defs)
36
31
  end
37
32
  end
38
- end
39
33
 
40
- def self.get_index_definitions(env, table_dump)
41
- env.dump.data.index_definitions ||= {}
42
- env.dump.data.index_definitions[table_dump.name] ||= env.connection.indexes(table_dump.name)
43
34
  end
44
35
  end
45
36
  end
@@ -53,7 +53,7 @@ module SchemaPlusPgIndexes
53
53
 
54
54
  env.index_definitions += result.map do |(index_name, unique, indkey, inddef, oid, using, conditions, expression, indclass)|
55
55
  index_keys = indkey.split(" ")
56
- opclasses = indclass.split(" ")
56
+ opclasses = indclass.split(" ").map(&:to_i)
57
57
 
58
58
  rows = env.connection.query(<<-SQL, 'SCHEMA')
59
59
  SELECT CAST(a.attnum as VARCHAR), a.attname, t.typname
@@ -98,14 +98,14 @@ module SchemaPlusPgIndexes
98
98
  orders = desc_order_columns.any? ? Hash[column_names.map {|column| [column, desc_order_columns.include?(column) ? :desc : :asc]}] : {}
99
99
 
100
100
  ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(env.table_name, column_names,
101
- :name => index_name,
102
- :unique => (unique == 't'),
103
- :orders => orders,
104
- :where => conditions,
105
- :case_sensitive => case_sensitive,
106
- :using => using.downcase == "btree" ? nil : using.to_sym,
107
- :operator_classes => operator_classes,
108
- :expression => expression)
101
+ name: index_name,
102
+ unique: unique,
103
+ orders: orders,
104
+ where: conditions,
105
+ case_sensitive: case_sensitive,
106
+ using: using.downcase == "btree" ? nil : using.to_sym,
107
+ operator_classes: operator_classes,
108
+ expression: expression)
109
109
  end
110
110
  end
111
111
 
@@ -1,3 +1,3 @@
1
1
  module SchemaPlusPgIndexes
2
- VERSION = "0.1.12"
2
+ VERSION = "0.2.0"
3
3
  end
data/schema_dev.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  ruby:
2
- - 2.1.5
2
+ - 2.3.1
3
3
  activerecord:
4
- - 4.2
4
+ - 5.0
5
5
  db:
6
6
  - postgresql
@@ -17,9 +17,9 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "activerecord", "~> 4.2"
21
- gem.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.3"
22
- gem.add_dependency "schema_plus_core", "~> 1.0"
20
+ gem.add_dependency "activerecord", "~> 5.0"
21
+ gem.add_dependency "schema_plus_indexes", "~> 0.2", ">= 0.2.4"
22
+ gem.add_dependency "schema_plus_core", "~> 2.0"
23
23
  gem.add_dependency "its-it", "~> 1.2"
24
24
 
25
25
  gem.add_development_dependency "bundler", "~> 1.7"
@@ -54,7 +54,7 @@ describe "Schema dump" do
54
54
 
55
55
  it "should define index with type cast" do
56
56
  with_index Post, [:integer_col], :name => "index_with_type_cast", :expression => "LOWER(integer_col::text)" do
57
- expect(dump_posts).to include(%q{t.index :name=>"index_with_type_cast", :expression=>"lower((integer_col)::text)"})
57
+ expect(dump_posts).to include(%q{t.index [], :name=>"index_with_type_cast", :expression=>"lower((integer_col)::text)"})
58
58
  end
59
59
  end
60
60
 
@@ -82,7 +82,7 @@ describe "Schema dump" do
82
82
 
83
83
  it "should define expression" do
84
84
  with_index Post, :name => "posts_freaky_index", :expression => "USING hash (least(id, user_id))" do
85
- expect(dump_posts).to include(%q{t.index :name=>"posts_freaky_index", :using=>:hash, :expression=>"LEAST(id, user_id)"})
85
+ expect(dump_posts).to include(%q{t.index [], :name=>"posts_freaky_index", :using=>:hash, :expression=>"LEAST(id, user_id)"})
86
86
  end
87
87
  end
88
88
 
@@ -101,7 +101,7 @@ describe "Schema dump" do
101
101
 
102
102
  it "should define expression with operator_class" do
103
103
  with_index Post, :name => "expr_with_opclass", :expression => "upper(str_short || string_no_default)", :operator_class => 'text_pattern_ops' do
104
- expect(dump_posts).to include(%q{t.index :name=>"expr_with_opclass", :expression=>"upper(((str_short)::text || (string_no_default)::text))", :operator_class=>"text_pattern_ops"})
104
+ expect(dump_posts).to include(%q{t.index [], :name=>"expr_with_opclass", :expression=>"upper(((str_short)::text || (string_no_default)::text))", :operator_class=>"text_pattern_ops"})
105
105
  end
106
106
  end
107
107
 
@@ -126,14 +126,14 @@ describe "Schema dump" do
126
126
 
127
127
  it "should dump unique: true with expression (Issue #142)" do
128
128
  with_index Post, :name => "posts_user_body_index", :unique => true, :expression => "BTRIM(LOWER(body))" do
129
- expect(dump_posts).to include(%q{t.index :name=>"posts_user_body_index", :unique=>true, :expression=>"btrim(lower(body))"})
129
+ expect(dump_posts).to include(%q{t.index [], :name=>"posts_user_body_index", :unique=>true, :expression=>"btrim(lower(body))"})
130
130
  end
131
131
  end
132
132
 
133
133
 
134
134
  it "should not define :case_sensitive => false with non-trivial expression" do
135
135
  with_index Post, :name => "posts_user_body_index", :expression => "BTRIM(LOWER(body))" do
136
- expect(dump_posts).to include(%q{t.index :name=>"posts_user_body_index", :expression=>"btrim(lower(body))"})
136
+ expect(dump_posts).to include(%q{t.index [], :name=>"posts_user_body_index", :expression=>"btrim(lower(body))"})
137
137
  end
138
138
  end
139
139
 
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.1.12
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,48 +16,48 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: schema_plus_indexes
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.2'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.1.3
36
+ version: 0.2.4
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '0.1'
43
+ version: '0.2'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.1.3
46
+ version: 0.2.4
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: schema_plus_core
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.0'
53
+ version: '2.0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '1.0'
60
+ version: '2.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: its-it
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -170,8 +170,8 @@ files:
170
170
  - README.md
171
171
  - Rakefile
172
172
  - gemfiles/Gemfile.base
173
- - gemfiles/activerecord-4.2/Gemfile.base
174
- - gemfiles/activerecord-4.2/Gemfile.postgresql
173
+ - gemfiles/activerecord-5.0/Gemfile.base
174
+ - gemfiles/activerecord-5.0/Gemfile.postgresql
175
175
  - lib/schema_plus_pg_indexes.rb
176
176
  - lib/schema_plus_pg_indexes/active_record/connection_adapters/index_definition.rb
177
177
  - lib/schema_plus_pg_indexes/active_record/connection_adapters/postgresql_adapter.rb
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.2.2
213
+ rubygems_version: 2.5.1
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: Adds support in ActiveRecord for PostgreSQL index expressions and operator