2016-06-09 08:39:16 -04:00
|
|
|
# rubocop:disable all
|
2018-11-13 02:27:31 -05:00
|
|
|
class DeduplicateUserIdentities < ActiveRecord::Migration[4.2]
|
2015-07-21 17:03:26 -04:00
|
|
|
def change
|
|
|
|
execute 'DROP TABLE IF EXISTS tt_migration_DeduplicateUserIdentities;'
|
2015-09-18 13:49:04 -04:00
|
|
|
execute 'CREATE TABLE tt_migration_DeduplicateUserIdentities AS SELECT id,provider,user_id FROM identities;'
|
2015-07-21 17:03:26 -04:00
|
|
|
execute 'DELETE FROM identities WHERE id NOT IN ( SELECT MIN(id) FROM tt_migration_DeduplicateUserIdentities GROUP BY user_id, provider);'
|
|
|
|
execute 'DROP TABLE IF EXISTS tt_migration_DeduplicateUserIdentities;'
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# This is an irreversible migration;
|
|
|
|
# If someone is trying to rollback for other reasons, we should not throw an Exception.
|
|
|
|
# raise ActiveRecord::IrreversibleMigration
|
|
|
|
end
|
|
|
|
end
|