You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
624 B
11 lines
624 B
class AddUniqIndexToCourseMember < ActiveRecord::Migration[5.2]
|
|
def change
|
|
# sql = %Q(delete from course_members where (user_id, course_id, role) in
|
|
# (select * from (select user_id, course_id, role from course_members group by user_id, course_id, role having count(*) > 1) a)
|
|
# and id not in (select * from (select min(id) from course_members group by user_id, course_id, role having count(*) > 1 order by id) b))
|
|
# ActiveRecord::Base.connection.execute sql
|
|
#
|
|
# add_index :course_members, [:user_id, :course_id, :role], unique: true, name: "index_user_id_course_id_role"
|
|
end
|
|
end
|