Today I Learned

A Hashrocket project

Rails 5 db schema and its indexes

Rails 5 changed the way they register db indexes on db/schema.rb file. Now it’s nested to create_table method.

rails 5

create_table "users", force: :cascade do |t|
  ...
  t.index ["username"],
    name: "index_users_on_username", using: :btree
end

rails 4

add_index "users", ["username"],
  name: "index_users_on_username", using: :btree

Foreign keys are registered the same way as before:

ActiveRecord::Schema.define(version: 20160524224020) do
  add_foreign_key "sessions", "users"
end
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket and we'd love to take a look at your project. Contact us and find out how we can help you.