schema_plus 1.3.1 → 1.3.2

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: 65c72cd47992bb6bf783d19b59e5d518e9256acc
4
- data.tar.gz: fc0f8382dfb38c00719a1e86286390de3b7726a7
3
+ metadata.gz: 72d678562e79aad7720350482d28f4a9f5c49130
4
+ data.tar.gz: 5d64c187a751e8a22c1b00af12c8e93e2e426318
5
5
  SHA512:
6
- metadata.gz: cdedc86c2659b80c404e189f178848426e60aea035fec8e3dc144fe48212dff4ce8139a24b34103f01c57a72a8099f5c9901d105cab5ffcb800d38983b1d1914
7
- data.tar.gz: 251070435963c3a912f0f097020f707adae3aae4861316f33a245448ba32fd1fef90e908816ee239c70f9e92309f891ada6c12fc9111bb4bf83484db7ca5d760
6
+ metadata.gz: c30849dd3016aa030dbd39aaceaa6358931908492159aca58703f3a2d7d57821ce17365f137dae123fb44a574beb86f08f06d40a819ae538764186fedede689c
7
+ data.tar.gz: 1c654a69c17dd13a6d898b5b308c865d4487f1df33e95fc1672e011a0ad9e756cf6df8252eec5dbd7034d2b1d72f3e75a0115b6b0796d89f22cebd99e60bdb38
data/README.md CHANGED
@@ -43,7 +43,7 @@ or in a Gemfile
43
43
 
44
44
  ## Features
45
45
 
46
- Here some examples that show off the high points. For full details see the
46
+ This README lists the major features, with examples of use. For full details see the
47
47
  [RDoc documentation](http://rubydoc.info/gems/schema_plus).
48
48
 
49
49
  ### Indexes
@@ -103,14 +103,14 @@ expressions, index methods, and case-insensitive indexes:
103
103
  t.string :last_name, index: { kind: 'hash' }
104
104
  t.string :last_name, index: { case_sensitive: false } # shorthand for expression: 'lower(last_name)'
105
105
 
106
- These features are available also in ActiveRecord::Migration.add_index. See
107
- doc at SchemaPlus::ActiveRecord::ConnectionAdapters::PostgresqlAdapter and
108
- SchemaPlus::ActiveRecord::ConnectionAdapters::IndexDefinition
106
+ These features are available also in `ActiveRecord::Migration.add_index`. See
107
+ doc for [SchemaPlus::ActiveRecord::ConnectionAdapters::PostgresqlAdapter](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/PostgresqlAdapter) and
108
+ [SchemaPlus::ActiveRecord::ConnectionAdapters::IndexDefinition](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/IndexDefinition)
109
109
 
110
110
  When you query column information using ActiveRecord::Base#columns, SchemaPlus
111
111
  analogously provides index information relevant to each column: which indexes
112
- reference the column, whether the column must be unique, etc. See doc at
113
- SchemaPlus::ActiveRecord::ConnectionAdapters::Column
112
+ reference the column, whether the column must be unique, etc. See doc for
113
+ [SchemaPlus::ActiveRecord::ConnectionAdapters::Column](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/Column).
114
114
 
115
115
  SchemaPlus also tidies some index-related behavior:
116
116
 
@@ -175,8 +175,8 @@ The foreign key behavior can be configured globally (see Config) or per-table
175
175
  To examine your foreign key constraints, `connection.foreign_keys` returns a
176
176
  list of foreign key constraints defined for a given table, and
177
177
  `connection.reverse_foreign_keys` returns a list of foreign key constraints
178
- that reference a given table. See
179
- SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.
178
+ that reference a given table. See doc at
179
+ [SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/ForeignKeyDefinition).
180
180
 
181
181
  #### Foreign Key Issues
182
182
 
@@ -298,7 +298,12 @@ of foreign key constraints, you can re-enable it:
298
298
 
299
299
  ### Master branch (to be released)
300
300
 
301
- * (nothing new yet)
301
+ * *nothing currently waiting to be released*
302
+
303
+ ### 1.3.2
304
+
305
+ * Bug fix, remove_index with if_exists but no name
306
+ * Sort indexes alphabetically when dumping, like rails does
302
307
 
303
308
  ### 1.3.1
304
309
 
@@ -26,10 +26,11 @@ module SchemaPlus
26
26
  when /^MySQL/i then 'MysqlAdapter'
27
27
  when 'PostgreSQL', 'PostGIS' then 'PostgresqlAdapter'
28
28
  when 'SQLite' then 'Sqlite3Adapter'
29
- end or raise "SchemaPlus: Unsupported adapter name #{adapter_name.inspect}"
30
- # use 'end or raise' instead of 'else raise' to get
31
- # 100% C0 code coverage despite having no test case
32
- # for this.
29
+ end
30
+ unless adapter
31
+ ::ActiveRecord::Base.logger.warn "SchemaPlus: Unsupported adapter name #{adapter_name.inspect}. Leaving it alone."
32
+ return
33
+ end
33
34
  adapter_module = SchemaPlus::ActiveRecord::ConnectionAdapters.const_get(adapter)
34
35
  self.class.send(:include, adapter_module) unless self.class.include?(adapter_module)
35
36
 
@@ -133,9 +134,10 @@ module SchemaPlus
133
134
  # :if_exists
134
135
  def remove_index_with_schema_plus(table_name, *args)
135
136
  options = args.extract_options!
136
- return if options.delete(:if_exists) and not index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
137
+ if_exists = options.delete(:if_exists)
137
138
  options.delete(:column) if options[:name] and ::ActiveRecord::VERSION::MAJOR < 4
138
139
  args << options if options.any?
140
+ return if if_exists and not index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
139
141
  remove_index_without_schema_plus(table_name, *args)
140
142
  end
141
143
 
@@ -133,7 +133,7 @@ module SchemaPlus
133
133
  dump << ", :expression => #{index.expression.inspect}"
134
134
  end
135
135
  dump << "\n"
136
- }.join
136
+ }.sort.join
137
137
  end
