class UniqIndexOnCollections < ActiveRecord::Migration[5.2] def change remove_index :collections, [:container_type, :container_id] add_index :collections, [:container_type, :container_id] add_index :collections, [:user_id, :container_type, :container_id], unique: true end end