schema_plus_indexes 0.1.0 → 0.1.1

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: c53c8e9e64713769dfa034d9f28f83251553e23b
4
- data.tar.gz: 56b8cc58c8e1332ed557fa75e76c3c30e01a3e78
3
+ metadata.gz: c3204552a60115feff109316363cec1ab9cc45e2
4
+ data.tar.gz: a1087216a0144af5c299bc0972fca2989c81c122
5
5
  SHA512:
6
- metadata.gz: f89e5ac13330c1e3a111fcd22c94376f362fda21d5fe52d17f909c87ff878e5a2d5fad4b7d477d96e93b84b3a77450f47c19d020296da080f0c467cadc5231ff
7
- data.tar.gz: 63acf447a5afacc21fa08da17f4c9adc121dee9a16b364cdf77ec12e0012e245db3d6870ed5ef63a2bbc5851afb0631af5575bebe54b4d3202f1b2db3908b8d1
6
+ metadata.gz: 537929890d6ad08fd33f11a7f36c0b9413a93281e252258048e060eb71a05434f32d800f2887f13c044c0b2c3044fe684cb15e912fbfe00f6ce3706dc01611cc
7
+ data.tar.gz: f36b1a1c603c1ee61ffcb1ed80345eee92c7f177c953ee859da21feefcc2b5a892a08caeb40e3dcea4b5295aa84eca702b432a7ca757c2cfff2e377bf1e68f62
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /coverage
2
2
  /tmp
3
3
  /pkg
4
+ /Gemfile.local
4
5
 
5
6
  *.lock
6
7
  *.log
data/.travis.yml CHANGED
@@ -8,9 +8,9 @@ rvm:
8
8
  - 1.9.3
9
9
  - 2.1.5
10
10
  gemfile:
11
- - gemfiles/rails-4.2/Gemfile.mysql2
12
- - gemfiles/rails-4.2/Gemfile.postgresql
13
- - gemfiles/rails-4.2/Gemfile.sqlite3
11
+ - gemfiles/activerecord-4.2/Gemfile.mysql2
12
+ - gemfiles/activerecord-4.2/Gemfile.postgresql
13
+ - gemfiles/activerecord-4.2/Gemfile.sqlite3
14
14
  env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
15
15
  addons:
16
16
  postgresql: '9.3'
data/README.md CHANGED
@@ -9,16 +9,16 @@ Schema_plus_index adds various convenient capabilities to `ActiveRecord`'s index
9
9
 
10
10
  * Adds shorthands to the `:index` option in migrations
11
11
 
12
- create_table :parts do |t|
13
- t.string :role, index: true # shorthand for index: {}
14
- t.string :product_code, index: :unique # shorthand for index: { unique: true }
15
- t.string :first_name
16
- t.string :last_name, index: { with: :first_name } # multi-column index
12
+ create_table :parts do |t|
13
+ t.string :role, index: true # shorthand for index: {}
14
+ t.string :product_code, index: :unique # shorthand for index: { unique: true }
15
+ t.string :first_name
16
+ t.string :last_name, index: { with: :first_name } # multi-column index
17
17
 
18
- t.string :country_code
19
- t.string :area_code
20
- t.string :local_number, index: { with: [:country_code, :area_code] } # multi-column index
21
- end
18
+ t.string :country_code
19
+ t.string :area_code
20
+ t.string :local_number, index: { with: [:country_code, :area_code] } # multi-column index
21
+ end
22
22
 
23
23
  Of course options can be combined, such as `index: { with: :first_name, unique: true, name: "my_index"}`
24
24
 
@@ -54,13 +54,12 @@ gem "schema_plus_indexes"
54
54
 
55
55
  schema_plus_indexes is tested on
56
56
 
