- Default sorting in Rails is on the
id
column, which is no longer relevant when uuid types are used. - A default scope of
default_scope -> { order("created_at ASC") }
may be necessary for models. - Also a consideration is adding an index for the
created_at
column:
class AddCreatedAtIndexes < ActiveRecord::Migration
def up
add_index :categories, :created_at
add_index :products, :created_at
add_index :users, :created_at
end
end
- (official) http://guides.rubyonrails.org/active_record_postgresql.html#uuid-primary-keys
- (example) http://blog.bigbinary.com/2016/04/04/rails-5-provides-application-config-to-use-UUID-as-primary-key.html
- (for default uuid) rails/rails#22033
- (example) https://www.penflip.com/loren/blog/blob/master/migrating-to-uuids.txt
Hi everyone, please help me with this question, what happen if we already have data on our database, how can I convert all classic IDs to uuids? Is it converting automatically ?