schema_plus_pg_indexes 0.1.3 → 0.1.4

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: a5edee49e9450968160894f728ed3ac793c60591
4
- data.tar.gz: 57215e8659d5fa28aab3849965536b5f39c5d75c
3
+ metadata.gz: b47ec75377fc42a755d49b02bdbf4129278a94f6
4
+ data.tar.gz: c803d64e0995541267e6484e68c99d4ee68bb036
5
5
  SHA512:
6
- metadata.gz: 8189ce3e111371fc260735182c6079b432f94630df6f746f8d9cf1a46d9c6d2a73a62e3e11ebb31e2bc7f2c5a4e8eea1d067b8f3d75617c2ac3d88cef2c2486b
7
- data.tar.gz: 72f51b3d84023ffd4caec75070af3d44cce5ed7c16924ba3002b7601864b6de899ac8be8663b219deb6a7886f9c31c3a64c417657d782308891c08ebc52df1d2
6
+ metadata.gz: 0ae836dd3706cbca4b4cccf18d073375c57c38539c35c1381a44c6f4aee7c1b3a8033e33d140b423985aba7730f12aaf27ffa23dacf4355b87fd8b4430ec1d0c
7
+ data.tar.gz: f744880251c090ba35b079bd7b5d6fc42a04474b80e4d9ed3134c90438fe96312ed234d9677618f196721605c1311cb3c78058eb835912375f707050bd2f4fdb
data/.travis.yml CHANGED
@@ -10,7 +10,7 @@ gemfile:
10
10
  - gemfiles/activerecord-4.2/Gemfile.postgresql
11
11
  env: POSTGRESQL_DB_USER=postgres
12
12
  addons:
13
- postgresql: '9.3'
13
+ postgresql: '9.4'
14
14
  before_script: bundle exec rake create_databases
15
15
  after_script: bundle exec rake drop_databases
16
16
  script: bundle exec rake travis
data/README.md CHANGED
@@ -31,26 +31,8 @@ gem "schema_plus_pg_indexes" # in a Gemfile
31
31
  gem.add_dependency "schema_plus_pg_indexes" # in a .gemspec
32
32
  ```
33
33
 
34
- To use with a rails app, also include
35
-
36
- ```ruby
37
- gem "schema_monkey_rails"
38
- ```
39
-
40
- which creates a Railtie to that will insert SchemaPlus::PgIndexes appropriately into the rails stack. To use with Padrino, see [schema_monkey_padrino](https://github.com/SchemaPlus/schema_monkey_padrino).
41
-
42
34
  <!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->
43
35
 
44
- ## Compatibility
45
-
46
- schema_plus_pg_indexes is tested on
47
-
48
- <!-- SCHEMA_DEV: MATRIX - begin -->
49
- <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
50
- * ruby **2.1.5** with activerecord **4.2**, using **postgresql**
51
-
52
- <!-- SCHEMA_DEV: MATRIX - end -->
53
-
54
36
  ## Deprecations
55
37
 
56
38
  SchemaPlus 1.8.x provided some options and accessors that are now available
@@ -62,10 +44,21 @@ form:
62
44
  * `:conditions` => `:where`
63
45
  * `:kind` => `:using`
64
46
 
65
- * `IndexDefinition` deprecates accessors:
47
+ * `IndexDefinition` deprecates accessors:
66
48
  * `#conditions` in favor of `#where`
67
49
  * `#kind` in favor of `#using.to_s`
68
50
 
51
+
52
+ ## Compatibility
53
+
54
+ schema_plus_pg_indexes is tested on
55
+
56
+ <!-- SCHEMA_DEV: MATRIX - begin -->
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**
59
+
60
+ <!-- SCHEMA_DEV: MATRIX - end -->
61
+
69
62
  ## History
70
63
 
71
64
  ### v0.1.0
@@ -104,8 +97,8 @@ Some things to know about to help you develop and test:
104
97
  provides middleware callback stacks to make it easy to extend
105
98
  ActiveRecord's behavior. If that API is missing something you need for
106
99
  your contribution, please head over to
