Browse Source

fixed 修改user login唯一索引

pull/342/head
xxqfamous 3 years ago
parent
commit
8cc565ca0c
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      db/migrate/20230520133729_add_user_login_uniq_index.rb

+ 12
- 0
db/migrate/20230520133729_add_user_login_uniq_index.rb View File

@@ -0,0 +1,12 @@
class AddForgeAppliedMessageUtf8mb4 < ActiveRecord::Migration[5.2]
def change

users = User.group("login").having("count(1) >1")
ids = users.pluck(:id)
logins = users.pluck(:login)
User.where(login: logins).where.not(id: ids).destroy_all

remove_index :users, :login
add_index :users, :login, unique: true
end
end

Loading…
Cancel
Save