2016-06-16 23:09:34 +05:30
|
|
|
# rubocop:disable all
|
2019-02-15 15:39:39 +05:30
|
|
|
class DeduplicateUserIdentities < ActiveRecord::Migration[4.2]
|
2015-09-25 12:07:36 +05:30
|
|
|
def change
|
|
|
|
execute 'DROP TABLE IF EXISTS tt_migration_DeduplicateUserIdentities;'
|
|
|
|
execute 'CREATE TABLE tt_migration_DeduplicateUserIdentities AS SELECT id,provider,user_id FROM identities;'
|
|
|
|
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
|