SchemaPlus / schema_plus_pg_indexes

Adds support in ActiveRecord for PostgreSQL index expressions and operator classes, as well as a shorthand for case-insensitive indexes
MIT License
30 stars 13 forks source link

Expression indexes don't work with operator class #7

Closed ivalkeen closed 9 years ago

ivalkeen commented 9 years ago

Hi,

I'm trying to use operator_class together with expression, and can't make it work. This is how I create index in PG:

CREATE INDEX index_users_on_fullname_lower ON users (lower(firstname || ' ' || lastname) text_pattern_ops)

And when I dump the schema, I get this in my schema.rb:

t.index name: "index_users_on_fullname_lower", expression: "lower((((firstname)::text || ' '::text) || (lastname)::text))", operator_class: {nil=>"text_pattern_ops"}

Is it (not) supported? Any plans to supporting this? Any help would be appreciated. Thanks!

I'm using version 0.1.7 of the gem with rails 4.2.3 and postgres 9.4.

Here is a log of the error when I'm trying to load schema.

rake aborted!
NoMethodError: undefined method `+' for nil:NilClass
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_pg_indexes-0.1.7/lib/schema_plus_pg_indexes/middleware/postgresql/sql.rb:58:in `block in around'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_pg_indexes-0.1.7/lib/schema_plus_pg_indexes/middleware/postgresql/sql.rb:57:in `each'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_pg_indexes-0.1.7/lib/schema_plus_pg_indexes/middleware/postgresql/sql.rb:57:in `around'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:73:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:83:in `_modware_continue'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:77:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:44:in `execute'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:20:in `start'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_monkey-2.1.3/lib/schema_monkey/stack.rb:34:in `start'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_core-0.6.0/lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb:15:in `add_index_options'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql/schema_statements.rb:476:in `add_index'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_core-0.6.0/lib/schema_plus/core/active_record/connection_adapters/postgresql_adapter.rb:15:in `block in add_index'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:55:in `call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:55:in `call_implementation'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:85:in `_modware_continue'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:77:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:83:in `_modware_continue'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:74:in `block in _modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_indexes-0.2.0/lib/schema_plus/indexes/middleware/migration.rb:44:in `around'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:73:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:83:in `_modware_continue'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:77:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:44:in `execute'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:20:in `start'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_monkey-2.1.3/lib/schema_monkey/stack.rb:34:in `start'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_core-0.6.0/lib/schema_plus/core/active_record/connection_adapters/postgresql_adapter.rb:14:in `add_index'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_pg_indexes-0.1.7/lib/schema_plus_pg_indexes/active_record/connection_adapters/postgresql_adapter.rb:11:in `add_index'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:212:in `block in create_table'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:211:in `each_pair'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:211:in `create_table'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_core-0.6.0/lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb:28:in `block in create_table'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:55:in `call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:55:in `call_implementation'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:85:in `_modware_continue'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:74:in `block in _modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_foreign_keys-0.1.2/lib/schema_plus/foreign_keys/middleware/migration.rb:14:in `around'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:73:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:83:in `_modware_continue'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:77:in `_modware_call'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:44:in `execute'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/modware-0.1.2/lib/modware/stack.rb:20:in `start'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_monkey-2.1.3/lib/schema_monkey/stack.rb:34:in `start'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/schema_plus_core-0.6.0/lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb:27:in `create_table'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:661:in `block in method_missing'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `block in say_with_time'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/benchmark.rb:288:in `measure'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `say_with_time'
/Users/ivan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:651:in `method_missing'
/Users/ivan/code/api/db/schema.rb:217:in `block in <top (required)>'
...
Tasks: TOP => db:schema:load
ronen commented 9 years ago

@ivalkeen thanks for the bug report. I've fixed the bug and released v0.1.8 of the gem.

Closing this out, feel free to re-open if you still have any troubles.

ivalkeen commented 9 years ago

@ronen Wow, that was fast! Thank you very much, I'll test it.