schema_plus_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 +4 -4
- data/README.md +81 -38
- data/lib/{schema_plus_indexes → schema_plus/indexes}/active_record/base.rb +1 -1
- data/lib/{schema_plus_indexes → schema_plus/indexes}/active_record/connection_adapters/abstract_adapter.rb +1 -1
- data/lib/{schema_plus_indexes → schema_plus/indexes}/active_record/connection_adapters/index_definition.rb +2 -5
- data/lib/{schema_plus_indexes → schema_plus/indexes}/middleware/dumper.rb +1 -1
- data/lib/{schema_plus_indexes → schema_plus/indexes}/middleware/migration.rb +3 -3
- data/lib/{schema_plus_indexes → schema_plus/indexes}/middleware/model.rb +1 -1
- data/lib/{schema_plus_indexes → schema_plus/indexes}/middleware/schema.rb +1 -1
- data/lib/schema_plus/indexes/version.rb +5 -0
- data/lib/schema_plus/indexes.rb +11 -0
- data/lib/schema_plus_indexes.rb +1 -11
- data/schema_plus_indexes.gemspec +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/matchers/have_index.rb +1 -1
- metadata +11 -10
- data/lib/schema_plus_indexes/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab3b42608f51e2ebb4b7b6b21b5ad2fc6566fec2
|
4
|
+
data.tar.gz: a9b0166d7a50826f93825aa20a29f714e952f69e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe17a220b606d91ef6cdc213371ef0ba018c69deda8ba67464a16171ede854b50c30423f17c404b00d622325f746ae6da254dc129641be992ab0fc050a87035b
|
7
|
+
data.tar.gz: 375f7b7201cae230180d7bc98fd11a980a5f2d1970b8a481ba2063019d9bc6e528c758758b747dabe8d932ff2ae35c6fe9b77e7bbd9f7b7db6d6b16398715946
|
data/README.md
CHANGED
@@ -3,45 +3,11 @@
|
|
3
3
|
[![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_indexes.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_indexes)
|
4
4
|
[![Dependency Status](https://gemnasium.com/lomba/schema_plus_indexes.svg)](https://gemnasium.com/SchemaPlus/schema_plus_indexes)
|
5
5
|
|
6
|
-
#
|
6
|
+
# SchemaPlus::Indexes
|
7
7
|
|
8
|
-
|
8
|
+
SchemaPlus::Indexes adds various convenient capabilities to `ActiveRecord`'s index handling.
|
9
9
|
|
10
|
-
|
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
|
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
|
22
|
-
|
23
|
-
Of course options can be combined, such as `index: { with: :first_name, unique: true, name: "my_index"}`
|
24
|
-
|
25
|
-
* Ensures that the `:index` option is respected by `Migration.add_column` and in `Migration.change_table`
|
26
|
-
|
27
|
-
* Adds `:if_exists` option to `ActiveRecord::Migration.remove_index`
|
28
|
-
|
29
|
-
* Provides consistent behavior regarding attempted duplicate index
|
30
|
-
creation: Ignore and log a warning. Different versions of Rails with
|
31
|
-
different db adapters otherwise behave inconsistently: some ignore the
|
32
|
-
attempt, some raise an error.
|
33
|
-
|
34
|
-
* `Model.indexes` returns the indexes defined for the `ActiveRecord` model.
|
35
|
-
Shorthand for `connection.indexes(Model.table_name)`; the value is cached
|
36
|
-
until the next time `Model.reset_column_information` is called
|
37
|
-
|
38
|
-
* In the schema dump `schema.rb`, index definitions are included within the
|
39
|
-
`create_table` statements rather than added afterwards
|
40
|
-
|
41
|
-
* When using SQLite3, makes sure that the definitions returned by
|
42
|
-
`connection.indexes` properly include the column orders (`:asc` or `:desc`)
|
43
|
-
|
44
|
-
schema_plus_indexes is part of the [SchemaPlus](https://github.com/SchemaPlus/) family of Ruby on Rails extension gems.
|
10
|
+
SchemaPlus::Indexes is part of the [SchemaPlus](https://github.com/SchemaPlus/) family of Ruby on Rails extension gems.
|
45
11
|
|
46
12
|
## Installation
|
47
13
|
|
@@ -64,6 +30,83 @@ which creates a Railtie to that will insert SchemaPlus::Indexes appropriately in
|
|
64
30
|
|
65
31
|
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->
|
66
32
|
|
33
|
+
|
34
|
+
## Features
|
35
|
+
|
36
|
+
### Migrations:
|
37
|
+
|
38
|
+
#### Shorthand to define a column with an index:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
t.string :role, index: true # shorthand for index: {}
|
42
|
+
```
|
43
|
+
|
44
|
+
#### Shorthand to define a column with a unique index:
|
45
|
+
```ruby
|
46
|
+
t.string :product_code, index: :unique # shorthand for index: { unique: true }
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Create multi-column indexes as part of column definition
|
50
|
+
|
51
|
+
Adds an option to include other columns in the index:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
t.string :first_name
|
55
|
+
t.string :last_name, index: { with: :first_name }
|
56
|
+
|
57
|
+
t.string :country_code
|
58
|
+
t.string :area_code
|
59
|
+
t.string :local_number, index: { with: [:country_code, :area_code] }
|
60
|
+
```
|
61
|
+
|
62
|
+
#### Create indexes with `add_column`, `change_table`
|
63
|
+
|
64
|
+
ActiveRecord supports the `index:` option to column definitions when creating table. SchemaPlus::Indexes extends that to work also with `add_column` and in `change_table`
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
add_column "tablename", "columnname", index: { ... }
|
68
|
+
|
69
|
+
change_table :tablename do |t|
|
70
|
+
t.integer :column, index: true
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
These of course accept the shorthands and `with:` option described above.
|
75
|
+
|
76
|
+
#### Remove index :if_exsts
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
remove_index "tablename", "columnname", if_exists: true
|
80
|
+
```
|
81
|
+
|
82
|
+
### Models
|
83
|
+
|
84
|
+
SchemaPlus::Indexes lets you easily get the indexes of a model:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
Model.indexes # shorthand for `connection.indexes(Model.table_name)`
|
88
|
+
```
|
89
|
+
|
90
|
+
The value gets cached until the next time `Model.reset_column_information` is called.
|
91
|
+
|
92
|
+
### Other things...
|
93
|
+
|
94
|
+
* Provides consistent behavior regarding attempted duplicate index
|
95
|
+
creation: Ignore and log a warning. Different versions of Rails with
|
96
|
+
different db adapters otherwise behave inconsistently: some ignore the
|
97
|
+
attempt, some raise an error.
|
98
|
+
|
99
|
+
* In the schema dump `schema.rb`, index definitions are included within the
|
100
|
+
`create_table` statements rather than added afterwards
|
101
|
+
|
102
|
+
* When using SQLite3, makes sure that the definitions returned by
|
103
|
+
`connection.indexes` properly include the column orders (`:asc` or `:desc`)
|
104
|
+
|
105
|
+
* For the `ActiveRecord::ConnectionAdapters::IndexDefinition` class (the object that's returned by `connection.indexes`), SchemaPlus::Indexes:
|
106
|
+
* Provides an `==` operator to compare if two objects refer to an equivalent index
|
107
|
+
* Allows calling `new` with a signature that matches add_index: `IndexDefinition.new(table_name, column_names, options)`
|
108
|
+
* Fleshes out the `:orders` attribute, listing `:asc` for a column instead of leaving it undefined.
|
109
|
+
|
67
110
|
## Compatibility
|
68
111
|
|
69
112
|
schema_plus_indexes is tested on
|
@@ -78,7 +121,7 @@ schema_plus_indexes is tested on
|
|
78
121
|
|
79
122
|
### v0.1.0
|
80
123
|
|
81
|
-
* Initial release
|
124
|
+
* Initial release, extracted from schema_plus 1.x
|
82
125
|
|
83
126
|
## Development & Testing
|
84
127
|
|
@@ -1,10 +1,7 @@
|
|
1
|
-
module
|
1
|
+
module SchemaPlus::Indexes
|
2
2
|
module ActiveRecord
|
3
3
|
module ConnectionAdapters
|
4
|
-
|
5
|
-
# SchemaPlusIndexes extends the IndexDefinition object to return information
|
6
|
-
# about partial indexes and case sensitivity (i.e. Postgresql
|
7
|
-
# support).
|
4
|
+
|
8
5
|
module IndexDefinition
|
9
6
|
|
10
7
|
def initialize(*args) #:nodoc:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module SchemaPlus::Indexes
|
2
2
|
module Middleware
|
3
3
|
module Migration
|
4
4
|
|
@@ -34,12 +34,12 @@ module SchemaPlusIndexes
|
|
34
34
|
|
35
35
|
# Ignore duplicates
|
36
36
|
#
|
37
|
-
#
|
37
|
+
# SchemaPlus::Indexes modifies SchemaStatements::add_index so that it ignores
|
38
38
|
# errors raised about add an index that already exists -- i.e. that has
|
39
39
|
# the same index name, same columns, and same options -- and writes a
|
40
40
|
# warning to the log. Some combinations of rails & DB adapter versions
|
41
41
|
# would log such a warning, others would raise an error; with
|
42
|
-
#
|
42
|
+
# SchemaPlus::Indexes all versions log the warning and do not raise the error.
|
43
43
|
def around(env)
|
44
44
|
yield env
|
45
45
|
rescue => e
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'schema_plus/core'
|
2
|
+
|
3
|
+
require_relative 'indexes/active_record/base'
|
4
|
+
require_relative 'indexes/active_record/connection_adapters/abstract_adapter'
|
5
|
+
require_relative 'indexes/active_record/connection_adapters/index_definition'
|
6
|
+
require_relative 'indexes/middleware/dumper'
|
7
|
+
require_relative 'indexes/middleware/migration'
|
8
|
+
require_relative 'indexes/middleware/model'
|
9
|
+
require_relative 'indexes/middleware/schema'
|
10
|
+
|
11
|
+
SchemaMonkey.register SchemaPlus::Indexes
|
data/lib/schema_plus_indexes.rb
CHANGED
@@ -1,11 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative 'schema_plus_indexes/active_record/base'
|
4
|
-
require_relative 'schema_plus_indexes/active_record/connection_adapters/abstract_adapter'
|
5
|
-
require_relative 'schema_plus_indexes/active_record/connection_adapters/index_definition'
|
6
|
-
require_relative 'schema_plus_indexes/middleware/dumper'
|
7
|
-
require_relative 'schema_plus_indexes/middleware/migration'
|
8
|
-
require_relative 'schema_plus_indexes/middleware/model'
|
9
|
-
require_relative 'schema_plus_indexes/middleware/schema'
|
10
|
-
|
11
|
-
SchemaMonkey.register SchemaPlusIndexes
|
1
|
+
require_relative 'schema_plus/indexes'
|
data/schema_plus_indexes.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'schema_plus/indexes/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "schema_plus_indexes"
|
8
|
-
gem.version =
|
8
|
+
gem.version = SchemaPlus::Indexes::VERSION
|
9
9
|
gem.authors = ["ronen barzel"]
|
10
10
|
gem.email = ["ronen@barzel.org"]
|
11
11
|
gem.summary = %q{Adds shorthands and conveniences to ActiveRecord's handling of indexes}
|
data/spec/spec_helper.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -140,15 +140,16 @@ files:
|
|
140
140
|
- gemfiles/activerecord-4.2/Gemfile.mysql2
|
141
141
|
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
142
142
|
- gemfiles/activerecord-4.2/Gemfile.sqlite3
|
143
|
+
- lib/schema_plus/indexes.rb
|
144
|
+
- lib/schema_plus/indexes/active_record/base.rb
|
145
|
+
- lib/schema_plus/indexes/active_record/connection_adapters/abstract_adapter.rb
|
146
|
+
- lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb
|
147
|
+
- lib/schema_plus/indexes/middleware/dumper.rb
|
148
|
+
- lib/schema_plus/indexes/middleware/migration.rb
|
149
|
+
- lib/schema_plus/indexes/middleware/model.rb
|
150
|
+
- lib/schema_plus/indexes/middleware/schema.rb
|
151
|
+
- lib/schema_plus/indexes/version.rb
|
143
152
|
- lib/schema_plus_indexes.rb
|
144
|
-
- lib/schema_plus_indexes/active_record/base.rb
|
145
|
-
- lib/schema_plus_indexes/active_record/connection_adapters/abstract_adapter.rb
|
146
|
-
- lib/schema_plus_indexes/active_record/connection_adapters/index_definition.rb
|
147
|
-
- lib/schema_plus_indexes/middleware/dumper.rb
|
148
|
-
- lib/schema_plus_indexes/middleware/migration.rb
|
149
|
-
- lib/schema_plus_indexes/middleware/model.rb
|
150
|
-
- lib/schema_plus_indexes/middleware/schema.rb
|
151
|
-
- lib/schema_plus_indexes/version.rb
|
152
153
|
- schema_dev.yml
|
153
154
|
- schema_plus_indexes.gemspec
|
154
155
|
- spec/index_definition_spec.rb
|