107
- [schema_plus_core](https://github/SchemaPlus/schema_plus_core) and open
108
- an issue or pull request.
100
+ [schema_plus_core](https://github.com/SchemaPlus/schema_plus_core) and open
101
+ an issue or pull request.
109
102
 
110
103
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - end -->
111
104
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - begin -->
@@ -114,6 +107,5 @@ Some things to know about to help you develop and test:
114
107
  [schema_monkey](https://github.com/SchemaPlus/schema_monkey) client,
115
108
  using [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s
116
109
  convention-based protocols for extending ActiveRecord and using middleware stacks.
117
- For more information see [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s README.
118
110
 
119
111
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - end -->
@@ -1,5 +1,4 @@
1
- require 'schema_monkey'
2
- require 'schema_plus_indexes'
1
+ require 'schema_plus/indexes'
3
2
 
4
3
  require_relative 'schema_plus_pg_indexes/active_record/connection_adapters/index_definition'
5
4
  require_relative 'schema_plus_pg_indexes/active_record/connection_adapters/postgresql_adapter'
@@ -9,4 +8,4 @@ require_relative 'schema_plus_pg_indexes/middleware/postgresql/sql'
9
8
  require_relative 'schema_plus_pg_indexes/middleware/postgresql/schema'
10
9
  require_relative 'schema_plus_pg_indexes/version'
11
10
 
12
- SchemaMonkey.register(SchemaPlusPgIndexes)
11
+ SchemaMonkey.register SchemaPlusPgIndexes
@@ -7,7 +7,7 @@ module SchemaPlusPgIndexes
7
7
 
8
8
  # Dump index extensions
9
9
  def after(env)
10
- index_defs = Dumper.get_index_defiinitions(env, env.table)
10
+ index_defs = Dumper.get_index_definitions(env, env.table)
11
11
 
12
12
  env.table.indexes.each do |index_dump|
13
13
  index_def = index_defs.find(&its.name == index_dump.name)
@@ -31,7 +31,7 @@ module SchemaPlusPgIndexes
31
31
 
32
32
  # Move index definitions inline
33
33
  def after(env)
34
- index_defs = Dumper.get_index_defiinitions(env, env.table)
34
+ index_defs = Dumper.get_index_definitions(env, env.table)
35
35
 
36
36
  env.table.indexes.select(&its.columns.blank?).each do |index|
37
37
  env.table.statements << "t.index name: #{index.name.inspect}, #{index.options}"
@@ -40,7 +40,7 @@ module SchemaPlusPgIndexes
40
40
  end
41
41
  end
42
42
 
43
- def self.get_index_defiinitions(env, table_dump)
43
+ def self.get_index_definitions(env, table_dump)
44
44
  env.dump.data.index_definitions ||= {}
45
45
  env.dump.data.index_definitions[table_dump.name] ||= env.connection.indexes(table_dump.name)
46
46
  end
@@ -53,7 +53,7 @@ module SchemaPlusPgIndexes
53
53
  end
54
54
 
55
55
  if expression
56
- env.sql.columns = expression.sub(/ ^\( (.*) \) $/x, '\1')
56
+ env.sql.columns = expression
57
57
  elsif operator_classes or case_insensitive
58
58
  option_strings = Hash[column_names.map {|name| [name, '']}]
59
59
  (operator_classes||{}).stringify_keys.each do |column, opclass|
@@ -1,3 +1,3 @@
1
1
  module SchemaPlusPgIndexes
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "activerecord", "~> 4.2"
21
- spec.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.2"
21
+ spec.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.3"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0.0"
26
- spec.add_development_dependency "schema_dev", "~> 3.1"
26
+ spec.add_development_dependency "schema_dev", "~> 3.5"
27
27
  spec.add_development_dependency "simplecov"
28
28
  spec.add_development_dependency "simplecov-gem-profile"
29
29
  end
data/spec/index_spec.rb CHANGED
@@ -7,50 +7,46 @@ describe "index" do
7
7
 
8
8
  describe "add_index" do
9
9
 
10
- before(:each) do
11
- connection.tables.each do |table| connection.drop_table table, cascade: true end
12
-
13
- define_schema do
14
- create_table :users, :force => true do |t|
15
- t.string :login
16
- t.text :address
17
- t.datetime :deleted_at
18
- end
19
-
20
- create_table :posts, :force => true do |t|
21
- t.text :body
22
- t.integer :user_id
23
- t.integer :author_id
24
- end
25
-
26
- end
27
- class User < ::ActiveRecord::Base ; end
28
- class Post < ::ActiveRecord::Base ; end
29
- end
30
-
10
+ class User < ::ActiveRecord::Base ; end
31
11
 
32
12
  after(:each) do
33
13
  migration.suppress_messages do
34
- migration.remove_index(:users, :name => @index.name) if (@index ||= nil)
14
+ User.indexes.each do |index|
15
+ migration.remove_index :users, name: index.name, if_exists: true
16
+ end
17
+ User.reset_column_information
35
18
  end
36
19
  end
37
20
 
38
21
  context "extra features" do
39
22
 
23
+ before(:each) do
24
+ connection.tables.each do |table| connection.drop_table table, cascade: true end
25
+
26
+ define_schema do
27
+ create_table :users, :force => true do |t|
28
+ t.string :login
29
+ t.text :address
30
+ t.jsonb :json_col
31
+ t.datetime :deleted_at
32
+ end
33
+ end
34
+ end
35
+
40
36
  it "should assign expression, where and using" do
41
37
  add_index(:users, :expression => "USING hash (upper(login)) WHERE deleted_at IS NULL", :name => 'users_login_index')
42
- @index = User.indexes.detect { |i| i.expression.present? }
43
- expect(@index.expression).to eq("upper((login)::text)")
44
- expect(@index.where).to eq("(deleted_at IS NULL)")
45
- expect(@index.using).to eq(:hash)
38
+ index = User.indexes.detect { |i| i.expression.present? }
39
+ expect(index.expression).to eq("upper((login)::text)")
40
+ expect(index.where).to eq("(deleted_at IS NULL)")
41
+ expect(index.using).to eq(:hash)
46
42
  end
47
43
 
48
44
  it "should allow to specify expression, where and using separately" do
49
45
  add_index(:users, :using => "hash", :expression => "upper(login)", :where => "deleted_at IS NULL", :name => 'users_login_index')
50
- @index = User.indexes.detect { |i| i.expression.present? }
51
- expect(@index.expression).to eq("upper((login)::text)")
52
- expect(@index.where).to eq("(deleted_at IS NULL)")
53
- expect(@index.using).to eq(:hash)
46
+ index = User.indexes.detect { |i| i.expression.present? }
47
+ expect(index.expression).to eq("upper((login)::text)")
48
+ expect(index.where).to eq("(deleted_at IS NULL)")
49
+ expect(index.using).to eq(:hash)
54
50
  end
55
51
 
56
52
  it "should assign operator_class" do
@@ -65,8 +61,14 @@ describe "index" do
65
61
 
66
62
  it "should allow to specify actual expression only" do
67
63
  add_index(:users, :expression => "upper(login)", :name => 'users_login_index')
68
- @index = User.indexes.detect { |i| i.name == 'users_login_index' }
69
- expect(@index.expression).to eq("upper((login)::text)")
64
+ index = User.indexes.detect { |i| i.name == 'users_login_index' }
65
+ expect(index.expression).to eq("upper((login)::text)")
66
+ end
67
+
68
+ it "should create proper sql with jsonb expressions (schema_plus #212)" do
69
+ add_index :users, :name => "json_expression", :using => :gin, :expression => "(json_col -> 'field')"
70
+ index = User.indexes.detect(&its.name == "json_expression")
71
+ expect(index.expression).to eq("(json_col -> 'field'::text)")
70
72
  end
71
73
 
72
74
  it "should raise if no column given and expression is missing" do
@@ -98,7 +100,7 @@ describe "index" do
98
100
  protected
99
101
 
100
102
  def index_for(column_names)
101
- @index = User.indexes.detect { |i| i.columns == Array(column_names).collect(&:to_s) }
103
+ User.indexes.detect { |i| i.columns == Array(column_names).collect(&:to_s) }
102
104
  end
103
105
 
104
106
  end
@@ -6,7 +6,7 @@ describe "Schema dump" do
6
6
  before(:all) do
7
7
  ActiveRecord::Migration.suppress_messages do
8
8
  ActiveRecord::Schema.define do
9
- connection.tables.each do |table| drop_table table, :cascade => true end
9
+ connection.tables.each do |table| drop_table table, force: :cascade end
10
10
 
11
11
  create_table :users, :force => true do |t|
12
12
  t.string :login
@@ -98,6 +98,12 @@ describe "Schema dump" do
98
98
  end
99
99
  end
100
100
 
101
+ it 'should dump proper operator_class with case_sensitive => false' do
102
+ with_index Post, :body, :operator_class => 'text_pattern_ops', :case_sensitive => false do
103
+ expect(dump_posts).to match(/body.*index:.*name: "index_posts_on_body", case_sensitive: false, operator_class: "text_pattern_ops"/)
104
+ end
105
+ end
106
+
101
107
  it "should dump unique: true with expression (Issue #142)" do
102
108
  with_index Post, :name => "posts_user_body_index", :unique => true, :expression => "BTRIM(LOWER(body))" do
103
109
  expect(dump_posts).to include(%q{t.index name: "posts_user_body_index", unique: true, expression: "btrim(lower(body))"})
data/spec/spec_helper.rb CHANGED
@@ -23,7 +23,7 @@ def define_schema(&block)
23
23
  ActiveRecord::Migration.suppress_messages do
24
24
  ActiveRecord::Schema.define do
25
25
  connection.tables.each do |table|
26
- drop_table table, :cascade => true
26
+ drop_table table, force: :cascade
27
27
  end
28
28
  instance_eval &block
29
29
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0.1'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.1.2
36
+ version: 0.1.3
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.1'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.1.2
46
+ version: 0.1.3
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '3.1'
95
+ version: '3.5'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '3.1'
102
+ version: '3.5'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: simplecov
105
105
  requirement: !ruby/object:Gem::Requirement