Do Not Add Database Index If It Already Exists in Rails

Written by prathamesh | Published 2020/05/10
Tech Story Tags: ruby-on-rails | database | ruby | ruby-on-rails-top-story | latest-tech-stories | database-index-ruby | ruby-index-error | coding

TLDR An option that will not create the table if it already exists has been added to the create_table method in Ruby on Rails 6.0.2 and below. The option is handy when we have added a table directly in production but now want to add it through a migration so that it is available in other environments as well. If this migration is run twice, it results into following error related to creating the table. The error was raised for existing index. But we do know that the index may exist. That's why we added the option to create the index.via the TL;DR App

no story

Written by prathamesh | Developer Evangelist at Last9
Published by HackerNoon on 2020/05/10