Home

Awesome

Gem Version Build Status Coverage Status Dependency Status

Deprecated for Rails 5.2+

As of ActiveRecord 5.2 all of the functionality provided by this gem is supported in the core ActiveRecord.

This gem can still be added to a Rails 5.2 project to maintain backward compatibility while migrating. However it will not be supported in future Rails versions. The schema_plus_indexes gem can still be used to support the shortcut index syntax.

Migrations can be written as

# instead of expression: 'upper(last_name)'
t.string :last_name
t.index 'upper(last_name)', name: 'index_my_table_on_last_name'

# instead of operator_class: 'varchar_pattern_ops'
t.string :last_name,  index: { opclass: 'varchar_pattern_ops' }

# instead of operator_class {last_name: 'varchar_pattern_ops', address: 'text_pattern_ops' }
t.string :last_name,  index: { with: :address, opclass: {last_name: 'varchar_pattern_ops', address: 'text_pattern_ops' } }

# instead of case_sensitive: false
t.string :last_name
t.index 'lower(last_name)', name: 'index_my_table_on_last_name'

After updating all of your migrations you can replace schema_plus_pg_indexes with schema_plus_indexes to continue to use the shortcut syntax.

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

<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - begin --> <!-- These lines are auto-inserted from a schema_dev template -->

As usual:

gem "schema_plus_pg_indexes"                # in a Gemfile
gem.add_dependency "schema_plus_pg_indexes" # in a .gemspec
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->

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:

Compatibility

schema_plus_pg_indexes is tested on

<!-- SCHEMA_DEV: MATRIX - begin --> <!-- These lines are auto-generated by schema_dev based on schema_dev.yml --> <!-- SCHEMA_DEV: MATRIX - end -->

Release Notes

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: TEMPLATE USES SCHEMA_DEV - begin --> <!-- These lines are auto-inserted from a schema_dev template --> <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end --> <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin --> <!-- These lines are auto-inserted from a schema_dev template --> <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - end --> <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - begin --> <!-- These lines are auto-inserted from a schema_dev template --> <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - end -->