因为原帖关闭了回复,所以单独发一个,我喜欢用 PostgreSQL 的一个原因就是条件索引(Partial Indexes)
add_index :users, :auth_token, unique: true, where: "auth_token IS NOT NULL" add_index :users, :password_reset_token, unique: true, where: "password_reset_token IS NOT NULL"