Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20150817163600_deduplicate_user_identities.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fceffc48018637bd7cf59d30c7ae01090e7a1441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class DeduplicateUserIdentities < ActiveRecord::Migration
  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