Home

Awesome

Gem Version Build Status Coverage Status

SchemaPlus::Indexes

SchemaPlus::Indexes adds various convenient capabilities to ActiveRecord's index handling.

SchemaPlus::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_indexes"                # in a Gemfile
gem.add_dependency "schema_plus_indexes" # in a .gemspec
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->

Features

Migrations:

Shorthand to define a column with an index:

t.string :role,             index: true     # shorthand for index: {}

Shorthand to define a column with a unique index:

t.string :product_code,     index: :unique  # shorthand for index: { unique: true }

Create multi-column indexes as part of column definition

Adds an option to include other columns in the index:

t.string :first_name
t.string :last_name,        index: { with: :first_name }

t.string :country_code
t.string :area_code
t.string :local_number,     index: { with: [:country_code, :area_code] }

Create indexes with add_column, change_table

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

add_column "tablename", "columnname", index: { ... }

change_table :tablename do |t|
  t.integer :column,    index: true
end

These of course accept the shorthands and with: option described above.

Remove index :if_exists

remove_index "tablename", "columnname", if_exists: true

Models

SchemaPlus::Indexes lets you easily get the indexes of a model:

Model.indexes  # shorthand for `connection.indexes(Model.table_name)`

The value gets cached until the next time Model.reset_column_information is called.

Other things...

Compatibility

schema_plus_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

v1.0.1

v1.0.0

v0.3.1

v0.3.0

v0.2.4

v0.2.3

v0.2.2

v0.2.1

v0.2.0

v0.1.0

Development & Testing

Are you interested in contributing to schema_plus_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 -->