schema_plus_pg_indexes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +9 -0
- data/gemfiles/Gemfile.base +8 -0
- data/gemfiles/rails-4.2/Gemfile.base +3 -0
- data/gemfiles/rails-4.2/Gemfile.postgresql +10 -0
- data/lib/schema_plus_pg_indexes.rb +11 -0
- data/lib/schema_plus_pg_indexes/active_record/connection_adapters/index_definition.rb +49 -0
- data/lib/schema_plus_pg_indexes/middleware/migration.rb +23 -0
- data/lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb +55 -0
- data/lib/schema_plus_pg_indexes/middleware/postgresql/migration.rb +83 -0
- data/lib/schema_plus_pg_indexes/middleware/postgresql/query.rb +130 -0
- data/lib/schema_plus_pg_indexes/version.rb +3 -0
- data/schema_dev.yml +7 -0
- data/schema_plus_pg_indexes.gemspec +30 -0
- data/spec/deprecation_spec.rb +62 -0
- data/spec/index_definition_spec.rb +135 -0
- data/spec/index_spec.rb +121 -0
- data/spec/named_schema_spec.rb +60 -0
- data/spec/schema_dumper_spec.rb +166 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/matchers/have_index.rb +60 -0
- metadata +203 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-gem-profile'
|
3
|
+
SimpleCov.start "gem"
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
require 'active_record'
|
10
|
+
require 'schema_plus_pg_indexes'
|
11
|
+
require 'schema_dev/rspec'
|
12
|
+
|
13
|
+
SchemaDev::Rspec.setup
|
14
|
+
|
15
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include(SchemaPlusPgIndexesMatchers)
|
19
|
+
config.warnings = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def define_schema(&block)
|
23
|
+
ActiveRecord::Migration.suppress_messages do
|
24
|
+
ActiveRecord::Schema.define do
|
25
|
+
connection.tables.each do |table|
|
26
|
+
drop_table table, :cascade => true
|
27
|
+
end
|
28
|
+
instance_eval &block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
SimpleCov.command_name "[ruby #{RUBY_VERSION} - ActiveRecord #{::ActiveRecord::VERSION::STRING} - #{ActiveRecord::Base.connection.adapter_name}]"
|
34
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module SchemaPlusPgIndexesMatchers
|
2
|
+
|
3
|
+
class HaveIndex
|
4
|
+
|
5
|
+
def initialize(expectation, options = {})
|
6
|
+
set_required_columns(expectation)
|
7
|
+
@unique = options.delete(:unique)
|
8
|
+
@name = options.delete(:name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(model)
|
12
|
+
@too_many = nil
|
13
|
+
@model = model
|
14
|
+
indexes = @model.indexes.select { |index| index.columns.to_set == @required_columns }
|
15
|
+
if indexes.length > 1
|
16
|
+
@too_many = indexes.length
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
index = indexes.first
|
20
|
+
return index && (@unique ? index.unique : true) && (@name ? index.name == @name.to_s : true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def failure_message(should_not = false)
|
24
|
+
invert = should_not ? "not to" : "to"
|
25
|
+
what = ""
|
26
|
+
what += "unique " if @unique
|
27
|
+
what += "named '{@name}'" if @name
|
28
|
+
msg = "Expected #{@model.table_name} #{invert} contain one #{what}index on #{@required_columns.entries.inspect}"
|
29
|
+
msg += "; found #{@too_many} indexes" if @too_many
|
30
|
+
msg
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure_message_when_negated
|
34
|
+
failure_message(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def on(expectation)
|
38
|
+
set_required_columns(expectation)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def set_required_columns(expectation)
|
44
|
+
@required_columns = Array(expectation).collect(&:to_s).to_set
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def have_index(*expectation)
|
50
|
+
options = expectation.extract_options!
|
51
|
+
HaveIndex.new(expectation, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
def have_unique_index(*expectation)
|
55
|
+
options = expectation.extract_options!
|
56
|
+
options[:unique] = true
|
57
|
+
HaveIndex.new(expectation, options)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schema_plus_pg_indexes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ronen barzel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: schema_monkey
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: schema_plus_indexes
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: schema_dev
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov-gem-profile
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- ronen@barzel.org
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- gemfiles/Gemfile.base
|
153
|
+
- gemfiles/rails-4.2/Gemfile.base
|
154
|
+
- gemfiles/rails-4.2/Gemfile.postgresql
|
155
|
+
- lib/schema_plus_pg_indexes.rb
|
156
|
+
- lib/schema_plus_pg_indexes/active_record/connection_adapters/index_definition.rb
|
157
|
+
- lib/schema_plus_pg_indexes/middleware/migration.rb
|
158
|
+
- lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb
|
159
|
+
- lib/schema_plus_pg_indexes/middleware/postgresql/migration.rb
|
160
|
+
- lib/schema_plus_pg_indexes/middleware/postgresql/query.rb
|
161
|
+
- lib/schema_plus_pg_indexes/version.rb
|
162
|
+
- schema_dev.yml
|
163
|
+
- schema_plus_pg_indexes.gemspec
|
164
|
+
- spec/deprecation_spec.rb
|
165
|
+
- spec/index_definition_spec.rb
|
166
|
+
- spec/index_spec.rb
|
167
|
+
- spec/named_schema_spec.rb
|
168
|
+
- spec/schema_dumper_spec.rb
|
169
|
+
- spec/spec_helper.rb
|
170
|
+
- spec/support/matchers/have_index.rb
|
171
|
+
homepage: https://github.com/SchemaPlus/schema_plus_pg_indexes
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata: {}
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 2.2.2
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Adds support in ActiveRecord for PostgreSQL index expressions and operator
|
195
|
+
classes, as well as a shorthand for case-insensitive indexes
|
196
|
+
test_files:
|
197
|
+
- spec/deprecation_spec.rb
|
198
|
+
- spec/index_definition_spec.rb
|
199
|
+
- spec/index_spec.rb
|
200
|
+
- spec/named_schema_spec.rb
|
201
|
+
- spec/schema_dumper_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
- spec/support/matchers/have_index.rb
|