If It's needed?

24 views
Skip to first unread message

Egor Vorobiev

unread,
Jun 12, 2015, 11:24:39 AM6/12/15
to rubyonra...@googlegroups.com
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)

Allen Madsen

unread,
Jun 12, 2015, 11:50:00 AM6/12/15
to rubyonra...@googlegroups.com
You can pass index options instead of true. For example:

```
t.references :vancancy, index: {name: :my_great_name}
```
Allen Madsen
http://www.allenmadsen.com
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-co...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages