Module: ActiveRecord::ConnectionAdapters::SchemaStatements

Defined in:
lib/activerecord-postgres-hstore/activerecord.rb

Instance Method Summary collapse

Instance Method Details

#add_hstore_index(table_name, column_name, options = {}) ⇒ Object

Adds a GiST or GIN index to a table which has an hstore column.

Example:

add_hstore_index :people, :info, :type => :gin

Options:

:type  = :gist (default) or :gin

See www.postgresql.org/docs/9.2/static/textsearch-indexes.html for more information.



134
135
136
137
138
# File 'lib/activerecord-postgres-hstore/activerecord.rb', line 134

def add_hstore_index(table_name, column_name, options = {})
  index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
  index_type = index_type.present? ? index_type : 'gist'
  execute "CREATE INDEX #{index_name} ON #{table_name} USING #{index_type}(#{column_name})"
end

#install_hstoreObject

Installs hstore by creating the Postgres extension if it does not exist



114
115
116
# File 'lib/activerecord-postgres-hstore/activerecord.rb', line 114

def install_hstore
  execute "CREATE EXTENSION IF NOT EXISTS hstore"
end

#remove_hstore_index(table_name, options = {}) ⇒ Object

Removes a GiST or GIN index of a table which has an hstore column.

Example:

remove_hstore_index :people, :info


145
146
147
148
# File 'lib/activerecord-postgres-hstore/activerecord.rb', line 145

def remove_hstore_index(table_name, options = {})
  index_name = index_name_for_remove(table_name, options)
  execute "DROP INDEX #{index_name}"
end

#uninstall_hstoreObject

Uninstalls hstore by dropping Postgres extension if it exists



120
121
122
# File 'lib/activerecord-postgres-hstore/activerecord.rb', line 120

def uninstall_hstore
  execute "DROP EXTENSION IF EXISTS hstore"
end