schema_plus_pg_indexes 0.1.2 → 0.1.3

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: b2b5b828916853a511caa4f8b19f8a7e79fe8442
4
- data.tar.gz: 5ff7110ccc48476917619787863700670b89c0f7
3
+ metadata.gz: a5edee49e9450968160894f728ed3ac793c60591
4
+ data.tar.gz: 57215e8659d5fa28aab3849965536b5f39c5d75c
5
5
  SHA512:
6
- metadata.gz: bbab6a29c45ba788aaf81951efa439b3e9ce2f4de676db318393a1edf08fdeea3e3d3d0098cbe986e912ef6381f20e5850829235e3d097abc52522e7a1abbdd8
7
- data.tar.gz: 9ab3c857047c7e6627e3d0888aef4c9b6060f63810e72c2994d05673eb659d52deeb243a98535e9f3861a8780af5a4663dd299b5f7fd53c3fe300299a5eab065
6
+ metadata.gz: 8189ce3e111371fc260735182c6079b432f94630df6f746f8d9cf1a46d9c6d2a73a62e3e11ebb31e2bc7f2c5a4e8eea1d067b8f3d75617c2ac3d88cef2c2486b
7
+ data.tar.gz: 72f51b3d84023ffd4caec75070af3d44cce5ed7c16924ba3002b7601864b6de899ac8be8663b219deb6a7886f9c31c3a64c417657d782308891c08ebc52df1d2
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@
5
5
  ---
6
6
  sudo: false
7
7
  rvm:
8
- - 1.9.3
9
8
  - 2.1.5
10
9
  gemfile:
11
10
  - gemfiles/activerecord-4.2/Gemfile.postgresql
