If It's needed?

Hi, Folks!

I wrote this.


class AddPremiumStatusTransactionsToVacancy < ActiveRecord::Migration

def change

create_table :jobs_data_vacancy_premium_status_transactions do |t|

t.integer :status, default: 0, null: false

t.references :vacancy, index: true

t.datetime :turn_on_premium_at

t.datetime :turn_off_premium_at

t.timestamps null: false

end

end

And after that I had an error


Index name 'index_jobs_data_vacancy_premium_status_transactions_on_vacancy_id' on table 'jobs_data_vacancy_premium_status_transactions' is too long; the limit is 63

Ok, I fixed it in this way


class AddPremiumStatusTransactionsToVacancy < ActiveRecord::Migration

def change

create_table :jobs_data_vacancy_premium_status_transactions do |t|

t.integer :status, default: 0, null: false

t.references :vacancy

t.datetime :turn_on_premium_at

t.datetime :turn_off_premium_at

t.timestamps null: false

end

add_index :jobs_data_vacancy_premium_status_transactions, [:vacancy_id], name: :index_premium_status_transactions_on_vacancy_id

end

end

But I do not like this stuff. It will be great if i can write something like


t.references :vancancy, index: true, index_name: :my_great_name

What do you think, about it?

I can make a PR for your, if it’s needed)

Thnx)

You can pass index options instead of true. For example:

t.references :vancancy, index: {name: :my_great_name}

Allen Madsen
http://www.allenmadsen.com