schema_plus_pg_indexes
Schema_plus_pg_indexes adds into ActiveRecord support for some additional PostgreSQL index features: expressions, operator classes, and case-insensitive indexes:
t.string :last_name, index: { expression: 'upper(last_name)' }
t.string :last_name, index: { operator_class: 'varchar_pattern_ops' }
t.string :last_name, index: { with: :address, operator_class: {last_name: 'varchar_pattern_ops', address: 'text_pattern_ops' }
t.string :last_name, index: { case_sensitive: false }
t.index expression: 'upper(last_name)', name: 'my_index' # no column given, must give a name
Case insensitivity is a shorthand for the expression lower(last_name)
The ActiveRecord::ConnectionAdapters::IndexDefinition object has the corresponding methods defined on it: #expression, #operator_classes and #case_sensitive?
Schema_plus_pg_indexes is part of the SchemaPlus family of Ruby on Rails extension gems.
Installation
In your application's Gemfile
gem "schema_plus_pg_indexes"
Compatibility
schema_plus_pg_indexes is tested on
- ruby 1.9.3 with activerecord 4.2, using postgresql
- ruby 2.1.5 with activerecord 4.2, using postgresql
Deprecations
SchemaPlus 1.8.x provided some options and accessors that are now available in rails 4.2, in slightly different form. SchemaPlusPgIndexes supports the SchemaPlus 1.8.x form but issues deprecation warnings in favor of the rails form:
Index definition deprecates these options:
:conditions=>:where:kind=>:using
IndexDefinitiondeprecates accessors:#conditionsin favor of#where#kindin favor of#using.to_s
History
v0.1.0
- Initial release
Development & Testing
Are you interested in contributing to schema_plus_pg_indexes? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.
Some things to know about to help you develop and test:
- schema_dev: schema_plus_pg_indexes uses schema_dev to facilitate running rspec tests on the matrix of ruby, rails, and database versions that the gem supports, both locally and on travis-ci
To to run rspec locally on the full matrix, do:
$ schema_dev bundle install
$ schema_dev rspec
You can also run on just one configuration at a time; For info, see schema_dev --help or the
schema_dev README.
The matrix of configurations is specified in schema_dev.yml in
the project root.
- schema_monkey: schema_plus_pg_indexes extends ActiveRecord using schema_monkey's extension API and protocols -- see its README for details. If your contribution needs any additional monkey patching that isn't already supported by schema_monkey, please head over there and submit a PR.