data/README.md CHANGED
@@ -22,18 +22,31 @@ Schema_plus_pg_indexes is part of the [SchemaPlus](https://github.com/SchemaPlus
22
22
 
23
23
  ## Installation
24
24
 
25
- In your application's Gemfile
25
+ <!-- SCHEMA_DEV: TEMPLATE INSTALLATION - begin -->
26
+ <!-- These lines are auto-inserted from a schema_dev template -->
27
+ As usual:
26
28
 
27
29
  ```ruby
28
- gem "schema_plus_pg_indexes"
30
+ gem "schema_plus_pg_indexes" # in a Gemfile
31
+ gem.add_dependency "schema_plus_pg_indexes" # in a .gemspec
29
32
  ```
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
+ <!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->
43
+
30
44
  ## Compatibility
31
45
 
32
46
  schema_plus_pg_indexes is tested on
33
47
 
34
48
  <!-- SCHEMA_DEV: MATRIX - begin -->
35
49
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
36
- * ruby **1.9.3** with activerecord **4.2**, using **postgresql**
37
50
  * ruby **2.1.5** with activerecord **4.2**, using **postgresql**
38
51
 
39
52
  <!-- SCHEMA_DEV: MATRIX - end -->
@@ -66,8 +79,10 @@ the standard protocol: fork, feature branch, develop, push, and issue pull reque
66
79
 
67
80
  Some things to know about to help you develop and test:
68
81
 
69
- * **schema_dev**: schema_plus_pg_indexes uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
70
- facilitate running rspec tests on the matrix of ruby, rails, and database
82
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - begin -->
83
+ <!-- These lines are auto-inserted from a schema_dev template -->
84
+ * **schema_dev**: SchemaPlus::PgIndexes uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
85
+ facilitate running rspec tests on the matrix of ruby, activerecord, and database
71
86
  versions that the gem supports, both locally and on
72
87
  [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus_pg_indexes)
73
88
 
@@ -76,15 +91,29 @@ Some things to know about to help you develop and test:
76
91
  $ schema_dev bundle install
77
92
  $ schema_dev rspec
78
93
 
79
- You can also run on just one configuration at a time; For info, see `schema_dev --help` or the
80
- [schema_dev](https://github.com/SchemaPlus/schema_dev) README.
94
+ You can also run on just one configuration at a time; For info, see `schema_dev --help` or the [schema_dev](https://github.com/SchemaPlus/schema_dev) README.
81
95
 
82
96
  The matrix of configurations is specified in `schema_dev.yml` in
83
97
  the project root.
84
98
 
85
- * **schema_monkey**: schema_plus_pg_indexes extends ActiveRecord using
86
- [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s extension
87
- API and protocols -- see its README for details. If your contribution needs any additional monkey patching
88
- that isn't already supported by
89
- [schema_monkey](https://github.com/SchemaPlus/schema_monkey), please head
90
- over there and submit a PR.
99
+
100
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
101
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin -->
102
+ <!-- These lines are auto-inserted from a schema_dev template -->
103
+ * **schema_plus_core**: SchemaPlus::PgIndexes uses the SchemaPlus::Core API that
104
+ provides middleware callback stacks to make it easy to extend
105
+ ActiveRecord's behavior. If that API is missing something you need for
106
+ your contribution, please head over to
107
+ [schema_plus_core](https://github/SchemaPlus/schema_plus_core) and open
108
+ an issue or pull request.
109
+
110
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - end -->
111
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - begin -->
112
+ <!-- These lines are auto-inserted from a schema_dev template -->
113
+ * **schema_monkey**: SchemaPlus::PgIndexes is implemented as a
114
+ [schema_monkey](https://github.com/SchemaPlus/schema_monkey) client,
115
+ using [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s
116
+ 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
+
119
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - end -->
@@ -1,8 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec :path => File.expand_path('..', __FILE__)
3
3
 
4
- platform :ruby do
5
- gem "byebug" if RUBY_VERSION > "2"
6
- end
7
-
8
4
  File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
@@ -2,9 +2,11 @@ require 'schema_monkey'
2
2
  require 'schema_plus_indexes'
3
3
 
4
4
  require_relative 'schema_plus_pg_indexes/active_record/connection_adapters/index_definition'
5
+ require_relative 'schema_plus_pg_indexes/active_record/connection_adapters/postgresql_adapter'
5
6
  require_relative 'schema_plus_pg_indexes/middleware/postgresql/dumper'
6
7
  require_relative 'schema_plus_pg_indexes/middleware/postgresql/migration'
7
- require_relative 'schema_plus_pg_indexes/middleware/postgresql/query'
8
+ require_relative 'schema_plus_pg_indexes/middleware/postgresql/sql'
9
+ require_relative 'schema_plus_pg_indexes/middleware/postgresql/schema'
8
10
  require_relative 'schema_plus_pg_indexes/version'
9
11
 
10
12
  SchemaMonkey.register(SchemaPlusPgIndexes)
@@ -6,10 +6,6 @@ module SchemaPlusPgIndexes
6
6
  # case sensitivity, expessions, and operator classes
7
7
  module IndexDefinition
8
8
 
9
- def self.included(base)
10
- base.alias_method_chain :initialize, :schema_plus_pg_indexes
11
- end
12
-
13
9
  attr_accessor :expression
14
10
  attr_accessor :operator_classes
15
11
 
@@ -27,8 +23,8 @@ module SchemaPlusPgIndexes
27
23
  using.to_s
28
24
  end
29
25
 
30
- def initialize_with_schema_plus_pg_indexes(*args)
31
- initialize_without_schema_plus_pg_indexes(*args)
26
+ def initialize(*args)
27
+ super
32
28
  options = args.dup.extract_options!
33
29
  @expression = options[:expression]
34
30
  @operator_classes = options[:operator_classes] || {}
@@ -36,7 +32,7 @@ module SchemaPlusPgIndexes
36
32
  end
37
33
 
38
34
  def ==(other)
39
- return false if not super(other) # can use super here because == is defined in SchemaPlusIndexes which was included before us
35
+ return false if not super other
40
36
  return false unless self.expression == other.expression
41
37
  return false unless !!self.case_sensitive? == !!other.case_sensitive?
42
38
  return false unless self.operator_classes == other.operator_classes
@@ -0,0 +1,17 @@
1
+ module SchemaPlusPgIndexes
2
+ module ActiveRecord
3
+ module ConnectionAdapters
4
+ module PostgresqlAdapter
5
+ #
6
+ # SchemaPlusPgIndexes allows the column_names paramter
7
+ # to be left off
8
+ #
9
+ def add_index(*args)
10
+ options = args.extract_options!
11
+ table_name, column_names = args
12
+ super table_name, column_names, options
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,10 +2,6 @@ module SchemaPlusPgIndexes
2
2
  module Middleware
3
3
  module Postgresql
4
4
  module Migration
5
- def self.insert
6
- SchemaMonkey::Middleware::Migration::Index.prepend DeprecateArgs
7
- SchemaMonkey::Middleware::Migration::IndexComponentsSql.append DefineExtensions
8
- end
9
5
 
10
6
  module Index
11
7
  # Deprecate args
@@ -19,77 +15,6 @@ module SchemaPlusPgIndexes
19
15
  end
20
16
  end
21
17
 
22
- module IndexComponentsSql
23
-
24
- # SchemaPlusPgIndexes provides the following extra options for PostgreSQL
25
- # indexes:
26
- # * +:expression+ - SQL expression to index. column_name can be nil or ommitted, in which case :name must be provided
27
- # * +:operator_class+ - an operator class name or a hash mapping column name to operator class name
28
- # * +:case_sensitive - setting to +false+ is a shorthand for :expression => 'LOWER(column_name)'
29
- #
30
- # The <tt>:case_sensitive => false</tt> option ties in with Rails built-in support for case-insensitive searching:
31
- # validates_uniqueness_of :name, :case_sensitive => false
32
- #
33
- # Since since <tt>:case_sensitive => false</tt> is implemented by
34
- # using <tt>:expression</tt>, this raises an ArgumentError if both
35
- # are specified simultaneously.
36
- #
37
- def around(env)
38
- options = env.options
39
- column_names = env.column_names
40
- table_name = env.table_name
41
- connection = env.connection
42
-
43
- if env.column_names.empty?
44
- raise ArgumentError, "No columns and :expression missing from options - cannot create index" unless options[:expression]
45
- raise ArgumentError, "No columns, and index name not given. Pass :name option" unless options[:name]
46
- end
47
-
48
- expression = options.delete(:expression)
49
- operator_classes = options.delete(:operator_class)
50
- case_insensitive = (options.delete(:case_sensitive) == false)
51
-
52
- if expression
53
- raise ArgumentError, "Cannot specify :case_sensitive => false with an expression. Use LOWER(column_name)" if case_insensitive
54
- expression.strip!
55
- if m = expression.match(/^using\s+(?<using>\S+)\s*(?<rest>.*)/i)
56
- options[:using] = m[:using]
57
- expression = m[:rest]
58
- end
59
- if m = expression.match(/^(?<rest>.*)\s+where\s+(?<where>.*)/i)
60
- options[:where] = m[:where]
61
- expression = m[:rest]
62
- end
63
- end
64
-
65
- yield env
66
-
67
- if operator_classes and not operator_classes.is_a? Hash
68
- operator_classes = Hash[column_names.map {|name| [name, operator_classes]}]
69
- end
70
-
71
- if expression
72
- env.sql.columns = expression.sub(/ ^\( (.*) \) $/x, '\1')
73
- elsif operator_classes or case_insensitive
74
- option_strings = Hash[column_names.map {|name| [name, '']}]
75
- (operator_classes||{}).stringify_keys.each do |column, opclass|
76
- option_strings[column] += " #{opclass}" if opclass
77
- end
78
- option_strings = connection.send :add_index_sort_order, option_strings, column_names, options
79
-
80
- if case_insensitive
81
- caseable_columns = connection.columns(table_name).select { |col| [:string, :text].include?(col.type) }.map(&:name)
82
- quoted_column_names = column_names.map do |col_name|
83
- (caseable_columns.include?(col_name.to_s) ? "LOWER(#{connection.quote_column_name(col_name)})" : connection.quote_column_name(col_name)) + option_strings[col_name]
84
- end
85
- else
86
- quoted_column_names = column_names.map { |col_name| connection.quote_column_name(col_name) + option_strings[col_name] }
87
- end
88
-
89
- env.sql.columns = quoted_column_names.join(', ')
90
- end
91
- end
92
- end
93
18
  end
94
19
  end
95
20
  end
@@ -1,7 +1,7 @@
1
1
  module SchemaPlusPgIndexes
2
2
  module Middleware
3
3
  module Postgresql
4
- module Query
4
+ module Schema
5
5
  module Indexes
6
6
 
7
7
  def get_opclass_names(env, opclasses)
@@ -0,0 +1,80 @@
1
+ module SchemaPlusPgIndexes
2
+ module Middleware
3
+ module Postgresql
4
+ module Sql
5
+
6
+ module IndexComponents
7
+
8
+ # SchemaPlusPgIndexes provides the following extra options for PostgreSQL
9
+ # indexes:
10
+ # * +:expression+ - SQL expression to index. column_name can be nil or ommitted, in which case :name must be provided
11
+ # * +:operator_class+ - an operator class name or a hash mapping column name to operator class name
12
+ # * +:case_sensitive - setting to +false+ is a shorthand for :expression => 'LOWER(column_name)'
13
+ #
14
+ # The <tt>:case_sensitive => false</tt> option ties in with Rails built-in support for case-insensitive searching:
15
+ # validates_uniqueness_of :name, :case_sensitive => false
16
+ #
17
+ # Since since <tt>:case_sensitive => false</tt> is implemented by
18
+ # using <tt>:expression</tt>, this raises an ArgumentError if both
19
+ # are specified simultaneously.
20
+ #
21
+ def around(env)
22
+ options = env.options
23
+ column_names = env.column_names
24
+ table_name = env.table_name
25
+ connection = env.connection
26
+
27
+ if env.column_names.empty?
28
+ raise ArgumentError, "No columns and :expression missing from options - cannot create index" unless options[:expression]
29
+ raise ArgumentError, "No columns, and index name not given. Pass :name option" unless options[:name]
30
+ end
31
+
32
+ expression = options.delete(:expression)
33
+ operator_classes = options.delete(:operator_class)
34
+ case_insensitive = (options.delete(:case_sensitive) == false)
35
+
36
+ if expression
37
+ raise ArgumentError, "Cannot specify :case_sensitive => false with an expression. Use LOWER(column_name)" if case_insensitive
38
+ expression.strip!
39
+ if m = expression.match(/^using\s+(?<using>\S+)\s*(?<rest>.*)/i)
40
+ options[:using] = m[:using]
41
+ expression = m[:rest]
42
+ end
43
+ if m = expression.match(/^(?<rest>.*)\s+where\s+(?<where>.*)/i)
44
+ options[:where] = m[:where]
45
+ expression = m[:rest]
46
+ end
47
+ end
48
+
49
+ yield env
50
+
51
+ if operator_classes and not operator_classes.is_a? Hash
52
+ operator_classes = Hash[column_names.map {|name| [name, operator_classes]}]
53
+ end
54
+
55
+ if expression
56
+ env.sql.columns = expression.sub(/ ^\( (.*) \) $/x, '\1')
57
+ elsif operator_classes or case_insensitive
58
+ option_strings = Hash[column_names.map {|name| [name, '']}]
59
+ (operator_classes||{}).stringify_keys.each do |column, opclass|
60
+ option_strings[column] += " #{opclass}" if opclass
61
+ end
62
+ option_strings = connection.send :add_index_sort_order, option_strings, column_names, options
63
+
64
+ if case_insensitive
65
+ caseable_columns = connection.columns(table_name).select { |col| [:string, :text].include?(col.type) }.map(&:name)
66
+ quoted_column_names = column_names.map do |col_name|
67
+ (caseable_columns.include?(col_name.to_s) ? "LOWER(#{connection.quote_column_name(col_name)})" : connection.quote_column_name(col_name)) + option_strings[col_name]
68
+ end
69
+ else
70
+ quoted_column_names = column_names.map { |col_name| connection.quote_column_name(col_name) + option_strings[col_name] }
71
+ end
72
+
73
+ env.sql.columns = quoted_column_names.join(', ')
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module SchemaPlusPgIndexes
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/schema_dev.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  ruby:
2
- - 1.9.3
3
2
  - 2.1.5
4
3
  activerecord:
5
4
  - 4.2
@@ -18,13 +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_monkey", "~> 1.0", ">= 1.0.1"
22
- spec.add_dependency "schema_plus_indexes", "~> 0.1"
21
+ spec.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.2"
23
22
 
24
23
  spec.add_development_dependency "bundler", "~> 1.7"
25
24
  spec.add_development_dependency "rake", "~> 10.0"
26
25
  spec.add_development_dependency "rspec", "~> 3.0.0"
27
- spec.add_development_dependency "schema_dev", "~> 3.0"
26
+ spec.add_development_dependency "schema_dev", "~> 3.1"
28
27
  spec.add_development_dependency "simplecov"
29
28
  spec.add_development_dependency "simplecov-gem-profile"
30
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.2
4
+ version: 0.1.3
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-03 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -25,39 +25,25 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: schema_monkey
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: '1.0'
33
+ version: '0.1'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 1.0.1
36
+ version: 0.1.2
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.0'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.0.1
47
- - !ruby/object:Gem::Dependency
48
- name: schema_plus_indexes
49
- requirement: !ruby/object:Gem::Requirement
50
40
  requirements:
51
41
  - - "~>"
52
42
  - !ruby/object:Gem::Version
53
43
  version: '0.1'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
44
+ - - ">="
59
45
  - !ruby/object:Gem::Version
60
- version: '0.1'
46
+ version: 0.1.2
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: bundler
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -106,14 +92,14 @@ dependencies:
106
92
  requirements:
107
93
  - - "~>"
108
94
  - !ruby/object:Gem::Version
109
- version: '3.0'
95
+ version: '3.1'
110
96
  type: :development
111
97
  prerelease: false
112
98
  version_requirements: !ruby/object:Gem::Requirement
113
99
  requirements:
114
100
  - - "~>"
115
101
  - !ruby/object:Gem::Version
116
- version: '3.0'
102
+ version: '3.1'
117
103
  - !ruby/object:Gem::Dependency
118
104
  name: simplecov
119
105
  requirement: !ruby/object:Gem::Requirement
@@ -160,9 +146,11 @@ files:
160
146
  - gemfiles/activerecord-4.2/Gemfile.postgresql
161
147
  - lib/schema_plus_pg_indexes.rb
162
148
  - lib/schema_plus_pg_indexes/active_record/connection_adapters/index_definition.rb
149
+ - lib/schema_plus_pg_indexes/active_record/connection_adapters/postgresql_adapter.rb
163
150
  - lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb
164
151
  - lib/schema_plus_pg_indexes/middleware/postgresql/migration.rb
165
- - lib/schema_plus_pg_indexes/middleware/postgresql/query.rb
152
+ - lib/schema_plus_pg_indexes/middleware/postgresql/schema.rb
153
+ - lib/schema_plus_pg_indexes/middleware/postgresql/sql.rb
166
154
  - lib/schema_plus_pg_indexes/version.rb
167
155
  - schema_dev.yml
168
156
  - schema_plus_pg_indexes.gemspec