2015-07-21 17:03:26 -04:00
|
|
|
class DeduplicateUserIdentities < ActiveRecord::Migration
|
|
|
|
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
|