schema_plus_pg_indexes 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/README.md +16 -2
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.base +1 -1
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.postgresql +0 -0
- data/lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb +6 -11
- data/lib/schema_plus_pg_indexes/middleware/postgresql/migration.rb +7 -6
- data/lib/schema_plus_pg_indexes/middleware/postgresql/query.rb +20 -27
- data/lib/schema_plus_pg_indexes/version.rb +1 -1
- data/schema_dev.yml +1 -1
- data/schema_plus_pg_indexes.gemspec +2 -2
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2b5b828916853a511caa4f8b19f8a7e79fe8442
|
4
|
+
data.tar.gz: 5ff7110ccc48476917619787863700670b89c0f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbab6a29c45ba788aaf81951efa439b3e9ce2f4de676db318393a1edf08fdeea3e3d3d0098cbe986e912ef6381f20e5850829235e3d097abc52522e7a1abbdd8
|
7
|
+
data.tar.gz: 9ab3c857047c7e6627e3d0888aef4c9b6060f63810e72c2994d05673eb659d52deeb243a98535e9f3861a8780af5a4663dd299b5f7fd53c3fe300299a5eab065
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -33,11 +33,25 @@ schema_plus_pg_indexes is tested on
|
|
33
33
|
|
34
34
|
<!-- SCHEMA_DEV: MATRIX - begin -->
|
35
35
|
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
36
|
-
* ruby **1.9.3** with
|
37
|
-
* ruby **2.1.5** with
|
36
|
+
* ruby **1.9.3** with activerecord **4.2**, using **postgresql**
|
37
|
+
* ruby **2.1.5** with activerecord **4.2**, using **postgresql**
|
38
38
|
|
39
39
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
40
40
|
|
41
|
+
## Deprecations
|
42
|
+
|
43
|
+
SchemaPlus 1.8.x provided some options and accessors that are now available
|
44
|
+
in rails 4.2, in slightly different form. SchemaPlusPgIndexes supports the
|
45
|
+
SchemaPlus 1.8.x form but issues deprecation warnings in favor of the rails
|
46
|
+
form:
|
47
|
+
|
48
|
+
* Index definition deprecates these options:
|
49
|
+
* `:conditions` => `:where`
|
50
|
+
* `:kind` => `:using`
|
51
|
+
|
52
|
+
* `IndexDefinition` deprecates accessors:
|
53
|
+
* `#conditions` in favor of `#where`
|
54
|
+
* `#kind` in favor of `#using.to_s`
|
41
55
|
|
42
56
|
## History
|
43
57
|
|
File without changes
|
@@ -3,15 +3,10 @@ module SchemaPlusPgIndexes
|
|
3
3
|
module Postgresql
|
4
4
|
module Dumper
|
5
5
|
|
6
|
-
|
7
|
-
SchemaMonkey::Middleware::Dumper::Indexes.append DumpExtensions
|
8
|
-
SchemaMonkey::Middleware::Dumper::Table.append InlineIndexes
|
9
|
-
end
|
10
|
-
|
11
|
-
class DumpExtensions < SchemaMonkey::Middleware::Base
|
12
|
-
def call(env)
|
13
|
-
continue env
|
6
|
+
module Indexes
|
14
7
|
|
8
|
+
# Dump index extensions
|
9
|
+
def after(env)
|
15
10
|
index_defs = Dumper.get_index_defiinitions(env, env.table)
|
16
11
|
|
17
12
|
env.table.indexes.each do |index_dump|
|
@@ -32,10 +27,10 @@ module SchemaPlusPgIndexes
|
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
|
-
|
36
|
-
def call(env)
|
37
|
-
continue env
|
30
|
+
module Table
|
38
31
|
|
32
|
+
# Move index definitions inline
|
33
|
+
def after(env)
|
39
34
|
index_defs = Dumper.get_index_defiinitions(env, env.table)
|
40
35
|
|
41
36
|
env.table.indexes.select(&its.columns.blank?).each do |index|
|
@@ -7,19 +7,20 @@ module SchemaPlusPgIndexes
|
|
7
7
|
SchemaMonkey::Middleware::Migration::IndexComponentsSql.append DefineExtensions
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
module Index
|
11
|
+
# Deprecate args
|
12
|
+
def before(env)
|
12
13
|
{:conditions => :where, :kind => :using}.each do |deprecated, proper|
|
13
14
|
if env.options[deprecated]
|
14
15
|
ActiveSupport::Deprecation.warn "ActiveRecord index option #{deprecated.inspect} is deprecated, use #{proper.inspect} instead"
|
15
16
|
env.options[proper] = env.options.delete(deprecated)
|
16
17
|
end
|
17
18
|
end
|
18
|
-
continue env
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
module IndexComponentsSql
|
23
|
+
|
23
24
|
# SchemaPlusPgIndexes provides the following extra options for PostgreSQL
|
24
25
|
# indexes:
|
25
26
|
# * +:expression+ - SQL expression to index. column_name can be nil or ommitted, in which case :name must be provided
|
@@ -33,7 +34,7 @@ module SchemaPlusPgIndexes
|
|
33
34
|
# using <tt>:expression</tt>, this raises an ArgumentError if both
|
34
35
|
# are specified simultaneously.
|
35
36
|
#
|
36
|
-
def
|
37
|
+
def around(env)
|
37
38
|
options = env.options
|
38
39
|
column_names = env.column_names
|
39
40
|
table_name = env.table_name
|
@@ -61,7 +62,7 @@ module SchemaPlusPgIndexes
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
64
|
-
|
65
|
+
yield env
|
65
66
|
|
66
67
|
if operator_classes and not operator_classes.is_a? Hash
|
67
68
|
operator_classes = Hash[column_names.map {|name| [name, operator_classes]}]
|
@@ -2,11 +2,7 @@ module SchemaPlusPgIndexes
|
|
2
2
|
module Middleware
|
3
3
|
module Postgresql
|
4
4
|
module Query
|
5
|
-
|
6
|
-
SchemaMonkey::Middleware::Query::Indexes.append LookupExtensions
|
7
|
-
end
|
8
|
-
|
9
|
-
class LookupExtensions < SchemaMonkey::Middleware::Base
|
5
|
+
module Indexes
|
10
6
|
|
11
7
|
def get_opclass_names(env, opclasses)
|
12
8
|
@opclass_names ||= {}
|
@@ -21,7 +17,7 @@ module SchemaPlusPgIndexes
|
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
24
|
-
def
|
20
|
+
def implement(env)
|
25
21
|
# Ideally we'd let AR do its stuff and then add the extras.
|
26
22
|
#
|
27
23
|
# But one of the extras is expressions. AR completely strips out
|
@@ -38,24 +34,21 @@ module SchemaPlusPgIndexes
|
|
38
34
|
# query we have the opportunity to handle tables of the form
|
39
35
|
# 'namespace.tablename'
|
40
36
|
#
|
41
|
-
# So,
|
42
|
-
#
|
43
|
-
# continue env
|
44
|
-
#
|
45
|
-
result = env.connection.query(<<-SQL, 'SCHEMA')
|
37
|
+
# So, this replacs the AR implementation
|
46
38
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
39
|
+
result = env.connection.query(<<-SQL, 'SCHEMA')
|
40
|
+
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,
|
41
|
+
m.amname, pg_get_expr(d.indpred, t.oid) as conditions, pg_get_expr(d.indexprs, t.oid) as expression,
|
42
|
+
d.indclass
|
43
|
+
FROM pg_class t
|
44
|
+
INNER JOIN pg_index d ON t.oid = d.indrelid
|
45
|
+
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
46
|
+
INNER JOIN pg_am m ON i.relam = m.oid
|
47
|
+
WHERE i.relkind = 'i'
|
48
|
+
AND d.indisprimary = 'f'
|
49
|
+
AND t.relname = '#{table_name_without_namespace(env.table_name)}'
|
50
|
+
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = #{namespace_sql(env.table_name)} )
|
51
|
+
ORDER BY i.relname
|
59
52
|
SQL
|
60
53
|
|
61
54
|
env.index_definitions += result.map do |(index_name, unique, indkey, inddef, oid, using, conditions, expression, indclass)|
|
@@ -63,10 +56,10 @@ module SchemaPlusPgIndexes
|
|
63
56
|
opclasses = indclass.split(" ")
|
64
57
|
|
65
58
|
rows = env.connection.query(<<-SQL, 'SCHEMA')
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
SELECT CAST(a.attnum as VARCHAR), a.attname, t.typname
|
60
|
+
FROM pg_attribute a
|
61
|
+
INNER JOIN pg_type t ON a.atttypid = t.oid
|
62
|
+
WHERE a.attrelid = #{oid}
|
70
63
|
SQL
|
71
64
|
columns = {}
|
72
65
|
types = {}
|
data/schema_dev.yml
CHANGED
@@ -18,13 +18,13 @@ 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", "~> 0.
|
21
|
+
spec.add_dependency "schema_monkey", "~> 1.0", ">= 1.0.1"
|
22
22
|
spec.add_dependency "schema_plus_indexes", "~> 0.1"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0.0"
|
27
|
-
spec.add_development_dependency "schema_dev", "~>
|
27
|
+
spec.add_development_dependency "schema_dev", "~> 3.0"
|
28
28
|
spec.add_development_dependency "simplecov"
|
29
29
|
spec.add_development_dependency "simplecov-gem-profile"
|
30
30
|
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.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,14 +30,20 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.1
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
43
|
+
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: schema_plus_indexes
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,20 +106,14 @@ dependencies:
|
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
104
|
-
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: 2.0.3
|
109
|
+
version: '3.0'
|
107
110
|
type: :development
|
108
111
|
prerelease: false
|
109
112
|
version_requirements: !ruby/object:Gem::Requirement
|
110
113
|
requirements:
|
111
114
|
- - "~>"
|
112
115
|
- !ruby/object:Gem::Version
|
113
|
-
version: '
|
114
|
-
- - ">="
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: 2.0.3
|
116
|
+
version: '3.0'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: simplecov
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,8 +156,8 @@ files:
|
|
156
156
|
- README.md
|
157
157
|
- Rakefile
|
158
158
|
- gemfiles/Gemfile.base
|
159
|
-
- gemfiles/
|
160
|
-
- gemfiles/
|
159
|
+
- gemfiles/activerecord-4.2/Gemfile.base
|
160
|
+
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
161
161
|
- lib/schema_plus_pg_indexes.rb
|
162
162
|
- lib/schema_plus_pg_indexes/active_record/connection_adapters/index_definition.rb
|
163
163
|
- lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb
|