samvera / questioning_authority

Question your authorities
Other
54 stars 30 forks source link

enable functional index generator #224

Closed ConorSheehan1 closed 5 years ago

ConorSheehan1 commented 5 years ago

Is it possible to enable the add_index_to_local_authorities.rb generator now?

As far as I can tell, qa depends on rails 5 since at least v3.0.0, and rails 5 supports functional indexes.

elrayle commented 5 years ago

@ConorSheehan1 Seems like this should be possible now. Are you interested in submitting a PR that puts this in place?

elrayle commented 5 years ago

FYI... there are instructions for setting up the indexing manually in the wiki documentation.

ConorSheehan1 commented 5 years ago

Yes I'm interested :) It's the end of the day where I am though, so I'll take a crack at it tomorrow morning when I'm back at my computer

ConorSheehan1 commented 5 years ago

@elrayle I think I got this wrong, sorry.

Looks like the functional index support in rails 5 that I referenced is for postgres only. Functional indexes for sqlite are added in rails 6. Same thing for mysql functional indexes.

I started making the changes, but ran into an error where the schema contains a nil where it should have 'lower(label)'

class AddIndexToLocalAuthorities < ActiveRecord::Migration[5.2]
  def change
    add_index :qa_local_authority_entries,
                ['local_authority_id', 'lower(local_authority_entry_label)'],
                name: 'index_local_authority_entries_on_lower_label',
                unique: true
  end
end

generates an invalid schema

  create_table "qa_local_authority_entries", force: :cascade do |t|
    t.integer "local_authority_id"
    t.string "label"
    t.string "uri"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    # on bundle exec rake db:migrate
    # rake aborted!
    # NoMethodError: undefined method `to_sym' for nil:NilClass
    t.index ["local_authority_id", nil], name: "index_local_authority_entries_on_lower_label", unique: true
  end