57
- [//]: # SCHEMA_DEV: MATRIX - begin
58
- [//]: # These lines are auto-generated by schema_dev based on schema_dev.yml
59
- * ruby **1.9.3** with rails **4.2**, using **mysql2**, **sqlite3** or **postgresql**
60
- * ruby **2.1.5** with rails **4.2**, using **mysql2**, **sqlite3** or **postgresql**
61
-
62
- [//]: # SCHEMA_DEV: MATRIX - end
57
+ <!-- SCHEMA_DEV: MATRIX - begin -->
58
+ <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
59
+ * ruby **1.9.3** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
60
+ * ruby **2.1.5** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
63
61
 
62
+ <!-- SCHEMA_DEV: MATRIX - end -->
64
63
 
65
64
  ## History
66
65
 
@@ -1,3 +1,3 @@
1
1
  eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gem "rails", "~> 4.2.0"
3
+ gem "activerecord", "~> 4.2.0"
@@ -1,14 +1,9 @@
1
1
  module SchemaPlusIndexes
2
2
  module Middleware
3
3
  module Dumper
4
+ module Table
4
5
 
5
- def self.insert
6
- SchemaMonkey::Middleware::Dumper::Table.append ColumnIndexes
7
- end
8
-
9
- class ColumnIndexes < SchemaMonkey::Middleware::Base
10
- def call(env)
11
- continue env
6
+ def after(env)
12
7
 
13
8
  # move each column's index to its column, and remove them from the
14
9
  # list of indexes that AR would dump after the table. Any left
@@ -2,28 +2,19 @@ module SchemaPlusIndexes
2
2
  module Middleware
3
3
  module Migration
4
4
 
5
- def self.insert
6
- SchemaMonkey::Middleware::Migration::Column.prepend Shortcuts
7
- SchemaMonkey::Middleware::Migration::Column.append IndexOnAddColumn
8
- SchemaMonkey::Middleware::Migration::Index.prepend NormalizeArgs
9
- SchemaMonkey::Middleware::Migration::Index.prepend IgnoreDuplicates
10
- end
11
-
12
- class Shortcuts < SchemaMonkey::Middleware::Base
13
- def call(env)
5
+ module Column
6
+
7
+ # Shortcuts
8
+ def before(env)
14
9
  case env.options[:index]
15
10
  when true then env.options[:index] = {}
16
11
  when :unique then env.options[:index] = { :unique => true }
17
12
  end
18
- continue env
19
13
  end
20
- end
21
14
 
22
- class IndexOnAddColumn < SchemaMonkey::Middleware::Base
23
- def call(env)
24
- continue env
15
+ # Support :index option in Migration.add_column
16
+ def after(env)
25
17
  return unless env.options[:index]
26
-
27
18
  case env.operation
28
19
  when :add, :record
29
20
  env.caller.add_index(env.table_name, env.column_name, env.options[:index])
@@ -31,25 +22,26 @@ module SchemaPlusIndexes
31
22
  end
32
23
  end
33
24
 
34
- class NormalizeArgs < SchemaMonkey::Middleware::Base
35
- def call(env)
25
+ module Index
26
+
27
+ # Normalize Args
28
+ def before(env)
36
29
  [:length, :order].each do |key|
37
30
  env.options[key].stringify_keys! if env.options[key].is_a? Hash
38
31
  end
39
32
  env.column_names = Array.wrap(env.column_names).map(&:to_s) + Array.wrap(env.options.delete(:with)).map(&:to_s)
40
- continue env
41
33
  end
42
- end
43
34
 
44
- class IgnoreDuplicates < SchemaMonkey::Middleware::Base
35
+ # Ignore duplicates
36
+ #
45
37
  # SchemaPlusIndexes modifies SchemaStatements::add_index so that it ignores
46
38
  # errors raised about add an index that already exists -- i.e. that has
47
39
  # the same index name, same columns, and same options -- and writes a
48
40
  # warning to the log. Some combinations of rails & DB adapter versions
49
41
  # would log such a warning, others would raise an error; with
50
42
  # SchemaPlusIndexes all versions log the warning and do not raise the error.
51
- def call(env)
52
- continue env
43
+ def around(env)
44
+ yield env
53
45
  rescue => e
54
46
  raise unless e.message.match(/["']([^"']+)["'].*already exists/)
55
47
  name = $1
@@ -1,14 +1,8 @@
1
1
  module SchemaPlusIndexes
2
2
  module Middleware
3
3
  module Model
4
-
5
- def self.insert
6
- SchemaMonkey::Middleware::Model::ResetColumnInformation.append ResetColumnInformation
7
- end
8
-
9
- class ResetColumnInformation < SchemaMonkey::Middleware::Base
10
- def call(env)
11
- continue env
4
+ module ResetColumnInformation
5
+ def after(env)
12
6
  env.model.reset_index_information
13
7
  end
14
8
  end
@@ -1,23 +1,19 @@
1
1
  module SchemaPlusIndexes
2
2
  module Middleware
3
3
  module Sqlite3
4
- def self.insert
5
- SchemaMonkey::Middleware::Query::Indexes.append LookupExtensions
6
- end
4
+ module Query
5
+ module Indexes
7
6
 
8
- class LookupExtensions < SchemaMonkey::Middleware::Base
9
- def call(env)
10
- continue env
11
- indexes = Hash[env.index_definitions.map{ |d| [d.name, d] }]
7
+ def after(env)
8
+ indexes = Hash[env.index_definitions.map{ |d| [d.name, d] }]
12
9
 
13
- env.connection.exec_query("SELECT name, sql FROM sqlite_master WHERE type = 'index'").map do |row|
14
- if (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any?
15
- index = indexes[row['name']]
16
- index.orders = Hash[index.columns.map {|column| [column, desc_columns.include?(column) ? :desc : :asc]}]
10
+ env.connection.exec_query("SELECT name, sql FROM sqlite_master WHERE type = 'index'").map do |row|
11
+ if (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any?
12
+ index = indexes[row['name']]
13
+ index.orders = Hash[index.columns.map {|column| [column, desc_columns.include?(column) ? :desc : :asc]}]
14
+ end
17
15
  end
18
16
  end
19
-
20
- env.index_definitions
21
17
  end
22
18
  end
23
19
  end
@@ -1,3 +1,3 @@
1
1
  module SchemaPlusIndexes
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/schema_dev.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ruby:
2
2
  - 1.9.3
3
3
  - 2.1.5
4
- rails:
4
+ activerecord:
5
5
  - 4.2
6
6
  db:
7
7
  - mysql2
@@ -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_monkey", "~> 0.2"
21
+ spec.add_dependency "schema_monkey", "~> 1.0"
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", "~> 2.0"
26
+ spec.add_development_dependency "schema_dev", "~> 3.0"
27
27
  spec.add_development_dependency "simplecov"
28
28
  spec.add_development_dependency "simplecov-gem-profile"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_indexes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-01-26 00:00:00.000000000 Z
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,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '2.0'
89
+ version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '2.0'
96
+ version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -136,10 +136,10 @@ files:
136
136
  - README.md
137
137
  - Rakefile
138
138
  - gemfiles/Gemfile.base
139
- - gemfiles/rails-4.2/Gemfile.base
140
- - gemfiles/rails-4.2/Gemfile.mysql2
141
- - gemfiles/rails-4.2/Gemfile.postgresql
142
- - gemfiles/rails-4.2/Gemfile.sqlite3
139
+ - gemfiles/activerecord-4.2/Gemfile.base
140
+ - gemfiles/activerecord-4.2/Gemfile.mysql2
141
+ - gemfiles/activerecord-4.2/Gemfile.postgresql
142
+ - gemfiles/activerecord-4.2/Gemfile.sqlite3
143
143
  - lib/schema_plus_indexes.rb
144
144
  - lib/schema_plus_indexes/active_record/base.rb
145
145
  - lib/schema_plus_indexes/active_record/connection_adapters/abstract_adapter.rb
@@ -155,7 +155,6 @@ files:
155
155
  - spec/index_spec.rb
156
156
  - spec/migration_spec.rb
157
157
  - spec/named_schema_spec.rb
158
- - spec/sanity_spec.rb
159
158
  - spec/schema_dumper_spec.rb
160
159
  - spec/spec_helper.rb
161
160
  - spec/support/matchers/have_index.rb
@@ -188,7 +187,6 @@ test_files:
188
187
  - spec/index_spec.rb
189
188
  - spec/migration_spec.rb
190
189
  - spec/named_schema_spec.rb
191
- - spec/sanity_spec.rb
192
190
  - spec/schema_dumper_spec.rb
193
191
  - spec/spec_helper.rb
194
192
  - spec/support/matchers/have_index.rb
data/spec/sanity_spec.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- # A basic sanity check to have as a spec when first starting. Feel free to delete this
5
- # once you've got real content.
6
-
7
- describe "Sanity Check" do
8
-
9
- it "database is connected" do
10
- expect(ActiveRecord::Base).to be_connected
11
- end
12
-
13
- end