138
138
 
139
139
  def dump_foreign_keys(foreign_keys, opts={}) #:nodoc:
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
data/spec/index_spec.rb CHANGED
@@ -177,6 +177,13 @@ describe "index" do
177
177
  User.indexes.length.should == 0
178
178
  end
179
179
 
180
+ it "removes index using column option" do
181
+ add_index :users, :login
182
+ User.indexes.length.should == 1
183
+ remove_index :users, column: :login
184
+ User.indexes.length.should == 0
185
+ end
186
+
180
187
  it "removes index if_exists" do
181
188
  add_index :users, :login
182
189
  User.indexes.length.should == 1
@@ -184,6 +191,20 @@ describe "index" do
184
191
  User.indexes.length.should == 0
185
192
  end
186
193
 
194
+ it "removes multi-column index if exists" do
195
+ add_index :users, [:login, :deleted_at]
196
+ User.indexes.length.should == 1
197
+ remove_index :users, [:login, :deleted_at], :if_exists => true
198
+ User.indexes.length.should == 0
199
+ end
200
+
201
+ it "removes index if_exists using column option" do
202
+ add_index :users, :login
203
+ User.indexes.length.should == 1
204
+ remove_index :users, column: :login, :if_exists => true
205
+ User.indexes.length.should == 0
206
+ end
207
+
187
208
  it "raises exception if doesn't exist" do
188
209
  expect {
189
210
  remove_index :users, :login
@@ -161,6 +161,14 @@ describe "Schema dump" do
161
161
  end
162
162
  end
163
163
 
164
+ it "should sort indexes" do
165
+ with_index Post, :user_id do
166
+ with_index Post, :short_id do
167
+ dump_posts.should match(/on_short_id.+on_user_id/m)
168
+ end
169
+ end
170
+ end
171
+
164
172
  unless SchemaPlusHelpers.mysql?
165
173
 
166
174
  it "should include index order" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-30 00:00:00.000000000 Z
12
+ date: 2013-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails