Search code examples
ruby-on-railsrubypostgresqlactiverecordrails-migrations

Does Rails index existing records when running an index migration?


When adding an index to an existing column in Rails:

add_index :users, :some_id

and then running the migrations:

rake db:migrate

Are all pre-existing records/columns automatically indexed? Database used is Postgres.


Solution

  • Yes, it does. It calls postgres CREATE INDEX that creates an index and fills it with existing data.